2012-10-13 3 views
2

"지금 말하기"대화 상자를 프로그래밍 방식으로 열 수 있습니까?"지금 말하기"대화 상자를 프로그래밍 방식으로 열 수 있습니까?

현재 사용자가 '검색'버튼을 누르면 대화 상자가 열리고 자동으로 소프트 키보드가 열리므로 사용자가 textedit 필드를 탭하지 않아도됩니다.

다른 '음성 검색'을 사용하면 대화 상자가 열리고 '지금 말하기'창이 자동으로 열립니다. 따라서 사용자는 키보드의 '마이크'버튼을 찾아서 탭하지 않아도됩니다.

아이디어가 있으십니까?

답변

3

예, 가능합니다. 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); 
} 
관련 문제