我使用android.speech.SpeechRecognizer
,只有通过蓝牙连接到配对手机才能正常工作。如果我停用手机的蓝牙,SpeechRecognizer
将停止工作。这适用于与iPhone或Android手机配对。活跃的电话连接真的是一个约束吗?
答案 0 :(得分:1)
检查文档,看起来仍然可以通过使用系统的SpeechRecognizer活动来完成。
您只需使用startActivityForResult
设置来调用ACTION_RECOGNIZE_SPEECH
,这将启动活动并通过onActivityResult
private static final int SPEECH_REQUEST_CODE = 0;
// Create an intent that can start the Speech Recognizer activity
private void displaySpeechRecognizer() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
// Start the activity, the intent will be populated with the speech text
startActivityForResult(intent, SPEECH_REQUEST_CODE);
}
// This callback is invoked when the Speech Recognizer returns.
// This is where you process the intent and extract the speech text from the intent.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) {
List<String> results = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
String spokenText = results.get(0);
// Do something with spokenText
}
super.onActivityResult(requestCode, resultCode, data);
}