예, 가능합니다. Android SDK에서 ApiDemos
샘플을 확인하십시오. VoiceRecognition
이라는 활동이 있으며 RecognizerIntent
을 사용합니다.
기본적으로, 당신이해야 할 일은 일부 엑스트라와 함께 적절한 의도를 저주하고 결과를 읽는 것입니다.
private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
private void startVoiceRecognitionActivity() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
// identifying your application to the Google service
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
// hint in the dialog
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
// hint to the recognizer about what the user is going to say
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
// number of results
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
// recognition language
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,"en-US");
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
ArrayList<String> matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
// do whatever you want with the results
}
super.onActivityResult(requestCode, resultCode, data);
}