1

I have some code:

tts.speak(Integer.toString(score), TextToSpeech.QUEUE_ADD, null);

Where score is an int between 0 and 100. Occasionally, but not very often, I will hear the digits ready separately ie "Eight Six" instead of "Eighty Six." Has anyone else experienced this? Any ideas short of a giant switch statement?

String to_read = "zero";
switch (score) {
    case 1: to_read = "one"; break;
    case 2: to_read = "two"; break;
    case 3: to_read = "three"; break;
    case 4: to_read = "four"; break;
    case 5: to_read = "five"; break;
    ...
}
tts.speak(to_read, TextToSpeech.QUEUE_ADD, null);

On second thought, a giant switch statement won't work very well unless we are going to add a hundred new strings to our Strings.xml and have them all translated...

Chase Roberts
  • 9,082
  • 13
  • 73
  • 131
  • As an alternative, a routine to produce the phonetic translation for a number [1..n] would not be terribly difficult - a quick search however did not yield any libraries so maybe more to it than i'm thinking. Obviously special cases for each position (million vs billion) and in particular teens and also "zero" which is not pronounced (e.g. 302) but doable and more scalable than a switch statement. –  Mar 27 '19 at 11:42
  • TtsSpan seems interesting as well: https://developer.android.com/reference/android/text/style/TtsSpan.html. TYPE_DECIMAL –  Mar 27 '19 at 11:55

1 Answers1

0

Since you're using QUEUE_ADD, and assuming you're rapidly adding random scores to the queue, maybe what you're actually hearing is:

  • Two scores being read in succession that actually are single digit scores
  • The trailing digit of a score (say, the 8 of twenty-eight) being read immediately before the next score which happens to be a single digit. "twenty-eight-six" is what is spoken, but your brain latches onto and remembers the "eight-six."

Aside from those possibilities, the basic fact is that you're not responsible for the internal behavior of any given TTS engine with regards to how it processes strings.

The user could have one of many/any engines (and sub-versions of those engines) and/or languages installed... all having potentially different behaviors, so if you try to compensate for the engine you are testing with, it's only going to open a can of worms and cause unpredictable/unwanted results on the remaining engines.

Nerdy Bunz
  • 6,040
  • 10
  • 41
  • 100