0

I am currently developing an app that makes intensive use of Text-To-Speech (I am using android.speech.tts.TextToSpeech) I have been able to integrate TTS in my voice and at present, a default American US voice is what reads aloud my text.

I would like to know how to make configurational changes to the speech engine. For example, I would like to reduce the speed at which the text is being read, swap between male and female voices and even provide support for different languages. Can anyone please help me with this information. Thanks in Advance :)

[Below is the code I am currently using (courtesy: a very well written basic blog on android TTS), all variable have been declared I am not copying the entire code, and this code snippet works just fine.]

btnSpeak = (ImageButton) findViewById(R.id.ttsIB);    
btnSpeak.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                speakOut();
            }

        });

@Override
    public void onDestroy() {
        // to shutdown TTS
        if (tts != null) {
            tts.stop();
            tts.shutdown();
        }
        super.onDestroy();
    }

    @Override
    public void onInit(int status) 
    {

        if (status == TextToSpeech.SUCCESS) 
        {
            int result = tts.setLanguage(Locale.US);

            if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED)
            {
                Log.e("TTS", "This Language is not supported");
            } 
            else 
            {
                btnSpeak.setEnabled(true);
                speakOut();
            }

        } 
        else 
        {
            Log.e("TTS", "Initilization Failed!");
        }

    }

    private void speakOut() 
    {

        String text = textVal.getText().toString();

        tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
    }
Darth Coder
  • 1,738
  • 7
  • 33
  • 56

1 Answers1

3

I've worked with TTS a couple of years ago and remember, that there were not so much configuration possibilities.

There is a useful method setEngineByPackageName(String packageName).

Some TTS engines have separate package names for every voice. For example, with Loquendo you need to write tts.setEngineByPackageName("com.loquendo.tts.susan") and your app will speak with US voice Susan.

But some TTS engines has common application and voices as plugins. So, you can configure it only this way:

tts.setEngineByPackageName("com.svox.pico");
tts.setLanguage(Locale.US);

If there are several US voices for this engine, your application will speak with default (selected in phone preferences)

darja
  • 4,985
  • 9
  • 33
  • 47
  • Thanks for the info :) Is there any link or reference where I can read more about these parameters and options? – Darth Coder Jun 20 '13 at 10:22
  • http://developer.android.com/reference/android/speech/tts/TextToSpeech.html#setEngineByPackageName(java.lang.String) – darja Jun 20 '13 at 11:42
  • Oops, it is deprecated now. But engine package name can be specified in constructor. And besides, I've never seen, that setEngineByPackageName returned ERROR. Only SUCCESS, even voice data are not installed and engine is not loaded in fact. – darja Jun 20 '13 at 11:44