set TTS Language

All your problems with Audio, Video and Images.

set TTS Language

Postby wolwe » Wed Mar 30, 2011 11:06 pm

Hello.

I'm running a German Android 2.2 Froyo installation. The TTS work fine, but I'd like to use it for English voice out.

So I set the language
Code: Select all
apiTextToSpeech.setLanguage(Locale.ENGLISH);

No matter if I try US or UK languge - it doesn't take affect. The voice tries to speak it German.

Next I called an TTS install intent, to ensure a complete installation
Code: Select all
            Intent installIntent = new Intent();
            installIntent
                  .setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(installIntent);

...but still German. While running out of ideas, I scanned for installed Locales and recieved NOTHING:
Code: Select all
               Locale locales [] = Locale.getAvailableLocales();
               for(int i=0; i<locales.length; i++){
                  if(TextToSpeech.LANG_NOT_SUPPORTED != apiTextToSpeech.isLanguageAvailable(locales[i])){
                   Toast.makeText(Welcome.this,
                         locales[i].getDisplayLanguage(),
                         Toast.LENGTH_LONG).show();
                  }
               }


Any help would be appreciated.
wolwe
Freshman
Freshman
 
Posts: 5
Joined: Wed May 05, 2010 11:59 am
Location: Germany

Top

Re: set TTS Language

Postby raj_J2ME » Thu Mar 31, 2011 10:15 am

Hi,

Did you try to print the length of the array, locales []?
What is that?
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Re: set TTS Language

Postby wolwe » Thu Mar 31, 2011 10:30 am

Hi Raj, yes I did.
As you can see I initialized the Locales Array with the help of Locale.getAvailableLocales() - and that Array is HUGE! :D
A lot of languages, but TTS don't like one of them. Even German, the language my app speaks at this moment, is not marked as supported language.

Is there perhaps another way to kick off the TTS API? I'm currently simply using = new TextToSpeech(this, this);

edit:
I checked my smartphone settings - English is installed! I can set English, check the option to overwrite application settings with standard setting and finally my app speaks English. But there has to be a way, to set the language via application code? Should be so simple...simply don't get it.
wolwe
Freshman
Freshman
 
Posts: 5
Joined: Wed May 05, 2010 11:59 am
Location: Germany

Re: set TTS Language

Postby raj_J2ME » Thu Mar 31, 2011 1:57 pm

Just found this link, could you check this and let us know if this is working.
http://code.google.com/p/android-locale ... troduction
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Re: set TTS Language

Postby wolwe » Thu Mar 31, 2011 8:05 pm

Thanks for the advice raj!

Finally I was able to implement a fully functional solution.
It was a time problem - you can set the language, but you have to do it in the onInit listener!

I packed the Speech API in an own wrapper class. This wrapper class implements the OnInitListener interface.
The onInit method sets the language!

Here's some sample code:
Code: Select all
package de.liquid.android.fluidinstr;

import java.util.Locale;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

import android.app.Activity;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.util.Log;

public class SpeechSynth implements OnInitListener {

   private TextToSpeech tts;
   static final int TTS_CHECK_CODE = 0;
   private int ready = 0;
   private ReentrantLock waitForInitLock = new ReentrantLock();

   SpeechSynth(Activity screen) {
      ready = 0;
      tts = new TextToSpeech(screen, this);
      waitForInitLock.lock();

   }

   public void onInit(int status) {
      if (status == TextToSpeech.SUCCESS) {
         ready = 1;
      }
      tts.setLanguage(Locale.US);
      waitForInitLock.unlock();
   }

   public int Speak( String text )
   {
           if (waitForInitLock.isLocked())
           {
               try
               {
                   waitForInitLock.tryLock(180, TimeUnit.SECONDS);
               }
               catch (InterruptedException e)
               {
                   Log.e("TTSAPI", "interruped");
               }
               //unlock it here so that it is never locked again
               waitForInitLock.unlock();
           }

       if( ready == 1 )
       {
           tts.speak(text, TextToSpeech.QUEUE_ADD, null);
           return 1;
       }
       else
       {
           return 0;
       }   
   }

}


Again thanks for your advices raj!
wolwe
Freshman
Freshman
 
Posts: 5
Joined: Wed May 05, 2010 11:59 am
Location: Germany

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Exabot [Bot] and 13 guests