我是android中的新成員,目前正在開發適用於Voice Command API的小型應用程序。例如,如果我說藍牙,它會將手機的藍牙切換到開/關模式(反之亦然)。如何在Android中使用語音命令API
請幫我做這件事....在Anvance
謝謝...
我是android中的新成員,目前正在開發適用於Voice Command API的小型應用程序。例如,如果我說藍牙,它會將手機的藍牙切換到開/關模式(反之亦然)。如何在Android中使用語音命令API
請幫我做這件事....在Anvance
謝謝...
這是相當簡單的使用方法:
private void startVoiceRecognitionActivity() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
//uses free form text input
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
//Puts a customized message to the prompt
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
getString(R.string.listenprompt));
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
/**
* Handles the results from the recognition activity.
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
// Fill the list view with the strings the recognizer thought it could have heard
ArrayList<String> matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
//Turn on or off bluetooth here
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
然後調用從startVoiceRecognitionActivity()
內的代碼,無論你需要它。當然,你需要有熱情才能訪問互聯網
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
在你的Android.manifest。
對不起親愛的這麼晚回覆,因爲現在我已經用它。它的工作非常好。 –
我得到了可能的文本值Arraylist,但我怎麼可以打開/關閉藍牙。 –
這是一個不同的問題,但[lmgtfy](http://goo.gl/aB3be)。 – keyboardsurfer