【问题标题】:SpeechRecognizer offline ERROR_NO_MATCHSpeechRecognizer 离线 ERROR_NO_MATCH
【发布时间】:2018-01-03 18:20:36
【问题描述】:

当设备离线时,SpeechRecognizer 在 onResults 中返回 ERROR_NO_MATCH,而它在 onPartialResults() 回调中返回部分结果。上次我玩 SpeechRecognizer 时它离线工作得很好,我想知道是否有人找到了解决方案。

【问题讨论】:

    标签: android speech-recognition recognizer-intent


    【解决方案1】:

    作为一种变通方法,我使用 onPartialResults() 中返回的 partialResults。 在返回的包中,“SpeechRecognizer.RESULTS_RECOGNITION”包含所有术语减去最后一个术语,“android.speech.extra.UNSTABLE_TEXT”包含最后一个缺失的识别术语。

        @Override
    public void onPartialResults(Bundle partialResults) {
        ArrayList<String> data = partialResults.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
        ArrayList<String> unstableData = partialResults.getStringArrayList("android.speech.extra.UNSTABLE_TEXT");
        mResult = data.get(0) + unstableData.get(0);
    }
    

    【讨论】:

      【解决方案2】:

      为了让答案更清楚一点,您需要先启用部分结果,并以特定方式调用 UNSTABLE_TEXT:

      // When creating the intent, set the partial flag to true
      intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS,true); 
      
      // When requesting results in onPartialResults(), the UNSTABLE_TEXT parameter to getSTtringArrayList() must be in quotes
      ArrayList<String> unstableMatches = partialResults.getStringArrayList("android.speech.extra.UNSTABLE_TEXT");
      

      onPartialResults() 现在被多次调用,而 onError() 仍然会使用 ERROR_NO_MATCH 调用。我最终使用了类似于此处列出的解决方案:https://github.com/nenick/QuAcc/blob/master/app/src/main/java/de/nenick/quacc/speechrecognition/speech/RecognizerListenerWithOfflineWorkaround.java

      简而言之:

      • 跟踪部分结果以及是否显示错误
      • 在 onBeginningOfSpeech() 中重置两者
      • 在调用 onPartialResults() 时将部分结果存储在变量中
      • 当 onError() 被调用时,检查结果是否为 ERROR_NO_MATCH 并将 SpeechRecognizer.RESULTS_RECOGNITION 与“android.speech.extra.UNSTABLE_TEXT”结合到您的部分结果变量中
      • 调用 onResults()

      【讨论】:

      • 链接不再有效。
      • 我修复了链接。应用而不是应用
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-05
      相关资源
      最近更新 更多