绕过Android UI错误屏幕语音识别

时间:2014-01-28 22:45:44

标签: java android android-intent processing speech-recognition

所以我正在开发一个使用googles API的语音识别程序。我在基于Java的IDE“Processing”中实现了这一点。

一切正常,但我试图绕过暂停会话的系统错误对话框,直到我再次点击(无法发布图片,但这是一个指向错误对话的链接):

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

我一直在深入研究API几个小时,但我仍然不知道如何禁用此提示。

编辑:我已经使用了提供的参考资料而没有太多运气在Processing中实现它。我不知道我错过了什么。 代码如下:

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

}

0 个答案:

没有答案