You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter speech_to_text插件Android端3秒后录音超时问题求助

Android端speech_to_text插件3秒超时问题解决

使用speech_to_text: ^5.6.1实现语音转文字功能时,iOS端运行正常,但Android端仅能工作3秒就自动停止,抛出错误Error: SpeechRecognitionError msg: error_speech_timeout, permanent: true,且已在AndroidManifest中添加必要权限。

解决办法

1. 调整语音识别超时参数

Android端默认静音3秒后会触发超时停止,可通过listen方法的参数延长超时时间:

修改speech_api.dart中的listen调用:

if (isAvailable) {
  _speech.listen(
    onResult: (value) => onResult(value.recognizedWords),
    pauseFor: const Duration(seconds: 10), // 静音10秒后才停止识别
    listenFor: const Duration(minutes: 2), // 设置最长录音时长
    cancelOnError: false, // 可选:遇到非致命错误不立即终止
    partialResults: true, // 可选:返回实时识别的中间结果
  );
}

2. 检查设备语音识别引擎

部分Android设备自带的语音识别服务存在限制,确保设备安装了可用的语音识别引擎(如Google语音搜索),且该服务能正常联网。

3. 开启调试日志定位问题

初始化插件时开启调试日志,查看更详细的错误细节:

final isAvailable = await _speech.initialize(
  onStatus: (status) => onListening(_speech.isListening),
  onError: (e) => print('Error: $e'),
  debugLogging: true, // 开启调试日志输出
);

内容的提问来源于stack exchange,提问作者Anandh Krishnan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 05:54:38