disable UI element speech recognition Android API

edited January 2014 in Android Mode

Hey all,

So I am using Googles speech recognition API on Android with success. I am having a bit of a difficult time though in understanding how to specifically disable a particular UI element. the problem is when I begin to record, and if google doesnt quite catch what was said (a cough or bump on mic), the dialogue box, "Didn't catch that. Try speaking again" pops up. This pauses the process of the program, which I want to eliminate.

I've seen the same question here: stackoverflow.com/questions/14728219/speech-api-recognizerintent-bypass-the-didnt-catch-that-try-speaking-again-m

but am having a bit of difficulty with the API. Here is my script thus far:

import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.speech.RecognizerIntent;

/************************************************************************

 --------------------------------  DATAS ---------------------------------

 *************************************************************************/
PFont androidFont;
String [] fontList;
int VOICE_RECOGNITION_REQUEST_CODE = 1234;

/************************************************************************

 --------------------------------  SETUP ---------------------------------

 *************************************************************************/
void setup() {
  orientation(LANDSCAPE);
  fontList = PFont.list();
  androidFont = createFont(fontList[0], 18, true);
  textFont(androidFont);


  PackageManager pm = getPackageManager();
  ArrayList<ResolveInfo> activities = (ArrayList<ResolveInfo>)pm.queryIntentActivities(
  new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
  if (activities.size() != 0) {
   // text("il y a un recognizer!", 20, 60);
  } 
  else {
    //text("Recognizer not present", 20, 60);
  }
}

/************************************************************************

 --------------------------------  DRAW ---------------------------------

 *************************************************************************/

void draw() {
}
/************************************************************************

 --------------------------------  EVENTS ---------------------------------

 *************************************************************************/

void mousePressed() {
  startVoiceRecognitionActivity();
}

void startVoiceRecognitionActivity() {
  Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
  intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
  intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
  startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}

void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
    background(0);
    // Fill the list view with the strings the recognizer thought it could have heard
    ArrayList<String>  matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
    String s[] = (String[]) matches.toArray(new String[matches.size()]);
    fill(255);
    for (int i=0; i<s.length; i++) {
      text(s[0], 60, 20);
      //println(s[i]);
    }
  }

  super.onActivityResult(requestCode, resultCode, data);
}
Sign In or Register to comment.