Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android TextToSpeech: getting the audio time length

I'm working in android using the TextToSpeech class and Have a string with and specific length. I want to calculate the estimated time of this generated text to speech audio (I know that i can get the audio and then get the time length of this generated audio but I want to explore other alternatives).

I'm trying getting the speechRate (but seems no posible) and the with the length of the String create some formula getting as result an estimation of the time.

Any sugestions??

Thanks in advance.

PD: About the spechRate: getSpeechRate()? (or how to tell what rate TTS is currently set at)

like image 320
Estiven Restrepo Avatar asked Feb 01 '13 16:02

Estiven Restrepo


2 Answers

I use int pauseInSeconds=1+string.length()/7 for short english speaking.

Very rough of course.

like image 128
djdance Avatar answered Nov 15 '22 23:11

djdance


You can do something like this:

private void speakWord(String word)
{
     //Get time
     textToSpeech.speak(...);
     checkSpeaking(true);
}

private void checkSpeaking(boolean isSpeaking)
{
    Print.e("Speaking is: " + isSpeaking);
    if (isSpeaking)
    {
        new Handler().postDelayed(()-> 
        {
            if (textToSpeech.isSpeaking()) {
                checkSpeaking(true);
            }
            else {
                checkSpeaking(false);
            } 
        },300);
    }
    else
    {
        //Get time
    } 
}
like image 28
Student Avatar answered Nov 15 '22 23:11

Student