在Android Studio应用中,以下音量不会改变;它仍然是最响亮的环境。评论的代码已折旧,但正在运行。我如何在中使用捆绑 新的API?
public void speakthetext2(String s) {
final String msg = s;
tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
//HashMap<String, String> params = new HashMap<>();
//params.put(KEY_PARAM_VOLUME, "0.20");
Bundle b = new Bundle();
b.putString(KEY_PARAM_VOLUME,"0.10");
tts.speak(msg, TextToSpeech.QUEUE_ADD, b, "1");
//noinspection deprecation
//tts.speak(msg, TextToSpeech.QUEUE_FLUSH, params);
} else {
Toast.makeText(getApplicationContext(), "tts error!", Toast.LENGTH_LONG).show();
}
}
});
}
答案 0 :(得分:0)
使用
b.putFloat(KEY_PARAM_VOLUME, 0.1f);
而不是putString。