如何设置文本转语音“说话”的音量方法?
我迷路了。我希望能够调整说话音量。无论我做什么,我都无法提高其音量。如何使其声音与 Android 设置中的声音一样大(如下)?
系统设置->语音输入输出->文本转语音设置 ->听一个例子
我此时的代码是:
AudioManager mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setSpeakerphoneOn(true);
int loudmax = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION);
mAudioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION,loudmax, AudioManager.FLAG_PLAY_SOUND);
mTts.speak(name,TextToSpeech.QUEUE_FLUSH, null);
I'm at a lost. I want to be able to adjust the speak volume. Whatever I do, I can't increase its volume. How do I make it as loud as that found in the Android settings (as below)?
System Settings -> Voice input and output -> Text-to-Speech settings -> Listen to an example
My code at this moment is:
AudioManager mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setSpeakerphoneOn(true);
int loudmax = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION);
mAudioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION,loudmax, AudioManager.FLAG_PLAY_SOUND);
mTts.speak(name,TextToSpeech.QUEUE_FLUSH, null);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
调用
setStreamVolume(...)
方法时尝试使用AudioManager.STREAM_MUSIC
。如果我调整手机上音乐播放的音量,示例语音会受到媒体音量的影响,所以我猜STREAM_MUSIC
就是您所需要的。编辑:此代码非常适合我...
我手机上
STREAM_MUSIC
的最大音量是 15,我什至通过替换amStreamMusicMaxVol
对此进行了测试我在上面调用am.setStreamVolume(...)
时使用了值 3、6、9、12、15,并且语音的音量已正确设置。Try using
AudioManager.STREAM_MUSIC
when calling thesetStreamVolume(...)
method. The example speech is affected by the media volume if I adjust the volume of music playback on my phone so I guessSTREAM_MUSIC
is what you need.EDIT: This code works perfectly for me...
The max volume for
STREAM_MUSIC
on my phone is 15 and I've even tested this by replacingamStreamMusicMaxVol
in my call toam.setStreamVolume(...)
above with the values 3, 6, 9, 12, 15 and the volume of the speech is correctly set.在您的代码中,您正在更改通知的音量。 TTS 播放的音量与通知的音量相同吗?我怀疑它不是,它可能在
STREAM_SYSTEM
或STREAM_MUSIC
上播放尝试将流类型更改为以下之一:In your code you are changing the volume of notifications. Is the volume of TTS played at the same volume level as notifications? I suspect it isn't and it probably played at either
STREAM_SYSTEM
orSTREAM_MUSIC
Try changing the stream type to one of these: