IOS works with pod 1.14.3
Flutter plugin for Vosk speech recognition.
Android | iOS | MacOS | Web | Linux | Windows |
---|---|---|---|---|---|
✔ | ✔ | ➖ | ➖ | ✔ | ✔ |
Follow the instruction at the Installing page to install the plugin.
From the assets:
flutter:
assets:
- assets/models/
From the network:
final vosk = VoskFlutterPlugin.instance();
final enSmallModelPath = await ModelLoader()
.loadFromAssets('assets/models/vosk-model-small-en-us-0.15.zip');
final recognizer = await vosk.createRecognizer(
model: model,
sampleRate: sampleRate,
);
final recognizerWithGrammar = await vosk.createRecognizer(
model: model,
sampleRate: sampleRate,
grammar: ['one', 'two', 'three'],
);
From the file:
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());
From the microphone(you can use any suitable flutter plugin to get the micStream, for example mic_stream):
Uint8List micStream = ...;
final speechService = await vosk.initSpeechService(recognizer);
speechService.onPartial().forEach((partial) => print(partial));
speechService.onResult().forEach((result) => print(result));
await speechService.start(micStream);