• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Need loop code or ?

Flinx

Lurker
I have problem with voice recognition code, works first part but then uses 1st 'results' in the google search method... ugh..

code:

if (results.contains("play")){


Handler handler4 = new Handler();
handler4.postDelayed(new Runnable() {
public void run() {

mTts.speak("Play What?", TextToSpeech.QUEUE_FLUSH, null);
}
}, 1000);

Handler handler5 = new Handler();
handler5.postDelayed(new Runnable() {
public void run() {

Intent g = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

g.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
g.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak UP!");
g.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);


final ArrayList<String> results1 = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
startActivityForResult(g, check);

Handler handler4 = new Handler();
handler4.postDelayed(new Runnable() {
public void run() {

Intent sgoogle = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com/search?q=%22"+results1+"%22"));
startActivityForResult(sgoogle, check);
}
}, 12000);

}
}, 5000);

It is suppose to react to word 'play' which it does, then TTS ask "Play what?", which it does.. and then open recognizer, which it does.. then take results to google search, which is where its broken.. because it uses the 1st results of 'play' ..

Thank you in advance.
Flinx
 
Back
Top Bottom