问题描述
早上好,我正在使用lib speech_to_text来使用麦克风并进行语音识别...我放置了一个计时器,使该人在讲话后可以使麦克风处于激活状态的时间更长,但这只能工作在iOS上,所以我看到Android已经有一个本地计时器....有人知道我能做什么吗?谢谢!
@action
onpressedMic({bool continous = false}) {
this.initSpeech();
if (this.hasspeech) {
try {
stt.listen(
localeId: LocaleUtils.getPtBR().localeId,onSoundLevelChange: _sttOnSoundLevelChange,onResult: _sttResultListener,cancelOnError: true,);
// displays the wave indicating the audio capture
status = StatusFooter.capturing_speech;
if (Platform.isIOS) _startTimerListen();
if (_startAudioCapture != null) _startAudioCapture();
} catch (e) {
status = StatusFooter.open_speech;
print("pressed Mic error: $e");
}
}
}
@computed
bool get canShowSuggestions => (this.suggestionChips?.length ?? 0) > 0;
@action
_sttResultListener(SpeechRecognitionResult result) async {
// restart timer,if stt stop command has not been issued
if (Platform.isIOS && !result.finalResult) _startTimerListen();
this.textCaptureAudio = result.recognizedWords;
// sends the question,as the stt stop command has been issued
if (result.finalResult && this.textCaptureAudio.trim().isNotEmpty)
this.sendQuestion(this.textCaptureAudio);
}
void _startTimerListen() {
_cancelTimerListen();
timerListen = Timer(Duration(seconds: 3),() {
if (this.textCaptureAudio.trim().isNotEmpty) {
stt.stop();
} else {
_defineOpenSpeechStatus();
}
});
}
解决方法
据我所知,应用程序实际上无法延长麦克风在Android上监听的时间,而不能使用Flutter或本机Android开发。几年前,我尝试为自己的应用程序解决此问题,但Android上的语音识别功能不支持此功能。很抱歉,但我希望我能帮助您澄清一下。