Android Flutter中的麦克风计时器



大家早上好,我正在使用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开发都没有。几年前,我尝试为自己的应用程序解决这个问题,但安卓系统上的语音识别不支持这个问题。很抱歉,但我希望我能帮助澄清一些事情。