【问题标题】:Offline SpeechRecognizer on Android is not workingAndroid 上的离线 SpeechRecognizer 无法正常工作
【发布时间】:2017-03-23 09:36:45
【问题描述】:

我正在使用 SpeechRecognizer。问题是如果没有活动的 Internet 连接 SpeechRecognizer 将抛出错误 SpeechRecognizer.ERROR_NETWORKSpeechRecognizer.ERROR_SERVER

这是我的识别器意图

    final Intent recognizerIntent;
    recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, this.getPackageName());
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);

    recognizerIntent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true);

我把recognizerIntent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true);

但没有运气。再次它会抛出同样的错误。

我经常遇到这两个错误。

  1. SpeechRecognizer.ERROR_RECOGNIZER_BUSY
  2. SpeechRecognizer.ERROR_NO_MATCH

请帮帮我。

【问题讨论】:

    标签: java android speech-recognition offline


    【解决方案1】:

    首先,您需要确定您是否在设备上安装了您放入 EXTRA_LANGUAGE_PREFERENCE 的离线语言包。

    要在支持的设备中启用离线语音输入,请按照以下步骤操作:

    • 进入设置
    • 点击“语言和输入法”
    • 屏幕键盘
    • 选择 Google 语音输入
    • 选择离线语音识别
    • 安装所需语言

    如果它仍然无法离线工作,请尝试将您的 EXTRA_LANGUAGE_PREFERENCE 值更改为更具体的值,例如 "en-US"(这对我有用)

    另外,如果你想告诉SpeechRecognizer 它应该识别哪种语言,我猜你应该使用EXTRA_LANGUAGE 参数而不是EXTRA_LANGUAGE_PREFERENCE

    希望对你有帮助

    【讨论】:

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