using eSpeak tts engine in application

帅比萌擦擦* 提交于 2020-01-24 21:14:05

问题


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?


回答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.




回答2:


Try changing the Locale according to your need.

Currently it is Locale.ENGLISH change this accordingly.



来源:https://stackoverflow.com/questions/17431858/using-espeak-tts-engine-in-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!