Reputation: 33996
I have an app for people with low vision that relies heavily on TTS. However for some reason when I use the speak method TTS randomly skips the first few letters of a sentence or speaks the first few letters in a ver low volume and the rest in a normal volume.
Any idea why this might happen?
This is my current code:
public class SpeechHelper implements TextToSpeech.OnInitListener {
private Context context = null;
private TextToSpeech tts;
public SpeechHelper(Context context)
{
this.context = context;
try {
tts = new TextToSpeech(context, this);
} catch(Exception e) {
Log.e("Phone Features Exception","Couldn't initiate TTS", e);
}
}
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
tts.setLanguage(Locale.getDefault());
}
}
public void speak(String s, int mode, String messageID) {
Log.d("VOLUME", "getStreamVolume " + am.getStreamVolume(AudioManager.STREAM_MUSIC)); // Always 15
Log.d("VOLUME", "isMusicActive " + (am.isMusicActive() ? "true" : "false")); // Always false
Log.d("VOLUME", "isVolumeFixed " + (am.isVolumeFixed() ? "true" : "false")); // Always false
Log.d("VOLUME", "isSpeakerphoneOn: " + (am.isSpeakerphoneOn() ? "true" : "false")); // Always false
Log.d("VOLUME", "getMode: " + am.getMode()); // Always 0
HashMap<String, String> params = new HashMap<String, String>();
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, messageID);
tts.speak(s, mode, params);
}
}
I've noticed the problem always happens on the next 5 seconds after making a call or when unlocking the phone to the app.
Upvotes: 6
Views: 676
Reputation: 1
Try to increase Expressive Breaks in setting. It may be to fast so it ship it. It should work as I just solved the problem in this way. Let me know
Upvotes: 0
Reputation: 2834
Either you are doing something wrong or Android is doing something wrong. If I had to put money on it I would say it is you.
Start by just calling
tts.speak("the quick brown fox jumps over the lazy dog", tts.QUEUE_FLUSH, null);
to see if you can reproduce the problem in a test app (I couldn't). If you can, then I'd be very curious as to what phone/OS you are running on . Your problem probably lies with truncated strings, or something else programmatically messing with volume.
Upvotes: 1