【发布时间】:2018-01-30 12:19:43
【问题描述】:
我正在制作一个具有文本到语音的 android 应用程序,并且我希望能够自定义它的语速。我已经有一个代码,但我不知道如何将语速应用于整个应用程序。
这是我为应用程序创建的设置。提前致谢! :D
public float getSpeechRate(){
int checkedRadioButton = this.radioRate.getCheckedRadioButtonId();
if (checkedRadioButton == R.id.rate_slow){
return 0.5f;
} else if (checkedRadioButton == R.id.rate_normal){
return 1.0f;
} else if(checkedRadioButton == R.id.rate_fast){
return 1.5f;
}
return 0;
}
public void setSpeechRate(){
float speechRate = this.getSpeechRate();
if(speechRate == 0.5f){
speakOut("This is a slow speech rate");
} else if(speechRate == 1.0f){
speakOut("This is a normal speech rate");
} else {
speakOut("This is a fast speech rate");
}
这就是我将文本调用为语音的方式
toSpeech = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
Log.e("TTS", "TextToSpeech.OnInit...");
}
});
【问题讨论】:
-
如何调用 tts 功能?
-
上述语速方法仅适用于一项活动
-
我在上面编辑了我如何创建文本到语音的代码
-
toSpeech.setSpeechRate(speechRate);
-
您可以将值存储在您的
SharedPreferences中,请参阅此处stackoverflow.com/a/26928604/1256219
标签: android text-to-speech mobile-development