0

我正在尝试更改程序的输出音频级别,最好以分贝为单位。我需要改变整个节目的音频电平并记录电平的变化。语言是Java。有什么简单的方法可以做到这一点?我用来播放声音的声音如下:

import java.io.InputStream;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;


public class Sound 
{
    String sounds;
    public Sound(String file)
    {
        sounds = file;
        playSound(sounds);
    }//end contructor

    public void playSound(String soundLoc)
    {  
        try
        {
            InputStream inputStream = getClass().getResourceAsStream(soundLoc);
            AudioStream audioStream = new AudioStream(inputStream);
            AudioPlayer.player.start(audioStream);
        }//end try

        catch (Exception e)
        {
        }//end catch
    }//end playSound method
}//end class Sound
4

1 回答 1

0

您可以使用 Java 声音 API 使用 MASTER_GAIN_CONTROL

你需要导入这个.... import javax.sound.sampled.*;

使用 Clip 对象获取您的剪辑,然后,

public void playSound(String soundLoc)
    {  
        try
        {
            InputStream inputStream = getClass().getResourceAsStream(soundLoc);
            AudioStream audioStream = new AudioStream(inputStream);
            AudioPlayer.player.start(audioStream);
            Clip myclip = AudioSystem.getClip();
            myclip.open(audioStream);
            FloatControl audioControl = (FloatControl) myclip.getControl(FloatControl.Type.MASTER_GAIN);
             audioControl.setValue(-5.0f); //decrease volume 5 decibels
             clip.start();
        }//end try

        catch (Exception e)
        {
        }//end catch
    }//end playSound method
于 2015-02-27T18:33:10.160 回答