Audio volume control (increase or decrease) in Java

前端 未结 3 1752
借酒劲吻你
借酒劲吻你 2020-11-29 09:16

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

3条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 09:49

    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();
    

提交回复
热议问题