我在我的App中使用文本到语音引擎。它在具有API 23及更高版本的模拟器Nexus 6上运行良好。但在具有API 22的仿真器Nexus 6上,它不会讲话。 两种仿真器均使用Pico TTS作为首选引擎。
我的活动布局仅包含一个按钮“说”。 这是我的活动代码:
public class MainActivity extends AppCompatActivity {
private TextToSpeech mTTS;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button speakBtn = findViewById(R.id.button);
speakBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
speak();
}
});
mTTS = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = mTTS.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "Language not supported");
}
mTTS.setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override
public void onStart(String utteranceId) {
Log.d("TTS", "onStart called, utteranceId = " + utteranceId);
}
@Override
public void onDone(String utteranceId) {
Log.d("TTS", "onDone called, utteranceId = " + utteranceId);
}
@Override
public void onError(String utteranceId) {
Log.d("TTS", "onError called, utteranceId = " + utteranceId);
}
});
} else {
Log.e("TTS", "Initialization failed");
}
}
});
}
private void speak() {
Log.d("TTS", "speak() method called");
HashMap<String, String> map = new HashMap<>();
map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "greeting");
mTTS.speak("hello", TextToSpeech.QUEUE_FLUSH, map);
}
}
这是来自仿真器Nexus 6 API 22的所有日志:
02-18 13:54:09.942 9739-9739 /? E / libprocessgroup:无法制作和添加/ acct / uid_10059:只读文件系统
02-18 13:54:09.943 9739-9739 /? W / Zygote:createProcessGroup失败,内核缺少CONFIG_CGROUP_CPUACCT吗?
02-18 13:54:09.943 9739-9739 /? I / art:不晚启用-Xcheck:jni(已启用)
02-18 13:54:09.961 9739-9748 /?电子/艺术:无法向调试器发送回复:管道损坏
02-18 13:54:09.961 9739-9748 /? I / art:调试器不再处于活动状态
02-18 13:54:09.992 9739-9739 /? W / art:在Android 4.1之前,方法android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter,android.content.res.ColorStateList,android.graphics.PorterDuff $ Mode)错误地覆盖了android.graphics.drawable.Drawable
中的package-private方法02-18 13:54:10.001 9739-9739 /? I / art:拒绝对先前失败的类java.lang.Class
进行重新初始化02-18 13:54:10.001 9739-9739 /? I / art:拒绝对先前失败的类java.lang.Class
进行重新初始化02-18 13:54:10.064 9739-9739 /? I / TextToSpeech:已成功绑定到com.svox.pico
02-18 13:54:10.072 9739-9757 /? D / OpenGLRenderer:使用EGL_SWAP_BEHAVIOR_PRESERVED:是
02-18 13:54:10.074 9739-9739 /? D /地图集:正在验证地图...
02-18 13:54:10.093 9739-9739 /? I / TextToSpeech:已连接到ComponentInfo {com.svox.pico / com.svox.pico.PicoService}
02-18 13:54:10.096 9739-9758 /? I / TextToSpeech:建立与ComponentInfo {com.svox.pico / com.svox.pico.PicoService}的连接
02-18 13:54:10.111 9739-9757 /? I / OpenGLRenderer:初始化的EGL,版本1.4
02-18 13:54:10.111 9739-9757 /? W / OpenGLRenderer:无法使用EGL_SWAP_BEHAVIOR_PRESERVED选择配置,请重试而无需...
02-18 13:54:10.128 9739-9757 /? D / EGL_emulation:eglCreateContext:0xae434e20:maj 2 min 0 rcv 2
02-18 13:54:10.131 9739-9757 /? D / EGL_emulation:eglMakeCurrent:0xae434e20:ver 2 0
02-18 13:54:10.134 9739-9757 /? D / OpenGLRenderer:启用调试模式0
02-18 13:54:10.174 9739-9757 /? D / EGL_emulation:eglMakeCurrent:0xae434e20:ver 2 0
02-19 09:32:25.570 9739-9739 / com.example.ttsapp D / TTS:调用了say()方法
答案 0 :(得分:0)
弄清楚如何解决问题。如果在启动Android Studio之后不是通过调试或执行而是通过AVD Manager启动仿真器,则一切正常。