When starting a Activity
function, I execute onCreate
the following code:
tts = new TextToSpeech(this, new TextToSpeech.OnInitListener()
{
@Override
public void onInit(int status)
{
if (status == TextToSpeech.SUCCESS)
{
tts.setLanguage(singletonGame.locale);
tts.speak(instruction, TextToSpeech.QUEUE_ADD, null);
}
}
});
But there is a delay before the audio starts playing, because it takes time.
I tried leaving the object TextToSpeech
in a class Singleton
to have it pre-loaded earlier and not wait for the delay, but it throws an error, because I have to destroy it every scene the object calls.
Does anyone know any solution?
Update 1:
I did a test and what it takes is this line to be executed, because it quickly enters theIF
tts.speak(instruction, TextToSpeech.QUEUE_ADD, null);
It is delayed because the function
speak
has arun
and is expecting a service, thus.So the solution I found is to place a message that says "Loading..."
And I add the functions when it starts and ends: