【发布时间】: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