How to give pause or gap between words in TTS in android
Asked Answered
G

5

8

I have given a text in mytts.speak("hi hello hi",parameter,parameter...);

But the words are continuously said without any gap or pause, I want to provide some time gap between words for more clarity.

How could I achieve this ?

Ganger answered 6/5, 2014 at 11:59 Comment(5)
1 second will do it.In emulator by giving'/' i cud achieve this but when i run it on sumsung device ,the behaviour is changed.Ganger
agree different devices, different behavior of TTS. Even somtimes voice quality is different.Carrollcarronade
I would like to target on sumsung devices,how could we generalize TTS on all devicesGanger
How about spliting words from hi hello hi sentence and play on tts ?Carrollcarronade
could you provide some sample code of what you mean by splitting wordsGanger
C
4

If I understand your question correctly, this thread has the answer (by rushi).

Simply add a delay into the TTS queue by splitting the string and loop over the snippets via a for loop:

mytts.speak(snippet, QUEUE_ADD, null);
mytts.playSilentUtterance(2000, QUEUE_ADD, null);
Cleavland answered 14/3, 2017 at 0:38 Comment(0)
S
3

Simply add a comma everywhere you want there to be pauses inserted.

For example: If you want the following web address to be said slower, enter it as a, t, t, r, s.gov

I realize this may not be suitable for some applications, but it definitely works.

Supplicate answered 14/9, 2018 at 12:30 Comment(0)
H
0

This is how I put a longer pause between each word:

//initialize and declare TextToSpeech as tts

//"line" is the String you are trying to speak

char ch = '';
String temp = "";

for(int counter = 0; counter < line.length; counter++)
{
    ch = charAt(counter);
    temp = temp + ch;

    if(ch == ' ' || counter == (line.length() - 1))
    {
        tts.speak(temp, TextToSpeech.QUE_ADD, null, null);
        tts.playSilentUtterance(1000, TextToSpeech.QUEUE_ADD,null);
        temp = "";
    }

}
Helmut answered 29/9, 2018 at 0:49 Comment(0)
M
0

Try adding '/ / / / /' to your text. It should give you it some breathing room. If you want a longer pause, try adding more.

Magnific answered 23/3, 2022 at 16:23 Comment(0)
R
-1

You can split you sentence in words and speak them in a for loop in a new thread. Splitting the phrase will give you a little delay, but if you want a longer one you could work on thread and make them wait. It would be something like this:

final Handler h = new Handler();
String[] words = text.split(" ");
for (final CharSequence word : words) {
    Runnable t = new Thread() {
        @Override
        public void run() {
            m_TTS.speak(word, TextToSpeech.QUEUE_ADD, null, "TTS_ID");

        }
    };
    h.postDelayed(t, 1000);
}
Raasch answered 30/6, 2015 at 9:59 Comment(2)
What is "TTS_ID"?Availability
It is an identifier defined by the developer. See the official developer.android.com/reference/android/speech/tts/…, int, android.os.Bundle, java.lang.String).Raasch

© 2022 - 2024 — McMap. All rights reserved.