天问 9694a7a230 Update 'README.md' | 2 months ago | |
---|---|---|
README.md | 2 months ago |
语音转文字
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<void> startListening() async {
await speechToText.listen(onResult: onSpeechResult);
setState(() {});
}
Future<void> stopListening() async {
await speechToText.stop();
setState(() {});
}
void onSpeechResult(SpeechRecognitionResult result) {
setState(() {
lastWords = result.recognizedWords;
});
}
@override
void dispose() {
super.dispose();
speechToText.stop();
}