Search code examples
androidtext-to-speechgoogle-text-to-speech

TTS player speaking number in words


I have a requirement( in Android code) that TTS player should speak out numbers eg "1234" as "one two three four". However currently its speaking it as "one thousand two hundred and thirty four".


Solution

  • TTS does not allow you to specify how the text should be read so your code has to modify the text input so that it reads the individual numbers.

    I suggest @opalenzuela's mention that a space in between each number. That should cause the TextToSpeech to read the individual numbers.

    If you need some code to help you detect numbers use this:

      private boolean isNumber(String word)
     {
    boolean isNumber = false;
      try
      {
          Integer.parseInt(word);
          isNumber = true;
       } catch (NumberFormatException e)
      {
           isNumber = false;
      }
      return isNumber;
    }