# speech_to_text 语音转文字 ## Usage ``` speech_to_text: ^6.3.0 import 'package:speech_to_text/speech_recognition_result.dart'; import 'package:speech_to_text/speech_to_text.dart'; final speechToText = SpeechToText(); await speechToText.initialize(); Future startListening() async { await speechToText.listen(onResult: onSpeechResult); setState(() {}); } Future stopListening() async { await speechToText.stop(); setState(() {}); } void onSpeechResult(SpeechRecognitionResult result) { setState(() { lastWords = result.recognizedWords; }); } @override void dispose() { super.dispose(); speechToText.stop(); } ``` ## Reference - [](https://pub.dev/packages/speech_to_text)