thammaknot
thammaknot

Reputation: 73

Android TTS speech synthesis error when screen is lock

I am writing an Android app that needs to speak using text-to-speech (TTS).

tts.speak("Some text", TextToSpeech.QUEUE_ADD, null, UTT_ID);

This works perfectly fine when the screen is on.

If the screen is off & lock, the Activity will wake up the screen (upon creation) and show itself (intentional). This is accomplished with

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

And this works fine too.

However, when the Activity is created and shown when the screen had been off...text-to-speech will not create any sound.

Looking at log, I see

TTS     : synthesizeWithoutLoadingVoice() failed

Googling this error message gave nothing. Anyone know what I did wrong here?

Upvotes: 1

Views: 1165

Answers (1)

Ambuj Kathotiya
Ambuj Kathotiya

Reputation: 369

Try recreating the TTS in the onResume function of your app. That is to move the init() function of TTS to onResume().

Upvotes: 2

Related Questions