语音转文字
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();
}