没有语音TTS的机器人 [英] No voice TTS in android
问题描述
在我的应用程序,我没有得到任何声音
In my application, i didn't get any voice
这是我的code,
公共类AndroidTextToSpeechActivity扩展活动器具 TextToSpeech.OnInitListener { / **第一次创建活动时调用。 * /
public class AndroidTextToSpeechActivity extends Activity implements TextToSpeech.OnInitListener { /** Called when the activity is first created. */
private TextToSpeech tts;
private Button btnSpeak;
private EditText txtText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tts = new TextToSpeech(this, this);
btnSpeak = (Button) findViewById(R.id.btnSpeak);
txtText = (EditText) findViewById(R.id.txtText);
// button on click event
btnSpeak.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
speakOut();
}
});
}
@Override
public void onDestroy() {
// Don't forget to shutdown!
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
@Override
public void onInit(int status) {
// TODO Auto-generated method stub
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.US);
// tts.setPitch(5); // set pitch level
// tts.setSpeechRate(2); // set speech speed rate
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "Language is not supported");
} else {
btnSpeak.setEnabled(true);
speakOut();
}
} else {
Log.e("TTS", "Initilization Failed");
}
}
private void speakOut() {
String text = txtText.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
}
我得到的日志猫错误
不支持语言
任何一个能帮助我吗?我需要发言时强调字
any one help me?? and i need to highlight word when speaking
推荐答案
我得到了一个解决方案,问题是,在Android默认的TTS引擎可用的区域设置不匹配那些在我的手机。我安装了另一个TTS引擎,它完美的作品与它的罚款。
I got an solution, 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.
或
// missing data, install it
Intent installIntent = new Intent();
installIntent.setAction(
TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
参考文献:
- SO:在TTS的Android 缺少语言
- <一个href="http://stackoverflow.com/questions/15087187/text-to-speech-works-on-emulator-but-not-on-phone">SO:文本到语音的工程仿真器,但无法在手机上
- SO: Missing languages in TTS android
- SO: Text to speech works on emulator but not on phone
这篇关于没有语音TTS的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!