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

ぐ巨炮叔叔 提交于 2019-12-04 07:04:14

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

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):

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!