[英]Why isn't Text to Speech working?
我正在嘗試制作一個手機可以在EditText中說中文文本的應用程序。 在使用API 19的手機上,它可以正常工作;當我在使用API 23的手機上對其進行測試時,當我按下說出文字的按鈕時,什么也沒發出。 怎么會? (聲音在電話上已達到最大音量,並且適用於英語文本。PS如果將語言更改為法語,將文本更改為“ 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);
}
}
});
}
}
顯然,Samsung Text-to-Speech不支持中文。 您需要將“文字轉語音”更改為Google。 然后,它開始為我工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.