我尝试为Flutter项目创建文字转语音功能,无法在视图中调用“播放”功能。这是我的代码:
void initSpeechRecognizer(){ FlutterTts flutterTts = FlutterTts();
未来_speak()异步{
var result = await flutterTts.speak("Hello World");
if (result == 1) setState(() => flutterTts = _VoiceHomeState.playing);
List<dynamic> languages = await flutterTts.getLanguages;
await flutterTts.setLanguage("id-ID");
await flutterTts.setSpeechRate(1.0);
await flutterTts.setVolume(1.0);
await flutterTts.setPitch(1.0);
await flutterTts.isLanguageAvailable("id-ID");
}
}
}
答案 0 :(得分:0)
此行导致错误
if (result == 1) setState(() => flutterTts = _VoiceHomeState.playing);
flutterTts是您在initSpeechRecognizer中拥有init的实例
在Fultter_TTS的示例代码中
TtsState ttsState = TtsState.stopped;
...
var result = await flutterTts.speak(_newVoiceText);
if (result == 1) setState(() => ttsState = TtsState.playing);
}
我认为您正在尝试设置TtsState。但是对flutterTts错别字