Note that there are some explanatory texts on larger screens.

plurals
  1. POSpeech Recognition in Surface View [android]
    primarykey
    data
    text
    <p>I am trying to make speech recognition in a surface view work. I am getting one small error.<br> Error:</p> <p>It's not drawing the text but its drawing the background.</p> <p>This line(#64):</p> <pre><code>c.drawARGB(255, 0, 0, 255); //works p.setTextSize(50); p.setColor(Color.WHITE); c.drawText("mText: "+mText, 500, 500, p); //does not work </code></pre> <p>Code:</p> <pre><code>package com.l3g3nds.virtual_dog; import java.util.ArrayList; import java.util.Random; import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.media.MediaPlayer; import android.os.Bundle; import android.speech.RecognitionListener; import android.speech.RecognizerIntent; import android.speech.SpeechRecognizer; import android.util.Log; import android.view.MotionEvent; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.view.View.OnTouchListener; import android.widget.TextView; @TargetApi(8) public class Main extends SurfaceView implements Runnable, OnTouchListener{ Thread t; boolean ok, started; SurfaceHolder holder; private String mText; private SpeechRecognizer sr; private static final String TAG = "MyStt3Activity"; public Main(Context context) { super(context); holder = getHolder(); setOnTouchListener(this); sr = SpeechRecognizer.createSpeechRecognizer(context); sr.setRecognitionListener(new listener()); mText = "nothing"; ok = false; t = null; } public void run() { while(ok == true) { if(!(holder.getSurface().isValid())) continue; Paint p = new Paint(); Canvas c = holder.lockCanvas(); c.drawARGB(255, 0, 0, 255); p.setTextSize(50); p.setColor(Color.WHITE); c.drawText("mText: "+mText, 500, 500, p); holder.unlockCanvasAndPost(c); } } public void pause() { ok = false; while(true){ try{ t.join(); }catch(Exception e){ e.printStackTrace(); } break; } t = null; } public void resume(){ ok = true; t = new Thread(this); t.start(); } @SuppressWarnings("deprecation") public boolean onTouch(View v, MotionEvent me) { int action = me.getAction(); if(action == MotionEvent.ACTION_DOWN){ Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test"); intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5); sr.startListening(intent); Log.i("111111","11111111"); } else if(action == MotionEvent.ACTION_UP){ } else if(action == MotionEvent.ACTION_MOVE){ } return true; } class listener implements RecognitionListener { public void onReadyForSpeech(Bundle params) { Log.d(TAG, "onReadyForSpeech"); } public void onBeginningOfSpeech() { Log.d(TAG, "onBeginningOfSpeech"); } public void onRmsChanged(float rmsdB) { Log.d(TAG, "onRmsChanged"); } public void onBufferReceived(byte[] buffer) { Log.d(TAG, "onBufferReceived"); } public void onEndOfSpeech() { Log.d(TAG, "onEndofSpeech"); } public void onError(int error) { Log.d(TAG, "error " + error); mText.equals("error " + error); } public void onResults(Bundle results) { String str = new String(); Log.d(TAG, "onResults " + results); ArrayList&lt;String&gt; data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); for (int i = 0; i &lt; data.size(); i++) { Log.d(TAG, "result " + data.get(i)); str += data.get(i); } //mText.setText("results: "+String.valueOf(data.size())); if(data.size() &gt; 0) mText.equals(String.valueOf(data.get(0))); } public void onPartialResults(Bundle partialResults) { Log.d(TAG, "onPartialResults"); } public void onEvent(int eventType, Bundle params) { Log.d(TAG, "onEvent " + eventType); } } } </code></pre> <p>I thought my class was a context? What am I doing wrong.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload