1

I have this code for text to speech in my application.

public void onInit(int status) {
    // TODO Auto-generated method stub
     if (status == TextToSpeech.SUCCESS) {
         //Setting speech language           
         int result = tts.setLanguage(Locale.ENGLISH);            
         //If your device doesn't support language you set above
         if (result == TextToSpeech.LANG_MISSING_DATA
                 || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                //Cook simple toast message with message
                Toast.makeText(this, "Language not supported", Toast.LENGTH_LONG).show();
                //Log.e("TTS", "Language is not supported");
         }                 
         //TTS is not initialized properly
     } else {
                Toast.makeText(this, "TTS Initilization Failed", Toast.LENGTH_LONG).show();
                //Log.e("TTS", "Initilization Failed");
     }
}

My application includes many different languages like English, Hindi, Marathi, Telugu, Tamil, etc. Since the default android tts engine does not support these languages, I downloaded eSpeak tts engine from this link and installed it on my phone.

Its default language is set as English. How do i change its language in my code so that it can read unicode texts of other languages as well?

Currently, for a word in hindi script, it speaks some numbers.

How do i make it recognise the language used in the text? It shows only the locales available in the default google tts. How do I change the tts engine to eSpeak tts?

newbee
  • 409
  • 2
  • 12
  • 34

2 Answers2

1

Initialize your TextToSpeech using

TextToSpeech (Context context, TextToSpeech.OnInitListener listener, String engine)

That is

tts = new TextToSpeech(this, this, "com.googlecode.eyesfree.espeak");

engine Package name of the TTS engine to use, which you can get by calling getEngines.

Hoan Nguyen
  • 18,033
  • 3
  • 50
  • 54
  • could you please explain in detail? When i initialize it like this, eclipse shows Context cannot be resolved into a variable, TextToSpeech.OnInitListener cannot be resolved into a variable....... – newbee Jul 04 '13 at 07:03
  • i have the eSpeak tts installed on my phone. When i code in eclipse, how do i make it recognize this engine? are there some steps that im missing? Please help. I am new to android – newbee Jul 04 '13 at 14:31
0

Try changing the Locale according to your need.

Currently it is Locale.ENGLISH change this accordingly.

Mr_Hmp
  • 2,474
  • 2
  • 35
  • 53
  • yeah.. but this does not detect eSpeak tts. It shows only the locales available in the default google tts. How do I change the tts engine to eSpeak tts? – newbee Jul 02 '13 at 17:52