【问题标题】:Using SpeechRecognizer with a custom keyboard if com.google.android.googlequicksearchbox is disabled如果禁用 com.google.android.googlequicksearchbox,则使用 SpeechRecognizer 和自定义键盘
【发布时间】:2022-07-12 23:23:21
【问题描述】:

我有一个特定的用例,我需要禁用 com.google.android.googlequicksearch,但是当我这样做时,我不再能够为我的自定义键盘使用语音识别。有没有办法解决这个问题,或者有办法在我的应用程序中手动包含该依赖项,但没有在设备上启用该应用程序。

这是我尝试初始化 SpeechRecognizer 的方法。我还在清单中为 android.speech.RecognitionService 添加了查询标签

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if(ContextCompat.checkSelfPermission(this,Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED){
        checkPermission();
    }
    //////////
    printListofSupportedLanguages();
    /////////
    editText = findViewById(R.id.text);
    micButton = findViewById(R.id.button);
    final Intent speechRecognizerIntent;
    speechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    try {
        speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this,
                ComponentName.unflattenFromString("android.speech.RecognitionService/com.google.android.voicesearch.serviceapi.GoogleRecognitionService")));

        Log.d(TAG,"SpeechRecognizer Created");
             speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    } catch (Exception e) {
        e.printStackTrace();
        Log.e(TAG,"Exception Rec:"+e.getMessage());
    }

【问题讨论】:

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


    【解决方案1】:

    如果 com.google.android.quicksearchbox 被禁用,它似乎不太可能为您的应用程序进行语音识别。 如果也没有安装其他可以处理 SpeechRecognizer 请求的应用程序,那么它根本就无法工作。

    但是,您可以将语音识别 SDK 集成到您的应用中,并以这种方式进行语音识别。 例如,华为有 ML Kit ASR SDK,您可以将其作为依赖项集成到您的应用中,并在您的应用中进行语音识别:https://developer.huawei.com/consumer/en/doc/development/hiai-Guides/ml-asr-0000001050066212

    请注意,支持的语言数量有限,尤其是在非华为手机上。 您也可以查看其他公司为此目的提供的 SDK。

    (免责声明:我在华为工作)

    【讨论】:

      猜你喜欢
      • 2017-05-17
      • 2010-11-11
      • 2018-06-01
      • 2012-10-03
      • 2016-11-29
      • 1970-01-01
      • 2018-01-30
      • 2017-04-09
      • 1970-01-01
      相关资源
      最近更新 更多