2
我正在使用android.speech.SpeechRecognizer
,它似乎只在通過藍牙連接到配對手機時才起作用。如果我禁用手機的藍牙,SpeechRecognizer
將停止工作。這適用於與iPhone或Android手機配對。活動的電話連接真的是一個限制嗎?SpeechRecognizer僅在Android Wear連接到智能手機時纔可用?
我正在使用android.speech.SpeechRecognizer
,它似乎只在通過藍牙連接到配對手機時才起作用。如果我禁用手機的藍牙,SpeechRecognizer
將停止工作。這適用於與iPhone或Android手機配對。活動的電話連接真的是一個限制嗎?SpeechRecognizer僅在Android Wear連接到智能手機時纔可用?
檢查文檔時,它看起來仍然可以通過使用系統的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);
}
能否請你點我指出,我們只需要一個藍牙連接的文件如果我們直接使用'SpeechRecognizer'? –
我的目標是實際上不使用系統活動(因爲它會離開我們的用戶界面)並在我們的應用程序中識別語音。 –
[這是[培訓文檔](https://developer.android.com/training/wearables/apps/voice.html#FreeFormSpeech)我指的是。它將系統提供的語音操作定義爲基於任務並且內置於穿戴平臺本身。我相信這是您可能需要在磨損應用程序本身中識別講話的內容。 – adjuremods