Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I get VOSK-IOS connected to flutter? #2

Open
furqanhermawan23 opened this issue Mar 15, 2022 · 20 comments
Open

How can I get VOSK-IOS connected to flutter? #2

furqanhermawan23 opened this issue Mar 15, 2022 · 20 comments

Comments

@furqanhermawan23
Copy link

Hi,

How can I get VOSK-IOS connected to flutter?

Thank you

@nshmyrev
Copy link
Contributor

You need to mail us at [email protected] and provide information about your project and will share the build.

@misbullah
Copy link

Hi @nshmyrev,

We got the package through email.

Thanks
Alim

@jaumard
Copy link

jaumard commented Jun 1, 2022

as flutter/dart support FFI, if you provide that implementation you can support iOS, android, linux, windows and Mac for free with one implementation could be huge ^^

@nshmyrev
Copy link
Contributor

nshmyrev commented Jun 1, 2022

@jaumard thank you, we'd love to have it as well. Working on iOS now

@gfhjjk
Copy link

gfhjjk commented Oct 11, 2022

hello,@nshmyrev
I think your vosk is very good,I also want a ios_flutter_plugin.I mail you two days ago.
Do you receiver it?
Thank you

@mfs-abarragan
Copy link

Publication of Flutter-iOS demo will be extremely appreciated!

@jtkeyva
Copy link

jtkeyva commented Nov 7, 2022

+1 for working iOS example :) awesome work!

@sergsavchuk
Copy link
Collaborator

@nshmyrev
Since Flutter's main platforms are still Android&iOS it would be great to implement iOS support.
We could for example serve an iOS binary at https://alphacephei.com/vosk/binaries/ios/vosk-ios-0.3.45.zip and restrict access to everyone except those who received an ACCESS_KEY after contacting [email protected].
This will require just a simple web server that will check the ACCESS_KEY using any connected DB.

@wunderbrick
Copy link

@nshmyrev I sent an email but haven't heard back. Is getting the iOS demo still a possibility?

@nshmyrev
Copy link
Contributor

@wunderbrick I'm sorry I can't associate you with the emails we've got. If you haven't got the link already, drop another email please with your github account mentioned.

@nshmyrev
Copy link
Contributor

Since Flutter's main platforms are still Android&iOS it would be great to implement iOS support.

its ok, most guys who request the package get it. No need for access keys, the library is fully offline.

@wunderbrick
Copy link

@nshmyrev Thanks for your reply. I sent another email as a reply to my original email with my Github username. My email address is the Tutanota address that starts with lambda.

@jtdLab
Copy link

jtdLab commented Nov 21, 2023

What is the recommended way to integrate the vosk ios build into a flutter app?

@sergsavchuk
Copy link
Collaborator

@jtdLab
Hi, unfortunately, the iOS part has not been implemented yet. You can implement it yourself and do PR. But first, you should get the iOS lib by contacting [email protected]

@jtdLab
Copy link

jtdLab commented Nov 22, 2023

Hi thanks for the reply.

I obtained the iOS library. When attempting to use the .h file describing the API through FFI, i encountered missing symbols "image not found" error thrown by dart:ffi.

Following this here's what I've tried:

  1. Cloned the vosk-flutter repository.
  2. Added the libvosk.xcframework to ios/Frameworks.
  3. Added a forward.h to ios/Classes that forwards to vosk-api/src/vosk-api.h (necessary because .podspec does not support relative paths).
  4. Added the framework to .podspec so it looks like this:
# To learn more about a Podspec, see http://guides.cocoapods.org/syntax/podspec.html
Pod::Spec.new do |s|
  s.name             = 'vosk_flutter'
  s.version          = '0.0.1'
  s.summary          = 'An iOS implementation of the vosk plugin.'
  s.description      = <<-DESC
  An iOS implementation of the vosk plugin.
                       DESC
  s.homepage         = 'http://example.com'
  s.license          = { :type => 'BSD', :file => '../LICENSE' }
  s.author           = { 'Your Company' => '[email protected]' }
  # This ensures that the source files in Classes/ are included in the native builds of apps using this FFI plugin. Podspec does not support relative paths, so Classes contains a forwarder C file that relatively imports `../../vosk-api/src/*` so that the C sources can be shared among all target platforms.
  s.source           = { :path => '.' }
  s.public_header_files = 'Classes/**/*.h'
  s.dependency 'Flutter'
  s.platform = :ios, '9.0'

  # Flutter.framework does not contain an i386 slice.
  s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
  s.swift_version = '5.0'
  s.vendored_frameworks = 'Frameworks/libvosk.xcframework'
end

