我正在尝试创建一个应用程序,其中手机可以在EditText中说出中文文本。它在带有API 19的手机上工作正常,当我在带有API 23的手机上进行测试时,当我按下说出文字的按钮时,什么都没有出来。怎么会? (声音在手机上音量很大,适用于英文文本。 附:如果我将语言更改为法语并将文本更改为" Bonjour",则可以使用。)
我的代码是:
public class MainActivity extends AppCompatActivity {
EditText subject;
Button submit;
TextToSpeech t1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
subject = (EditText) findViewById(R.id.subject);
submit = (Button) findViewById(R.id.submit);
t1 = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
public void onInit(int status) {
t1.setLanguage(Locale.SIMPLIFIED_CHINESE);
}
});
// The button is called submit. The toast is there just to make sure that the t1.speak started to run.
submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (android.os.Build.VERSION.SDK_INT > 20) {
t1.setLanguage(Locale.SIMPLIFIED_CHINESE);
String utteranceId = this.hashCode() + "";
t1.speak(subject.getText().toString(), TextToSpeech.QUEUE_FLUSH, null, utteranceId);
Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
} else {
t1.setLanguage(Locale.SIMPLIFIED_CHINESE);
t1.speak(subject.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);
}
}
});
}
}
答案 0 :(得分:0)
显然,三星文字转语音不支持中文。您需要将文字转语音更改为Google。然后,它开始为我工作。