Android 文字转语音音量不变
Android text to speech volume not changing
在 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();
}
}
});
}
使用
b.putFloat(KEY_PARAM_VOLUME, 0.1f);
而不是 putString。
在 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();
}
}
});
}
使用
b.putFloat(KEY_PARAM_VOLUME, 0.1f);
而不是 putString。