In Dart, I only edited src/vosk_flutter.dart:
a) _supportsFFI to return true on iOS.
b) _loadVoskLibrary to load the library via FFI using DynamicLibrary.executable() to load the static libvosk.

Inside pubspec.yaml, I enabled iOS as an FFI plugin, similar to what was done with Linux and Windows already.

While investigating the current Android implementation, I'm also considering mirroring it, as it seems to use multiple threads. Is this required to not get lags in the UI?

@sergsavchuk
Copy link
Collaborator

@jtdLab
Firstly, there's no need to use vosk-api.h, because it's only used to generate generated_vosk_bindings.dart.
Secondly, looks like you need to do the same thing I did for Linux according to the information:
image

And you'll have something like this in Dart:

    String libraryPath;
    if (Platform.isLinux || Platform.isIOS) {
      libraryPath = Platform.environment['LIBVOSK_PATH']!;
    } ....

Thirdly, yes, we use multiple threads in Android to not block the main thread. Btw, there's a branch with Android FFI implemented.

@jtdLab
Copy link

jtdLab commented Nov 25, 2023

@sergsavchuk Thanks a lot for the response
Im still running into an error following the guide u mentioned using the following my_flutter_app/ios/libvosk.podspec

Inspired by this and this

Pod::Spec.new do |s|
    s.name             = 'libvosk'
    s.version          = '0.3.38'
    s.summary          = 'Vosk iOS.'
    s.description      = "Vosk for iOS."
    s.homepage         = 'http://example.com'
    s.license          = { :type => 'BSD', :file => '../LICENSE' }
    s.author           = { 'Your Company' => '[email protected]' }
    s.platform = :ios, '9.0'
    s.source           = { :http => "https://alphacephei.com/path/to/vosk/api.zip" }
    s.vendored_frameworks = "**/libvosk.xcframework"
  end

Hint: Same result when using s.source = { :path => '.' } and copy the libvosk.xcframework next to the my_flutter_app/ios/libvosk.podspec.

to include the binaries but its not getting added to the pods projects. I also had to put the my_flutter_app/ios/libvosk.podspec into the app and reference it inside my_flutter_app/ios/Podfile to make pod install work (which is not good as it should be included inside the vosk_flutter plugin and not a consuming app like my_flutter_app).

The vosk_flutter/ios/vosk_flutter.podspec looks like this:

Pod::Spec.new do |s|
    s.name             = 'vosk_flutter'
    s.version          = '0.0.1'
    s.summary          = 'An iOS implementation of the vosk plugin.'
    s.description      = <<-DESC
    An iOS implementation of the vosk plugin.
                         DESC
    s.homepage         = 'http://example.com'
    s.license          = { :type => 'BSD', :file => '../LICENSE' }
    s.author           = { 'Your Company' => '[email protected]' }
    s.source           = { :path => '.' }
    s.source_files     = 'Classes/**/*'
    s.dependency 'Flutter'
    s.dependency 'libvosk'
    s.platform = :ios, '11.0'
  
    # Flutter.framework does not contain an i386 slice.
    s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
    s.swift_version = '5.0'
  end

The vosk_flutter/ios/Classes/VoskFlutterPlugin.swift looks like:

import Flutter
 
public class VoskFlutterPlugin: NSObject, FlutterPlugin {
  public static func register(with registrar: FlutterPluginRegistrar) {
    setenv("LIBVOSK_PATH", Bundle.main.privateFrameworksPath! + "/libvosk.framework/libvosk", 0);
    let channel = FlutterMethodChannel(name: "vosk_flutter", binaryMessenger: registrar.messenger())
    let instance = VoskFlutterPlugin()
    registrar.addMethodCallDelegate(instance, channel: channel)
  }
}

The vosk_flutter/pubspec.yaml looks like this

...
flutter:
  plugin:
    platforms:
...
      ios:
        pluginClass: VoskFlutterPlugin
        ffiPlugin: true
...

Hint: To read the env var set on the native side from dart i had to use stdlibc instead of Platform.environment (which returned an empty map).
So lib/src/vosk_flutter.dart was changed to

if (Platform.isLinux || Platform.isIOS) {
 libraryPath = getenv('LIBVOSK_PATH')!;
}

Help would be appreciated.

@jtdLab
Copy link

jtdLab commented Dec 11, 2023

@nshmyrev is it possible to get a version of vosk-ios containing dynamic libs instead of static ones. Dart FFI seems to not support static libs.

@mateuszboryn
Copy link

Hi, can I get the iOS library, please? Last week I sent the request to the email mentioned above, but not response yet.

@dkjazz
Copy link

dkjazz commented Mar 1, 2024

I am also interested in iOS support by this plugin.

@jtdLab do you mind sharing a repo with the changes you tried? I can play with it as well to see if we can make it work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests