Android TextToSpeech addSpeech () not working

I have an HD Desire phone with Android 2.3.

TTS is working fine and it says every text that I give. But when I use it in any of the lines below to set my own voice for some texts, it simply ignores it and synthesizes the text, just like a line is not written!

tts.addSpeech("salam", "/sdcard/salam.wav"); tts.addSpeech("shalam", "com.company.appname", R.raw.shalam); ... tts.speak("salam", TextToSpeech.QUEUE_FLUSH, null); //<--This isn't playing my voice file. tts.speak("shalam", TextToSpeech.QUEUE_FLUSH, null); //<--Neither is this 

I am sure that both files exist. Why is this? Is there a limit on audio files? For example, at their frequency or mono or stereo?

I already checked the docs and didn't see anything.

+1
source share
1 answer

Well, I found my problem, a very stupid situation that wasted for hours! Hope this helps if someone makes my mistake.

We must defer this text matching until the TTS is successfully initialized, for example, in the onInit function:

 @Override public void onInit(int status) { if(status == TextToSpeech.SUCCESS) { tts.setLanguage(Locale.US); mapVoices(); } else ... } private void mapVoices() { tts.addSpeech("salam", "/sdcard/salam.wav"); tts.addSpeech("shalam", "com.company.appname", R.raw.shalam); //... } 
+2
source

Source: https://habr.com/ru/post/1271660/


All Articles