2012-06-28 3 views
3

나는 항상 사용자의 음성을 듣는 Android 응용 프로그램을 개발 중입니다. Sony X10i에서 실행하면 작동하지만 Samsung Galaxy SII에서는 작동하지 않습니다.Galaxy SII에서 음성 인식 수신기가 작동하지 않습니다.

다음
SpeechRecognizer  speechRecognizer; 
    speechRecognizer = SpeechRecognizer.createSpeechRecognizer(getBaseContext()); 
    MyRecognitionListener speechListner=new MyRecognitionListener(); 
    speechRecognizer.setRecognitionListener(speechListner); 
    speechRecognizer.startListening(RecognizerIntent.getVoiceDetailsIntent(getApplicationContext())); 

내 리스너 클래스입니다 :이 경우

class MyRecognitionListener implements RecognitionListener { 

    public void onBeginningOfSpeech() { 
     Log.d("leapkh", "onBeginningOfSpeech"); 
    } 

    public void onBufferReceived(byte[] buffer) { 
     Log.d("leapkh", "onBufferReceived"); 
    } 

    public void onEndOfSpeech() { 
     Log.d("leapkh", "onEndOfSpeech"); 
    } 

    public void onError(int error) { 
     Log.d("leapkh", "onError"); 
    } 

    public void onEvent(int eventType, Bundle params) { 
     Log.d("leapkh", "onEvent"); 
    } 

    public void onPartialResults(Bundle partialResults) { 
     Log.d("leapkh", "onPartialResults"); 
    } 

    public void onReadyForSpeech(Bundle params) { 
     Log.d("leapkh", "onReadyForSpeech"); 
    } 


    public void onResults(Bundle results) { 
     Log.d("leapkh", "onResults"); 

    } 

    public void onRmsChanged(float rmsdB) { 
     Log.d("leapkh", "onRmsChanged"); 
    } 
} 

, 어떻게이 문제를 해결하기 여기 내 코드?

답변

7

해결책을 찾았습니다.

변경 다음과 같이 intentspeechRecognizer.startListening() 방법의 매개 변수 :

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); 
    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getApplication().getPackageName()); 
    speechRecognizer.startListening(intent); 
0

변경이 또한 의도

{ 
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 

intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en"); 

intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, 
       this.getPackageName()); 

intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, 
       RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); 

intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3); 

    if (speech != null) { 
      speech = null; 

     } 

     SpeechRecognizer speech SpeechRecognizer.createSpeechRecognizer(this); 

     speech.setRecognitionListener(this); 

     speech.startListening(intent); 

}

로 전달하는 매개 변수가 오류의 유형을 확인하면 nomatch, 네트워크 및 서버 오류 호출에 대해 을 받고 있습니다. 다시 시작 수신 대기

public void startListening() { 
    try { 

     if (SpeechRecognizer.isRecognitionAvailable(this)) { 
      if (speech != null) { 
       speech.startListening(intent); 

      } else { 
       SimpleMethod(); 
      } 
     } 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
}