Android 文语转换问题
我想做一个文本到语音测试应用程序,请参见本教程: 我试着按照教程所说的去做,我只把语言设置为西班牙语:Android 文语转换问题,android,text-to-speech,Android,Text To Speech,我想做一个文本到语音测试应用程序,请参见本教程: 我试着按照教程所说的去做,我只把语言设置为西班牙语: mTts = new TextToSpeech(this, this); Locale loc = new Locale ("spa", "ESP"); mTts.setLanguage(loc); 我也尝试过这样做(不起作用): 问题是,当应用程序启动时,应用程序会提示我进入一个屏幕,要求我下载四种语言:德语、西班牙语、法语和意大利语。如果我只下载西班牙语,然后按back键,应
mTts = new TextToSpeech(this, this);
Locale loc = new Locale ("spa", "ESP");
mTts.setLanguage(loc);
我也尝试过这样做(不起作用):
问题是,当应用程序启动时,应用程序会提示我进入一个屏幕,要求我下载四种语言:德语、西班牙语、法语和意大利语。如果我只下载西班牙语,然后按back键,应用程序就会工作,但每次启动应用程序时,它都会显示下载其他三种语言的相同屏幕,并且只有在我下载foru语言时才会停止显示
我的目标是提示用户只下载西班牙语,并且只显示一次语言下载对话框,而不是全部显示
我正在Nexus S手机上用4.1进行测试
这是完整的代码:
public class MainActivity extends Activity implements OnInitListener {
private static final int MY_DATA_CHECK_CODE = 0;
EditText editText;
Button button;
private TextToSpeech mTts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText) findViewById(R.id.editText);
button = (Button) findViewById(R.id.button);
editText.setText("Estoy probando, porque hay que probar.");
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mTts.speak(editText.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MY_DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
// success, create the TTS instance
mTts = new TextToSpeech(this, this);
Locale loc = new Locale ("spa", "ESP");
mTts.setLanguage(loc);
} else {
// missing data, install it
Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
mTts = new TextToSpeech(this, this);
Locale loc = new Locale ("spa", "ESP");
mTts.setLanguage(loc);
}
}
}
@Override
public void onInit(int arg0) {}
}
我希望你能帮我找到解决办法
问候语您不能使用but/code来创建区域设置:
locale loc=new locale(“es”)代码>。另请参见。中的“类概述”部分,您不能使用but/code创建区域设置:locale loc=new locale(“es”)代码>。另请参见。中的“课程概述”部分,选中文本到语音设置下的“始终使用我的设置”。选中文本到语音设置下的“始终使用我的设置”。
public class MainActivity extends Activity implements OnInitListener {
private static final int MY_DATA_CHECK_CODE = 0;
EditText editText;
Button button;
private TextToSpeech mTts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText) findViewById(R.id.editText);
button = (Button) findViewById(R.id.button);
editText.setText("Estoy probando, porque hay que probar.");
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mTts.speak(editText.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MY_DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
// success, create the TTS instance
mTts = new TextToSpeech(this, this);
Locale loc = new Locale ("spa", "ESP");
mTts.setLanguage(loc);
} else {
// missing data, install it
Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
mTts = new TextToSpeech(this, this);
Locale loc = new Locale ("spa", "ESP");
mTts.setLanguage(loc);
}
}
}
@Override
public void onInit(int arg0) {}
}