Search code examples
androidtext-to-speech

Android Text To Speech And Numbers


I am using Android Text to Speech engine for reading some text and it's working. But my text contains numbers and I want the numbers to be read digit by digit.

I couldn't find anything in the documentation, but I am still hoping someone knows how I can do that.


Solution

  • The API 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 adding 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;
    }