Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should read the article here: <a href="http://developer.android.com/resources/articles/tts.html" rel="nofollow">http://developer.android.com/resources/articles/tts.html</a></p> <p>But to do some simple text to speech, use code a bit like this:</p> <pre><code> private TextToSpeech mTts; private ImageView targetImage; private TextView textView; private TextView textViewCol; private TextView textViewVal; private boolean hasTTSBeenInitialized = false; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button buttonLoadImage = (Button) findViewById(R.id.loadimage); textView = (TextView) findViewById(R.id.textView); textViewCol = (TextView) findViewById(R.id.textViewColor); targetImage = (ImageView) findViewById(R.id.targetimage); textViewVal = (TextView) findViewById(R.id.textViewValue); buttonLoadImage.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, 0); } }); //Initialise tts here so you can use it at anytime in the activity. mTts = new TextToSpeech(this, new OnInitListener() { @Override public void onInit(int status) { hasTTSBeenInitialized = true; } }); mTts.setLanguage(Locale.US); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { 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) { e.printStackTrace(); } } targetImage.setOnTouchListener(touchListener); } OnTouchListener touchListener = new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { 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)) { //only attempt to play if tts has been initialised, if it hasnt then play it later when it has been initialised if(hasTTSBeenInitialized){ mTts.speak("Color is Red", TextToSpeech.QUEUE_FLUSH, null); }else{ //Maybe add it to a queue to play when it has been initialized } textViewCol.setText("Color is Red."); } return true; } }; </code></pre>
    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. VO
      singulars
      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