1. Download our Official Android App: Forums for Android!

Apps TextTospeech

Discussion in 'Android Development' started by vijith, Apr 22, 2012.

  1. vijith

    vijith Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Feb 18, 2012

    Feb 18, 2012
    1
    0
    5
    Hello,
    I'm making text to speech application.
    I successfully implemented the application by referring some tutorials. And it works fine.
    But those tutorials use only one class to implement text to speech application.
    Now, I want to use two classes. One for main activity and another for text to speech.
    I tried to implement it. But the problem is that the text to speech conversion is not working. I can't hear any voice output.
    My codes are given below..

    Main activity class is...
    .........................................................
    Code (Text):
    1. import android.app.Activity;
    2. import android.app.AlertDialog;
    3. import android.os.Bundle;
    4.  
    5. public class Tts_2Activity extends Activity {
    6.     Speak speak;
    7.     /** Called when the activity is first created. */
    8.     @Override
    9.     public void onCreate(Bundle savedInstanceState) {
    10.         super.onCreate(savedInstanceState);
    11.         setContentView(R.layout.main);
    12.         //final Speak speak;
    13.        speak=new Speak(this);
    14.        
    15.        read();
    16.        
    17.     }
    18. public void read(){
    19.      try{
    20.             speak.spell("hai, testing");
    21.         }catch(Exception e){
    22.         new AlertDialog.Builder(this).setMessage(e.toString()).show();
    23.         }
    24. }
    25. }
    26.  
    class for text to speech conversion is....
    ..........................................................................................

    Code (Text):
    1. import java.util.Locale;
    2.  
    3. import android.app.AlertDialog;
    4. import android.content.Context;
    5. import android.speech.tts.TextToSpeech;
    6.  
    7. public class Speak implements TextToSpeech.OnInitListener{
    8.     TextToSpeech tts;
    9.      Context context;
    10.      public Speak(Context act_context)
    11.         {
    12.             context =act_context;
    13.             tts = new TextToSpeech(context, this);
    14.         }
    15.      public void onInit(int status) {
    16.          if (status == TextToSpeech.SUCCESS) {        
    17.                
    18.                 int result = tts.setLanguage(Locale.US);
    19.      
    20.                 if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
    21.                     new AlertDialog.Builder(context).setMessage("This Language is not supported").show();
    22.                     //Log.e("TTS", "This Language is not supported");
    23.                 }      
    24.             } else {
    25.                 new AlertDialog.Builder(context).setMessage("This Language is not supported").show();
    26.                 //Log.e("TTS", "Initialization Failed!");
    27.             }
    28.     }
    29.      public void spell(String text) {        
    30.          tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);        
    31.          }
    32.      public void onDestroy() {        
    33.            if (tts != null) {
    34.                tts.stop();
    35.                tts.shutdown();
    36.            }  
    37.      }
    38. }
    Please help me?
     

    Advertisement

  2. D-U-R-X

    D-U-R-X turbo drinker
    Rank:
    None
    Points:
    1,343
    Posts:
    16,878
    Joined:
    Apr 20, 2011

    Apr 20, 2011
    16,878
    7,194
    1,343
    Work to live, not the other way round!!
    Sheffield, South Yorkshire
    Hello and welcome to the forums - thanks for joining!

    Sorry, I can't help as I know nothing about development.

    I have moved your thread to the Development section of the forums, as you are most likely to get an answer from other devs from here.

    Hope you find this place useful - good luck with your app!
     
    vijith likes this.
  3. jonbonazza

    jonbonazza Android Expert
    Rank:
    None
    Points:
    163
    Posts:
    1,930
    Joined:
    Jul 13, 2010

    Jul 13, 2010
    1,930
    457
    163
    Male
    Please be sure to place your code inside of the
    Code (Text):
    1.  tags so that it retains its formatting. It's a pita to read when it is not in [CODE] tags.
    2.  
    3. Unfortunately, however, I have never really worked with TTS, so I cannot accurately answer your question.
     
    vijith likes this.

Share This Page

Loading...