To recognize text from the microphone, import the package and follow the lifecycle: initialize the plugin, check for availability, and then call listen.
Note: The initialize method should only be called once per application session. Subsequent calls to initialize are ignored, and you cannot reset the onStatus or onError callbacks after the first call. It is recommended to maintain a single instance of the plugin throughout your app's lifecycle.
import 'package:speech_to_text/speech_to_text.dart' as stt;
stt.SpeechToText speech = stt.SpeechToText();
bool available = await speech.initialize(
onStatus: statusListener,
onError: errorListener
);
if (available) {
speech.listen(onResult: resultListener);
} else {
print("The user has denied the use of speech recognition.");
}
// some time later...
speech.stop();