TextToSpeech issuse

All your problems with Audio, Video and Images.

TextToSpeech issuse

Postby jbnonn79@gmail » Fri Nov 11, 2011 11:34 pm

I have been trying to get this to work with no luck. When I try and click on the textview box in the following code, it make the screen go back and does nothing. I want when I click on the textview box it will say what ever is inside the box. But also with out changing the screen. Can someone please give me some help on what I am doing wrong.

The following is the MainActivity:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.app.Activity;
  2. import android.os.Bundle;
  3. import android.widget.Button;
  4. import android.widget.TextView;
  5. import android.view.Menu;
  6. import android.view.MenuInflater;
  7. import android.view.MenuItem;
  8. import android.view.View;
  9. import android.view.View.OnClickListener;
  10. import android.content.Intent;
  11.  
  12. public class MainActivity extends Activity
  13. {
  14.        
  15.         @Override
  16.     public void onCreate(Bundle savedInstanceState)
  17.     {
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.layout_24);
  20.         ((TextView)findViewById(R.id.mainText)) .setOnClickListener(textspeak);
  21.         ((Button)findViewById(R.id.btnClear)) .setOnClickListener(clearbutton);
  22.     }
  23.    
  24.         OnClickListener textspeak = new OnClickListener()
  25.         {
  26.                 public void onClick(View v)
  27.                 {
  28.                 Intent intent = new Intent(MainActivity.this, TTSActivity.class);
  29.                 MainActivity.this.startActivityForResult(intent, 0);
  30.                 }
  31.         };
  32.        
  33.     OnClickListener clearbutton = new OnClickListener()
  34.     {
  35.         public void onClick(View v)
  36.         {
  37.                 TextView mainText = (TextView)findViewById(R.id.mainText);
  38.             mainText.setText("");
  39.         }
  40.     };
  41.    
  42.     @Override
  43.     public boolean onCreateOptionsMenu(Menu menu)
  44.     {
  45.         MenuInflater inflater = getMenuInflater();
  46.         inflater.inflate(R.menu.menu, menu);
  47.         return true;
  48.     }
  49.    
  50.     @Override
  51.     public boolean onOptionsItemSelected(MenuItem item)
  52.     {
  53.         switch (item.getItemId())
  54.         {
  55.         case R.id.select8icons: setContentView(R.layout.layout_8);
  56.                 break;
  57.         case R.id.select24icons: setContentView(R.layout.layout_24);
  58.                 break;
  59.         case R.id.select63icons: setContentView(R.layout.layout_63);
  60.                 break;
  61.         }
  62.         return true;
  63.     }
  64. }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


This is the TTSActivity:

Syntax: [ Download ] [ Hide ]
  1. import android.app.Activity; 
  2. import android.content.Intent; 
  3. import android.os.Bundle; 
  4. import android.speech.tts.TextToSpeech; 
  5. import android.view.View; 
  6. import android.widget.TextView; 
  7.  
  8. public class TTSActivity extends Activity implements TextToSpeech.OnInitListener 
  9. private TextToSpeech tts; 
  10.  
  11. private static final int MY_DATA_CHECK_CODE = 1234; 
  12.  
  13. @Override 
  14. public void onCreate(Bundle savedInstanceState) 
  15. super.onCreate(savedInstanceState); 
  16. Intent checkIntent = new Intent(); 
  17. checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); 
  18. startActivityForResult(checkIntent, MY_DATA_CHECK_CODE); 
  19.  
  20.  
  21. public void speakClicked(View v) 
  22. TextView editText = (TextView) findViewById(R.id.mainText); 
  23. tts.speak(editText.getText().toString(), 
  24. TextToSpeech.QUEUE_FLUSH, 
  25. null); 
  26.  
  27. public void onInit(int i) 
  28.  
  29.  
  30. public void onActivityResult(int requestCode, int resultCode, Intent data) 
  31. if (requestCode == MY_DATA_CHECK_CODE) 
  32. if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) 
  33. tts = new TextToSpeech(this, this); 
  34. else 
  35. Intent installIntent = new Intent(); 
  36. installIntent.setAction( 
  37. TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); 
  38. startActivity(installIntent); 
  39.  
  40. @Override 
  41. public void onDestroy() 
  42. if (tts != null) 
  43. tts.stop(); 
  44. tts.shutdown(); 
  45. super.onDestroy(); 
jbnonn79@gmail
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Nov 11, 2011 11:26 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 11 guests