android TextToSpeech: getting the audio time length
Asked Answered
S

2

10

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)

Scurrile answered 1/2, 2013 at 16:25 Comment(2)
There is no accurate way to do this without actually rendering the speech.Oxidize
You can create a mp3 file and get its length. I think this is the easy way.Reticulum
J
1

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

Very rough of course.

Jardine answered 2/3, 2016 at 20:6 Comment(0)
R
1

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
    } 
}
Raffaello answered 8/6, 2020 at 2:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.