Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DTMF tone in RecognitionListener.onReadyForSpeech() mistaken for speech

The Google Voice Search comes with a significant delay from the moment you call it via startActivityForResult() until its dialog box is displayed, ready to take your speech.

This requires the user to always look at the screen, waiting for the dialog box to be displayed, before speaking.

So I was thinking of generating an audible signal instead of the dialog box by implementing RecognitionListener and sounding a DTMF tone in onReadyForSpeech() as in the following snippet:

  @Override
  public void onReadyForSpeech(Bundle params) {
    Log.d(LCTAG, "Called when the endpointer is ready for the user to start speaking.");
    mToneGenerator.startTone(ToneGenerator.TONE_DTMF_1);
    try {
      Thread.sleep(50);
    } catch (InterruptedException e) {
      Log.e(LCTAG, "InterruptedException while in Thread.sleep(50).");        
      e.printStackTrace();
    } // SystemClock.sleep(50);
    mToneGenerator.stopTone();
  }

The tone sounds beautifully but... it is also "heard" by the microphone, arriving to the voice recognition service and always generating a recognition error ERROR_NO_MATCH.

Is there a way to work around this?

like image 931
srf Avatar asked Apr 20 '11 17:04

srf


2 Answers

Here is a random idea, and it may very well not work.

Can you try disabling the microphone (maybe via AudioManager.setMicrophoneMute) while the tone is played?

like image 158
EboMike Avatar answered Oct 19 '22 18:10

EboMike


Here's my code that's working for me, put into the onReadyForSpeech() callback of the RecognitionListener.

private void playSpeechReadyTone(){
    audioManager.setMicrophoneMute(true);
    MediaPlayer mediaPlayer = MediaPlayer.create(JarvisService.this, R.raw.doublebeep);
    mediaPlayer.setOnCompletionListener(new OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer arg0) {
            audioManager.setMicrophoneMute(false);
        }
    });
    mediaPlayer.start();    
}
like image 20
Paul Avatar answered Oct 19 '22 17:10

Paul