SMS
SMS

Reputation: 558

How to give pause or gap between words in TTS in android

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 ?

Upvotes: 8

Views: 19289

Answers (5)

Paul Dressler
Paul Dressler

Reputation: 41

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.

Upvotes: 3

Guilherme Fernandes
Guilherme Fernandes

Reputation: 1

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

Upvotes: 0

Joe Giusti
Joe Giusti

Reputation: 179

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 = "";
    }

}

Upvotes: 0

Mairyu
Mairyu

Reputation: 839

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);

Upvotes: 4

Giuseppe
Giuseppe

Reputation: 307

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);
}

Upvotes: -1

Related Questions