0

So I am working on a speech recognition program utilizing googles API. I am implementing this in the java based IDE, "Processing".

everything works fine, but I am trying to bypass the system error dialogue box that pauses the session until i click again (cant post an image but heres a link to the error dialogue):

http://www.pocketables.com/images/2013/06/didnt-catch-304x280.jpg

I've been digging into the API for hours, but im still at a loss how to disable this prompt.

EDIT: i've used the references supplied without much luck implementing it in Processing. Im not sure what I am missing. code below:

   import java.util.*;

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

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

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

 *************************************************************************/
PFont androidFont;
String [] fontList;
int VOICE_RECOGNITION_REQUEST_CODE = 1234;
  SpeechRecognizer recognizer;
Intent intent;
/************************************************************************

 --------------------------------  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 = 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);

}
@Override
void onActivityResult(int requestCode, int resultCode, Intent data) {


  recognizer = SpeechRecognizer.createSpeechRecognizer(this);

recognizer.setRecognitionListener(new listener());
               recognizer.startListening(intent);

  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);


}




/*************RECOGNITION LISTENER CLASS*************************/


 class listener implements RecognitionListener {


    @Override
    public void onBeginningOfSpeech() {
       println("onBeginningOfSpeech");
    }

    @Override
    public void onBufferReceived(byte[] buffer) {
      println( "onBufferReceived");
    }

    @Override
    public void onEndOfSpeech() {
      println( "onEndOfSpeech");
    }

    @Override
    public void onError(int error) {
  startVoiceRecognitionActivity();

    println( "onError = " + error);

    }

    @Override
    public void onEvent(int eventType, Bundle params) {
      println( "onEvent");
    }

    @Override
    public void onPartialResults(Bundle partialResults) {
     println("onPartialResults");
    }

    @Override
    public void onReadyForSpeech(Bundle params) {
   println("onReadyForSpeech");
    }


    @Override
    public void onResults(Bundle results) {
    //ArrayList<String>  suggestedWords = results.getStringArrayList(RecognizerIntent.EXTRA_MAX_RESULTS);

    println( "results = " + results);

    }


    @Override
    public void onRmsChanged(float rmsdB) {
 //println( "onRmsChanged");
    }

}
danieljay
  • 113
  • 2
  • 11
  • Wasn't it discussed many times already? http://stackoverflow.com/questions/6316937/how-can-i-use-speech-recognition-without-the-annoying-dialog-in-android-phones – Nikolay Shmyrev Jan 29 '14 at 08:03
  • Yes, specifically: http://stackoverflow.com/a/6317055/29505 – cbrulak Jan 29 '14 at 18:11
  • You have to create your own dialog or use speech recognition without dialog. – Hoan Nguyen Jan 29 '14 at 19:11
  • hey Hoan, im not sure what you mean exactly. – danieljay Jan 29 '14 at 19:21
  • Look at http://stackoverflow.com/questions/16228817/android-speech-recognition-app-without-pop-up/16229256#16229256 – Hoan Nguyen Jan 29 '14 at 20:06
  • I have attempted the best I can with my limited Java knowledge to attempt to disable the pop up dialogue box. I am way in over my head, and no matter how many forum posts ive read for the past 3 days (including all of your suggestions), this is the best I can do. does anyone have a streamlined answer of what I specifically am doing wrong as oppose to throwing links at me? it would be alot more constructive for me. – danieljay Jan 29 '14 at 20:32
  • most of your suggestions point to HOW to use the SpeechRecognition class, as here http://stackoverflow.com/questions/1703148/is-it-possible-to-use-androids-speech-recognition-without-showing-the-dialog but i have yet to find a straight forward answer on the issue anywhere. im completely new to this, and want to be aware what i am overlooking with my current sketch. not references on how to use the speechrecognition class since im apparently confused wit my attempts – danieljay Jan 29 '14 at 23:15

0 Answers0