Note that there are some explanatory texts on larger screens.

plurals
  1. POEmbedding a Voice in application, Android
    text
    copied!<p>This is my code's body, I want to embed the voice using TextToSpeech to read "Color is RED" and I don't know where and how to put it It always having problem by defining the variable for the String and TextToSpeech. Any help?</p> <pre><code> public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button buttonLoadImage = (Button)findViewById(R.id.loadimage); targetImage = (ImageView)findViewById(R.id.targetimage); buttonLoadImage.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, 0); }}); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK){ Uri targetUri = data.getData(); Bitmap bitmap; try { bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(targetUri)); targetImage.setImageBitmap(bitmap); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } final TextView textView = (TextView)findViewById(R.id.textView); final TextView textViewCol = (TextView)findViewById(R.id.textViewColor); final TextView textViewVal = (TextView)findViewById(R.id.textViewValue); targetImage.setOnTouchListener(new ImageView.OnTouchListener(){ TextToSpeech mTts ; public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub textView.setText("Touch coordinates : " + String.valueOf(event.getX()) + "x" + String.valueOf(event.getY())); ImageView imageView = ((ImageView)v); Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap(); int pixel = bitmap.getPixel((int)event.getX(),(int)event.getY()); textViewVal.setText("[" + Color.red(pixel) + "," + Color.green(pixel) + "," + Color.blue(pixel) + "]"); if ((Color.red(pixel) &gt; 200) &amp;&amp; (Color.blue(pixel) &lt; 10) &amp;&amp; (Color.green(pixel) &lt; 10)) { textViewCol.setText("Color is Red."); } return true; } }); } protected int valueOf(float x) { // TODO Auto-generated method stub return 0; } } </code></pre>
 

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