2016-10-11 54 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