2

I am designing an APP in Android using the TTS Engine.
As the first time, I tried to send the text to google then receive the audio from google via internet, and it is working well.

The next step is to play the TTS audio offline.
That means that I have some text, my Application will get the audio from the system, without connecting to internet.

I have implemented this: Voice Recognition and Text to Speech

But my problem is TextToSpeech.LANG_MISSING_DATA: this is not working without internet.
If internet is not available, it is not working.

Please help me.

Community
  • 1
  • 1

1 Answers1

1

Check out Sifat Ifty's implementation at Text to speech(TTS)-Android specifically the code block:

tts=new TextToSpeech(MainActivity.this, new TextToSpeech.OnInitListener() {

        @Override
        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("error", "This Language is not supported");
                }
                else{
                    ConvertTextToSpeech();
                }
            }
            else
                Log.e("error", "Initilization Failed!");
        }
    });

This TextToSpeech.OnInitListener attempts to initialize the tts service if available. Remember to stop the tts service when you are done with it as well!

Community
  • 1
  • 1
JohnnyJem
  • 23
  • 1
  • 5
  • Thank you, But i have problems with "result". When internet not available result =TextToSpeech.LANG_MISSING_DATA But result =TextToSpeech.LANG_AVAILABLE internet available. Why ? ( i checked voice data TTS of Locale.US in "Google TTS voice data" and it not installed) – Mhsoft Company Apr 15 '15 at 14:05
  • Because when the device is connected to the internet the internet is used to provide TTS in the case of TTS being unavailable offline. To have it work offline you would need to download the TTS voice data in Settings. – hexicle Sep 29 '17 at 03:44
  • result will be always 0 from setLanguage even if you remove voice data – user924 Jan 11 '18 at 10:06