【问题标题】:SpeechRecognizer: no selected voice recognition serviceSpeechRecognizer:没有选择语音识别服务
【发布时间】:2017-03-20 19:27:23
【问题描述】:

这就是我开始 RecogniseListener 意图的方式:

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);   
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);

intent.putExtra("android.speech.extra.DICTATION_MODE", true);               
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,this.getPackageName());
intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,1);
sr.startListening(intent);

但是,我得到了一个奇怪的行为。它适用于某些手机(在本例中为三星 Galaxy S5),但在联想 K50-T5 上出现以下错误:

E/SpeechRecognizer: no selected voice recognition service

这是我的 AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="lips.deafcommunication.deaflips">

<uses-permission android:name="android.permission.RECORD_AUDIO" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppThemeNoBar">
    <activity android:name=".MainActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".ChatInProgressActivity" android:screenOrientation="portrait"
                android:windowSoftInputMode="adjustPan"
                android:configChanges="keyboardHidden|orientation|screenSize"
        ></activity>
</application>
</manifest>

【问题讨论】:

  • 我得到同样的错误,因为如果你去移动设备设置>语言和输入>语音输入>你会发现两个选项默认没有选择

标签: java android speech-recognition speech-to-text


【解决方案1】:

在我的情况下,如果他/她默认未选择语音识别器服务,则用户设备会发出此警告情况这是设置此问题的照片,您在照片中看到默认情况下未选择服务,

通过显式添加 GoogleRecognitionService 到我的SpeechRecognizer 来解决这个问题,最后我的代码看起来像这样

 this.speechRecognizer = SpeechRecognizer.createSpeechRecognizer(getActivity(), ComponentName.unflattenFromString("com.google.android.googlequicksearchbox/com.google.android.voicesearch.serviceapi.GoogleRecognitionService"));

所以你的代码看起来像你使用默认的语音意图,在这里制作你自己的自定义识别监听器是链接到How can I use speech recognition without the annoying dialog in android phones

注意:确保已安装Google app

【讨论】:

  • 这是一个根本错误的解决方案:“googlequicksearchbox”可能没有安装,或者将来可能不会安装,或者可能不是用户想要使用的。正确的解决方案是通知用户没有安装/选择识别器,然后打开一个对话框帮助用户进行安装/选择。
  • 通知用户没有识别器是 UX 的一部分,我只是展示了我认为程序员足够聪明的问题,可以通知用户在调用谷歌语音之前没有识别器检查
  • 到目前为止,Hamza 在 createSpeechRecognizer 中提供 ComponentName 的解决方案是唯一对我有用的方法。我一辈子都找不到在任何 Android 设备上“安装”识别器的位置或方式。
  • 确保您已在手机中安装 Google 应用程序大部分手机默认有一段时间被用户 play.google.com/store/apps/… 禁用
  • 谢谢,成功了。也可以把这个check做这个万无一失stackoverflow.com/a/56319307/4411645
【解决方案2】:

这意味着用户根本没有安装语音识别器,或者没有配置运行。您无法解决此问题,用户必须安装一个。

【讨论】:

    【解决方案3】:

    该错误表明没有可用的语音识别器服务。您应该在调用 SpeechRecognizer.createSpeechRecognizer 之前测试这种情况。

    import android.speech;
    
    if(SpeechRecognizer.isRecognitionAvailable(this)) {
        SpeechRecognizer sr = SpeechRecognizer.createSpeechRecognizer(this);
    } else {
        // SOME SORT OF ERROR
    }
    

    【讨论】:

      【解决方案4】:

      为了使Hamza's solution 万无一失,您可以添加以下检查,以预先排除startVoiceRecognition() 上的日志中的不同错误

      private static final String GOOGLE_RECOGNITION_SERVICE_NAME = "com.google.android.googlequicksearchbox/com.google.android.voicesearch.serviceapi.GoogleRecognitionService"
      
      public static boolean isSpeechRecognizerAvailable() {
          if (sIsSpeechRecognizerAvailable == null) {
              boolean isRecognitionAvailable = context != null && context.getPackageManager() != null
                      && SpeechRecognizer.isRecognitionAvailable(context);
              if (isRecognitionAvailable) {
                  ServiceConnection connection = new ServiceConnection() {
                      @Override
                      public void onServiceConnected(ComponentName name, IBinder service) {
      
                      }
      
                      @Override
                      public void onServiceDisconnected(ComponentName name) {
      
                      }
                  };
                  Intent serviceIntent = new Intent(RecognitionService.SERVICE_INTERFACE);
                  ComponentName recognizerServiceComponent = ComponentName.unflattenFromString(GOOGLE_RECOGNITION_SERVICE_NAME);
                  if (recognizerServiceComponent == null) {
                      return false;
                  }
      
                  serviceIntent.setComponent(recognizerServiceComponent);
                  boolean isServiceAvailableToBind = context.bindService(serviceIntent, connection, Context.BIND_AUTO_CREATE);
                  if (isServiceAvailableToBind) {
                      context.unbindService(connection);
                  }
                  sIsSpeechRecognizerAvailable = isServiceAvailableToBind;
              } else {
                  sIsSpeechRecognizerAvailable = false;
              }
          }
          return sIsSpeechRecognizerAvailable;
      }
      

      然后使用相同的组件名称来初始化语音识别器

      this.speechRecognizer = SpeechRecognizer.createSpeechRecognizer(context, ComponentName.unflattenFromString(GOOGLE_RECOGNITION_SERVICE_NAME));
      

      【讨论】:

      • 什么是“GOOGLE_RECOGNITION_SERVICE_NAME”?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-26
      • 1970-01-01
      • 2014-10-04
      相关资源
      最近更新 更多