【发布时间】:2020-08-14 15:15:44
【问题描述】:
大家早上好,我正在使用 lib speech_to_text 来使用麦克风并进行语音识别……我设置了一个计时器,以便在对方说话后让麦克风保持活动更长时间,但它只能工作在 iOS 上,所以我看到 Android 已经有一个本机 Timer .... 有人知道我能做什么吗?谢谢!
@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 上的语音识别不支持这个。很抱歉,但我希望我能帮助澄清一些事情。
-
你能分享一些代码和/或当前的实现吗?
-
@Stefan 太伤心了,谢谢你的回答!!
-
@Bernardo Nunes Pinheiro 我将其发布为正确答案。
-
@MarianoZorrilla 好的,我编辑了问题!
标签: android flutter dart microphone