我有一个应用程序,为视力低下的人,严重依赖TTS。但是,由于某种原因,当我使用speaks方法时,TTS会随机跳过句子的前几个字母,或者以极低的音量说出前几个字母,其余的则以正常音量发音。
你知道为什么会发生这种情况吗?
这是我当前的代码:
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);
}
}我注意到,这个问题总是发生在打完电话后的5秒内,或者是解锁手机应用程序的时候。
发布于 2015-09-10 11:21:29
要么是你做错了什么,要么是Android做错了什么。如果非要我下赌注的话,我会说是你。
从打电话开始
tts.speak("the quick brown fox jumps over the lazy dog", tts.QUEUE_FLUSH, null);看看你是否可以在测试应用程序中重现这个问题(我不能)。如果你可以,那么我会非常好奇你是在什么手机/操作系统上运行的。您的问题可能出在截断的字符串上,或者是其他以编程方式处理卷的问题。
https://stackoverflow.com/questions/32447124
复制相似问题