1

I am trying to port a TTS app that utilizes in-text control tags from desktop/web/iOS to Android. The app makes a text file consisting of the text to be spoken and silent periods between the spoken words. Silent periods are represented with in-text control tags such as SAPI TTS <silence msec="1000"/> tag or iOS TTS engine in-text control tag for silence [[slnc 10000]]

The text sent to the SAPI TTS speech synthesizer looks like this:

Text one <silence msec="750"/> text two <silence msec="1000"/> text three <silence msec="500"/> Text four <silence msec="600"/> Text five.....

Similarly for iOS TTS the in-text control tag for silence is [[slnc 10000]] and the text to be sent to the speech synthesizer looks like this:

Text one [[slnc 750]] text two [[slnc 10000]] text three [[slnc 500]] text four [[slnc 600]] text five......

Android TTS doesn't seem to use in-text control tags for the speech synthesizer. Also the following two variants of the speech() method use google web service so to achieve accurate timing of the spoken text coming back from the speech synthesizer server and the timing of the silence periods within the code may be impossible or unreliable at best.

speak(speech, TextToSpeech.QUEUE_FLUSH, null);

speak(speech, TextToSpeech.ADD_ADD, null);

I welcome any Android solution that focuses on preserving accurate timing of silence periods between spoken words.

Gina Kalani
  • 128
  • 1
  • 9
  • Did you read the [Android TTS documentation](https://developer.android.com/reference/android/speech/tts/TextToSpeech.html)? There are the `playSilence()` and the newer `playSilentUtterance()`methods that do just that. And `speak()` doesn't use any web service. – Markus Kauppinen Apr 11 '17 at 16:53
  • Thanks @MarkusKauppinen , so the answer will be to alternate speak() and playSilence() with QUEUE_ADD to continuously add to the queue. I intend to provide user with a stop() so no need for isSpeaking(). I like it. As for on-line off-line speech syntheses it seems that the default method is to sent request to the google server. Alternatively user can download the engine for off-line use via settings on the phone. User can be notified ahead of the time to make these changes including setting default voice and language. Great :) – Gina Kalani Apr 11 '17 at 19:24

1 Answers1

3

The Android TTS engine has the deprecated playSilence() and the newer playSilentUtterance() methods that can be used to pause the speech output for a given amount of time.

If the app targets API level 21 i.e. Android 5.0 as the minimum, then playSilentUtterance() should be used. Otherwise the deprecated playSilence() is still available.

The complete method signature of the playSilentUtterance method is:

int playSilentUtterance (long durationInMs, int queueMode, String utteranceId)

Here durationInMs is the duration of the silence in milliseconds.

The queueMode can be either QUEUE_ADD which means that the silence is played after the TTS engine has finished what it is currently speaking and what was already added to the queue and QUEUE_FLUSH stops everything first and clears the queue, so the silence is played right away.

Finally the utteranceId is an optional unique identifier for the text (or in this case silence) to be spoken and is useful if using an UtteranceProgressListener.

Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
  • I am new here, and I think I got the answer to my question. Not sure if I need to close it, mark it as answered, leave as is? – Gina Kalani Apr 12 '17 at 15:11
  • If you are happy with the answer, you can accept it. There's no need to do anything to the question. It will remain in the archive along with the answer and people with the same trouble may find it later via search. – Markus Kauppinen Apr 12 '17 at 15:14
  • For compatibility with SAPI in-text silence tag behavior one needs to create a new method e.g. `playSAPIText()` which will dissect the text and apply `speak()` method for the text and `playSilentUtterance()` or `playSilence()` (for pre-API level 21) for the silence period. `queueMode` in this case should be `QUEUE_ADD` to provide uninterrupted audio stream. – Gina Kalani Apr 12 '17 at 15:28