Java中的音频音量控制(增加或减少) [英] Audio volume control (increase or decrease) in Java

查看:28
本文介绍了Java中的音频音量控制(增加或减少)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Java 增加传出的 wav 音频流的音量?我在使用各种 Java TTS 引擎和合成语音的输出音量时遇到问题.我可以使用 API 调用或 doo-hickey.jar 来提高音量吗?

How do I increase the volume of an outgoing wav audio stream using Java? I'm having issues with various Java TTS engines and the output volume of the synthesized speech. Is there an API call or a doo-hickey.jar I can use to pump up the volume?

推荐答案

如果您使用的是 Java Sound API,则可以使用 MASTER_GAIN 控制.

If you're using the Java Sound API, you can set the volume with the MASTER_GAIN control.

import javax.sound.sampled.*;

AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(
    new File("some_file.wav"));
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
FloatControl gainControl = 
    (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(-10.0f); // Reduce volume by 10 decibels.
clip.start();

这篇关于Java中的音频音量控制(增加或减少)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