'Android TTS speaks 0 as "oh"
When using Android TextToSpeech to speak messages that have digits, Android is speaking 0 (zero) as "oh" rather than "zero". All other digits are spoken as expected.
I've tried a couple different ways to speak, all of them result in this issue. First, I tried in the normal way:
mTTS = new TextToSpeech(mContext, this);
String text= "this is a test";
String digits= "0 0 0 1";
String finalString= text+digits;
// speak something using google TTS
Bundle lParams = new Bundle();
lParams.putInt(TextToSpeech.Engine.KEY_PARAM_STREAM, Constants.TTS_AUDIO_STREAM);
mTTS.speak(finalString, TextToSpeech.QUEUE_FLUSH, lParams, "");
I also tried digits as "0001" (no spaces). Both ended up spoken as "this is a test oh oh oh one". Next, I tried using TtsSpans:
mTTS = new TextToSpeech(mContext, this);
String text= "this is a test";
String digits= "0 0 0 1";
String finalString= text+digits;
Spannable lSpannedMsg = new SpannableString( finalString );
TtsSpan lSpan = new TtsSpan.DigitsBuilder(digits).build();
TtsSpan lSpanText = new TtsSpan.TextBuilder(text).build();
lSpannedMsg.setSpan(lSpan, finalString.indexOf(digits), finalString.indexOf(digits) + digits.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
lSpannedMsg.setSpan(lSpanText, finalString.indexOf(text), finalString.indexOf(text) + text.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// speak something using google TTS
Bundle lParams = new Bundle();
lParams.putInt(TextToSpeech.Engine.KEY_PARAM_STREAM, Constants.TTS_AUDIO_STREAM);
mTTS.speak(lSpannedMsg, TextToSpeech.QUEUE_FLUSH, lParams, "");
Even with the spanned string, the engine still spoke "this is a test oh oh oh one". Is there any way to force Google to speak 0 as "zero"? I would like to avoid investigating the string sent in and replacing 0 with "zero" as this would cause issues with other languages.
Solution 1:[1]
holder.mEmployeeId.setText("100001");
String buildNumber = holder.mEmployeeId.getText().toString();
StringBuilder builderForEmployeeNo = new StringBuilder();
for (char ch : buildNumber.toCharArray()){
builderForEmployeeNo.append(ch);
builderForEmployeeNo.append(",");
}
holder.mEmployeeId.setContentDescription(builderForEmployeeNo);
By using this method no matter your default locale it will read 0 as zero only
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ryan M |
