Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android TTS (Text-To-Speech) doesn't pronounce single letter correctly

I am trying to implement text to speech technology of Android in my Activity. It is a simple word game and I want the TTS engine to spell a single letter when the user presses some button. For example when the user presses the A button I want to hear "A".

The problem is the the .speak method only takes a String as input. So, when I tell the TTS engine that I just want a single letter string, the sound is not the pronunciationof the letter. Is there any way that I can make it pronounce correctly the single letter strings?

The solution so far, was to use as string input, words that sound like the letters, e.g. "bee" for B, "see" for C and so on. But what about F, H and so on?

Any other ideas?

like image 632
Nick Avatar asked Mar 15 '12 09:03

Nick


People also ask

Why TTS is not working in Android?

Speech Output (Text-to-Speech aka TTS) Look under Accessibility > Text-to-speech output. Ensure you have "Google Text to Speech" selected and the correct language. Note that Speaking Email won't use Samsung or other vendor voices - so you need to enable the Google voices as your default TTS engine.

How do I use Google Text to Speech in Android Studio?

Go to the app -> res -> layout -> activity_main. xml section and set the layout for the app. In this file add an EditText to input the text from the user, a Button, so whenever the user clicks on the Button then it's converted to speech and a TextView to display the GeeksforGeeks text.

How do I slow down Text-to-speech on Android?

Tap the Settings icon . Scroll down and tap Accessibility. Scroll down and tap Text-to-speech output. Adjust the sliders for Speech Rate and Pitch.


2 Answers

After experimenting a lot, I found a better solution. In order the android tts engine to anounce a single letter you have to write it in capitals. For example "B". This way it will pronounce correctly! The only exceptions are "A" and "Z" which have to be writen as "ay" and "zet"!

Hope this helps

like image 70
Nick Avatar answered Sep 30 '22 18:09

Nick


I've updated an old project testing TTS, so yes is the way that you say but putting comma separated to force pronunciation letter by letter, I was trying the other option that you say too (both are included here):

enter image description here

The main class are:

public class SpellUtil {

public static String convertToSpellOnce(String words) {
    StringBuilder sb = new StringBuilder();
    for (char letter : words.toCharArray()) {
        sb.append(letter);
        //sb.append(convertSoundBased(letter)); this is another option
        sb.append(",");
    }
    return sb.toString();
}

private static String convertSoundBased(char letter) {
    switch (letter) {
        case 'a':
            return "a";
        case 'b':
            return "bee";
        case 'c':
            return "cee";
        case 'd':
            return "dee";
        case 'e':
            return "e";
        case 'f':
            return "ef";
        case 'g':
            return "gee";
        case 'h':
            return "aitch";
        case 'i':
            return "i";
        case 'j':
            return "jay";
        case 'k':
            return "kay";
        case 'l':
            return "el";
        case 'm':
            return "em";
        case 'n':
            return "en";
        case 'o':
            return "o";
        case 'p':
            return "pee";
        case 'q':
            return "cue";
        case 'r':
            return "ar";
        case 's':
            return "ess";
        case 't':
            return "tee";
        case 'u':
            return "u";
        case 'v':
            return "vee";
        case 'w':
            return "double-u";
        case 'x':
            return "ex";
        case 'y':
            return "wy";
        case 'z':
            return "zed";
    }
    return "";

}
}

Check the completed code here:

https://github.com/tiveor/android-intermediate/tree/master/SpeechTest

like image 26
alvarodev Avatar answered Sep 30 '22 20:09

alvarodev