3

In my android TTS application, I tried to speak out Japanese. So, I set the language to Japanese.

result = tts.setLanguage(Locale.JAPAN);
finalText = textField.getText().toString();
tts.speak(finalText , TextToSpeech.QUEUE_ADD, null);

This didn't work. So I set to

result = tts.setLanguage(Locale.JAPANESE);
finalText = textField.getText().toString();
tts.speak(finalText , TextToSpeech.QUEUE_ADD, null);

This also didn't work.

The wonderful case is, any other language except English is not working!!!!!!!!!!!!!!!

This is the text I tried to speak

私は英雄です。だから問題は何ですか?

So my question is, what is happening here? Can't it speak out other languages?

UPDATE

This started working as soon as I set the language in onInit() . Previously, I tried to set on user request, which means, onInit() is not called when the user manually change the language from US to Japanese. So, how can I call the OnInit() manually, without restarting the activity?

PeakGen
  • 21,894
  • 86
  • 261
  • 463

3 Answers3

2

Write code as in onCreate()

 String Text = text.getText().toString();
            tts.speak(Text, TextToSpeech.QUEUE_ADD, null);
Intent checkIntent = new Intent();
        checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
        startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);

then

public void onInit(int status) {
        // TODO Auto-generated method stub
        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{
                talk.setEnabled(true);
            speakOut();
            }
        }
        else{
            Log.e("TTS", "Initialization Falied");
        }

    }
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                    if (requestCode == MY_DATA_CHECK_CODE) {
                        if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
                            // success, create the TTS instance
                            tts = new TextToSpeech(this, this);
                        }
                        else {
                            // missing data, install it
                            Intent installIntent = new Intent();
                            installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                            startActivity(installIntent);
                        }
                    }

                }

this will give you the option of selecting the voice service there you can Download the Japnese language

Android Noob
  • 621
  • 8
  • 18
0

Check the return value; http://developer.android.com/reference/android/speech/tts/TextToSpeech.html#setLanguage(java.util.Locale)

It appears that if the locale you're trying to set is not available (on your phone) it will set the nearest available Locale which in your case might be only english

Pontus Backlund
  • 1,017
  • 1
  • 10
  • 17
0
it not working because your default language select in your phone is English, you need to change it to your desired language or if the package is not available of the desired language you need to download it.
phone setting->language &input->google voice typing->languages.
yet your problem not solve than commenting me your problem.
Vishal Sharma
  • 1,051
  • 2
  • 8
  • 15