2014-07-25 2 views
2

TTS (Text to Speech)를 사용하여 명령을 내린 다음 음성 인식 의도를 사용하여 사용자의 음성 답변을 듣는 Android 앱을 개발했습니다.TTS 종료 말하기 전에 음성 인식 의도가 시작됩니다.

명백히 말하면, tts가 말하기를 끝내면 음성 인식의 의도가 던져집니다. 때로는 주로 활동에서 다른 활동으로 이동하거나 버튼을 통해이 과정을 활성화 할 때, 음성 인식기의 의도는 TTS 완료 전에 시작됩니다! 문제는 사용자의 단어 대신 명령의 동일한 텍스트를 가져 와서 분석한다는 것입니다. 음성 인식기에 대기 할 코드 부분은 다음과 같습니다.

while(tts.isSpeaking()){ 
    //DOING NOTHING 
} 
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US"); 

try { 
     startActivityForResult(intent, RESULT_SPEECH); 
} catch (ActivityNotFoundException a) { 
    Toast t = Toast.makeText(getApplicationContext(),"Opps! Your device doesn't support Speech to Text", Toast.LENGTH_SHORT); 
    t.show(); 
}  

아무도 해결책이 있습니까? 꽤 무작위 인 것 같습니다. 때로는 기다리지 만 때로는 그렇지 않습니다. 감사합니다! tts.isSpeaking()는 여러 가지 이유로 쓸모가 사용

답변

2

, 당신은 자세한 내용은이를 읽을 수 있습니다

Problem with isSpeaking() when using Text-to-Speech on Android

Intead, 당신이 리스너 작동하도록 OnUtteranceProgressListener이

tts.setOnUtteranceProgressListener(new UtteranceProgressListener() { 
     @Override 
     public void onStart(String utteranceId) { 
      // Nothing 
     } 

     @Override 
     public void onError(String utteranceId) { 
      // Nothing 
     } 

     @Override 
     public void onDone(String utteranceId) { 
      // Restart recognizer here 

있다는 점 유의 하시길 바랍니다 설정해야합니다 tts.speak 호출에서 params를 사용하여 TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID을 설정해야합니다.

0

다음은 샘플입니다. 어떤 이유에서 주 스레드에서 speechRecognizer를 시작해야 할 수도 있습니다.

tts.setOnUtteranceProgressListener (새 UtteranceProgressListener() {

   @Override 
       public void onStart(String utteranceId) { 

       } 

       @Override 
       public void onDone(String utteranceId) { 
        if (utteranceId.contains(<utterance_id_you_set>)){ 
         Handler mainHandler = new Handler(getApplicationContext().getMainLooper()); 

         Runnable myRunnable = new Runnable() { 
          @Override 
          public void run() { 
           //start your recognizer here 
          } 
         }; 
         mainHandler.post(myRunnable); 

        } 
       } 

       @Override 
       public void onError(String utteranceId) { 

       } 
      }); 
     } 
    });