vosk_flutter 0.3.46 copy "vosk_flutter: ^0.3.46" to clipboard
vosk_flutter: ^0.3.46 copied to clipboard

outdated

Flutter plugin for Vosk speech recognition model.

Vosk Flutter Plugin #

style: very good analysis vosk_flutter

Flutter plugin for Vosk speech recognition.

Platform Support #

Android iOS MacOS Web Linux Windows

Usage #

Configurations #

Add this pro guard rules in android/app/proguard-rules.pro(if the file does not exist - create it):

-keep class com.sun.jna.* { *; }
-keepclassmembers class * extends com.sun.jna.* { public *; }
copied to clipboard

Add this plugin to your pubspec.yaml:

vosk_flutter:
  git: https://github.com/alphacep/vosk-flutter
copied to clipboard

If you want to use a microphone input, add the microphone permission to your AndroidManifest.xml:

<uses-permission android:name="android.permission.RECORD_AUDIO" />
copied to clipboard

Load model #

flutter:
  assets:
    - assets/models/

copied to clipboard
final vosk = VoskFlutterPlugin.instance();
final enSmallModelPath = await ModelLoader()
    .loadFromAssets('assets/models/vosk-model-small-en-us-0.15.zip');
copied to clipboard

Create recognizer #

final recognizer = await vosk.createRecognizer(
    model: model,
    sampleRate: sampleRate,
);
final recognizerWithGrammar = await vosk.createRecognizer(
    model: model,
    sampleRate: sampleRate,
    grammar: ['one', 'two', 'three'],
);
copied to clipboard

Recognize audio data #

Uint8List audioBytes = ...; // audio data in PCM 16-bit mono format
List<String> results = [];
int chunkSize = 8192;
int pos = 0;

while (pos + chunkSize < audioBytes.length) {
    final resultReady = await recognizer.acceptWaveformBytes(
      Uint8List.fromList(audioBytes.getRange(pos, pos + chunkSize).toList()));
    pos += chunkSize;
    
    if (resultReady) {
      print(await recognizer.getResult());
    } else {
      print(await recognizer.getPartialResult());
    }
}
await recognizer.acceptWaveformBytes(
  Uint8List.fromList(audioBytes.getRange(pos, audioBytes.length).toList()));
print(await recognizer.getFinalResult());
copied to clipboard

Recognize microphone data #

final speechService = await vosk.initSpeechService(recognizer);
speechService.onPartial().forEach((partial) => print(partial));
speechService.onResult().forEach((result) => print(result));
await speechService.start();
copied to clipboard
19
likes
0
points
420
downloads

Publisher

unverified uploader

Weekly Downloads

2024.09.20 - 2025.04.04

Flutter plugin for Vosk speech recognition model.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

archive, flutter, http, path, path_provider, permission_handler

More

Packages that depend on vosk_flutter