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?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With