android - Why is it not sleeping for 3 seconds before it starts listening? -


i'm trying do:

  1. perform texttospeech
  2. speechrecognizer starts listening user repeats texttospeech'd word/phrases

but problem that, example, if "example" via texttospeech, when speechrecognizer starts listening, takes in "example" previous , adds onto 1 user says. @ end, ended "example example", didn't want.

code:

public void onitemclick(adapterview<?> parent, view view, int position,         long id) {     // todo auto-generated method stub     item = (string) parent.getitematposition(position);      tts.speak(item, texttospeech.queue_flush, null);     thread thread = new thread() {         public void run() {             try {                 sleep(3000);             } catch (interruptedexception e) {                 e.printstacktrace();             }         }     };     thread.start();     sr.startlistening(srintent); } 

you doing 2 process in 2 thread. creating thread 1 , make sleep 3 seconds , sr.startlistening(srintent); start intent in separate ui thread. start intent immediately. use both process in 1 thread post below

public void onitemclick(adapterview<?> parent, view view, int position,     long id) { // todo auto-generated method stub item = (string) parent.getitematposition(position);  tts.speak(item, texttospeech.queue_flush, null); thread thread = new thread() {     public void run() {         try {             sleep(3000);         } catch (interruptedexception e) {             e.printstacktrace();         }     mspeech.sendemptymessage(0);     } }; thread.start(); 

}

create 1 inner handler class perform ui operations

private handler mspeech=new handler(){     public void handlemessage(android.os.message msg) {          sr.startlistening(srintent);     } }; 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -