文本到语音的工作在模拟器而不是手机上 [英] Text to speech works on emulator but not on phone
问题描述
我已经经历了几乎所有与此主题有关的链接走了,但还没有找到任何合适的答案。我试图建立一个基本的文本到语音应用。它的工作原理完全正常的模拟器。但是,当我的手机上运行它,它显示了不支持的语言。
我想这事做的语言环境。默认的语言环境中我的手机设置为 EN_US
我的code是如下:
I have gone through almost all the links related to this topic but haven't found any suitable answer. I am trying to build a basic text to speech application. It works perfectly fine on the emulator. But when i run it on my phone, it shows language not supported.
I guess this has something to do with the locale. The default locale set in my phone is en_US
My code is as follows:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tts = new TextToSpeech(this, this);
btnSpeak = (Button) findViewById(R.id.btnSpeak);
txtText = (EditText) findViewById(R.id.txtText);
btnSpeak.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// Method yet to be defined
speakOut();
}
});
}
public void onInit(int status) {
// TODO Auto-generated method stub
// TTS is successfully initialized
if (status == TextToSpeech.SUCCESS) {
// Setting speech language
// System.out.println(Locale.getAvailableLocales());
int result = tts.setLanguage(Locale.ENGLISH);
// int result = tts.setLanguage(Locale.getDefault());
// If your device doesn't support language you set above
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
// Cook simple toast message with message
Toast.makeText(this, "Language not supported",
Toast.LENGTH_LONG).show();
Log.e("TTS", "Language is not supported");
} else {
btnSpeak.setEnabled(true);
}
// TTS is not initialized properly
} else {
Toast.makeText(this, "TTS Initilization Failed", Toast.LENGTH_LONG)
.show();
Log.e("TTS", "Initilization Failed");
}
}
private void speakOut() {
// Get the text typed
String text = txtText.getText().toString();
// If no text is typed, tts will read out 'You haven't typed text'
// else it reads out the text you typed
if (text.length() == 0) {
tts.speak("You haven't typed text", TextToSpeech.QUEUE_FLUSH, null);
} else {
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
}
public void onDestroy() {
// Don't forget to shutdown!
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
即使我使用 INT结果= tts.setLanguage(Locale.getDefault());
而不是 Locale.ENGLISH
,它显示了相同的语言不支持的消息
even if i use int result = tts.setLanguage(Locale.getDefault());
instead of Locale.ENGLISH
, it shows the same language not supported message
logcat的错误:
LOGCAT ERROR:
02-26 16:24:57.492: I/TextToSpeech.java(23356): initTts() successfully bound to service
02-26 16:24:58.015: E/TTS(23356): Language is not supported
我在我的Android版本2.3.6电话 - 三星Galaxy-Y(GT-S5360)运行此
I am running this on my phone- Samsung Galaxy-Y (GT-S5360) with Android version 2.3.6
推荐答案
找到了解决办法我自己。问题是,在Android默认的TTS引擎可用的区域设置不匹配我的手机上。结果
我安装了另一个TTS引擎和它完美的作品与它的罚款。
found a solution myself. the problem was that the locales available on the android default tts engine did not match those on my phone.
i installed another tts engine and it works perfectly fine with it.
这篇关于文本到语音的工作在模拟器而不是手机上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!