【问题标题】:Android SpeechRecognizer when do I get ERROR_CLIENT when starting the voice recognizer?Android SpeechRecognizer 启动语音识别器时何时会收到 ERROR_CLIENT?
【发布时间】:2022-01-17 21:34:27
【问题描述】:

我不确定一些与文档相关的东西。

总结一下我做了什么以及我想做什么:我成功地将语音识别功能引入了一个在平板电脑上运行 Android 4.2 的 Android 应用程序,它工作正常。现在我想将我的应用程序移植到 Google Glass 上,但不幸的是,当我尝试启动语音识别器时出现以下错误:错误 5 -> ERROR_CLIENT(其他客户端错误)。该消息引导我查找与 SpeechRecognizer 对象无关的其他错误,但我的日志中没有任何错误,甚至没有警告。所以我的问题会是:我究竟什么时候会收到ERROR_CLIENT?阻止识别器启动的错误应该是什么?

谢谢! :)

【问题讨论】:

  • 您可能忘记了清单中的音频权限。
  • 不,一点也不。当我没有足够的权限时,我会收到另一个代码,那是 9 而不是 5。

标签: android speech-recognition google-glass


【解决方案1】:

我发现这个链接是产生错误的源代码。

SpeechRecognizer source

有 7 个地方搜索到“ERROR_CLIENT”

这是 ERROR_CLIENT 发送到 onError 之前的日志语句

  • Lo​​g.e(TAG, "未选择语音识别服务");
  • Lo​​g.e(TAG, "绑定识别服务失败");
  • Lo​​g.e(TAG, "startListening() failed", e);
  • Lo​​g.e(TAG, "stopListening() failed", e);
  • Lo​​g.e(TAG, "cancel() failed", e);
  • Lo​​g.e(TAG, "未连接识别服务");

当然,您可以在上面的链接中找到更多信息,但这应该会为您提供获得 ERROR_CLIENT 的一般原因

【讨论】:

    【解决方案2】:

    因此,经过一番痛苦后,我设法解决了有关玻璃应用的问题。

    首先,我发现 SpeechRecognizer 仅在我的眼镜连接到互联网时才有效! 即使如此,我仍然不时收到错误 5。那是因为我与互联网,有时我的玻璃只是在没有任何通知的情况下与互联网断开连接!我认为这是下一个级别的眼镜必须解决的问题。它只是无法在不通知您的情况下断开互联网连接。

    因此,Google Glass 上出现 ERROR_CLIENT(5) 的原因之一是:没有互联网连接

    【讨论】:

      【解决方案3】:

      如果 Google search application 对麦克风没有权限,也会发生此错误。在这种情况下,手机语音识别服务将被禁用,并且所有应用都会触发 ERROR_CLIENT 错误(以上案例已在运行 Android 11 的三星手机上验证)

      【讨论】:

        【解决方案4】:

        我收到此错误是因为我在主循环中使用了对象变量

        class SpeechRecognition implements RecognitionListener {
            private SpeechRecognizer recognizer;
        
            public void transcribe (Activity activity) {
                new Handler(Looper.getMainLooper()).post(() -> {
                    this.speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this.activity);
                    this.speechRecognizer.setRecognitionListener(this.listener);
        
                    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
        
                    this.speechRecognizer.startListening(intent);
                }
            }
        
            [...]
         }
        

        解决方案:

        class SpeechRecognitionRunnable implements Runnable {
            private volatile SpeechRecognizer speechRecognizer;
            private RecognitionListener listener;
            private Activity activity;
        
            public SpeechRecognitionRunnable (RecognitionListener listener, Activity activity) {
                this.listener = listener;
                this.activity = activity;
            }
        
            @Override
            public void run() {
                this.speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this.activity);
                this.speechRecognizer.setRecognitionListener(this.listener);
        
                Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        
                this.speechRecognizer.startListening(intent);
            }
        
            public SpeechRecognizer getSpeechRecognizer() {
                return this.speechRecognizer;
            }
        }
        
        class SpeechRecognition implements RecognitionListener {
            private SpeechRecognizer recognizer;
        
            public void transcribe (Activity activity) {
                new Handler(Looper.getMainLooper()).post(new SpeechRecognitionRunnable(this, activity)
            }
        
            [...]
         }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多