late AzureSpeechRecognition _speechAzure;
String subKey = Env.azureTTSAPIKey;
String region = Env.azureTTSAPIRegion;
String lang = "en-US";
Future<void> azureStt() async {
await activateSpeechRecognizer();
await recognizeVoiceMicStreaming();
}
Future<void> activateSpeechRecognizer() async {
await Permission.microphone.request();
_speechAzure = AzureSpeechRecognition();
// MANDATORY INITIALIZATION
AzureSpeechRecognition.initialize(subKey, region,
lang: lang,);
_speechAzure.setFinalTranscription((text) {
print("1: $text");
// do what you want with your final transcription
});
_speechAzure.setRecognitionResultHandler((text) {
print("2: $text");
// do what you want with your partial transcription (this one is called every time a word is recognized)
// if you have a string that is displayed you could call here setState() to updated with the partial result
});
_speechAzure.setRecognitionStartedHandler(() {
print("3: Start");
// called at the start of recognition (it could also not be used)
});
}
Future<void> recognizeVoiceMicStreaming() async {
try {
await AzureSpeechRecognition.micStream();
} on PlatformException catch (e) {
print("Failed start the recognition: '${e.message}'.");
}
}
IOS - Error
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method micStream on channel azure_speech_recognition)
#0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:308:7)
<asynchronous suspension>
Android - Error
Print results:
I/flutter (20409): 3: Start
I/flutter (20409): 1:
Immediately after each other.
Also is there a possibility to stop recognizing manually?
It seems that you are including the package azure_speech_recognition instead of azure_speech_recognition_null_safety, which is the package held in this repo.
The package now supports (in the version 0.8.8) manually starting and stopping the recognizer. It works for both iOS and Android.
I hope that solves both of your issues.
I got error both in IOS and Android:
IOS - Error
Android - Error Print results:
Immediately after each other.
Also is there a possibility to stop recognizing manually?