2016-10-11 53 views

回答

1

檢查文檔時,它看起來仍然可以通過使用系統的SpeechRecognizer活動完成。

你只需要調用startActivityForResultACTION_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); 
} 
+0

能否請你點我指出,我們只需要一個藍牙連接的文件如果我們直接使用'SpeechRecognizer'? –

+0

我的目標是實際上不使用系統活動(因爲它會離開我們的用戶界面)並在我們的應用程序中識別語音。 –

+0

[這是[培訓文檔](https://developer.android.com/training/wearables/apps/voice.html#FreeFormSpeech)我指的是。它將系統提供的語音操作定義爲基於任務並且內置於穿戴平臺本身。我相信這是您可能需要在磨損應用程序本身中識別講話的內容。 – adjuremods