如何使用Java声音增加录音和播放音量?
我使用下面的代码用Java录制和播放声音,但是音量太小了,如何使声音更大,至少是2,3倍如何使用Java声音增加录音和播放音量?,java,audio,Java,Audio,我使用下面的代码用Java录制和播放声音,但是音量太小了,如何使声音更大,至少是2,3倍 public void Record_Audio(String File_Path,AudioFileFormat.Type File_Type) { try { audioFormat=getAudioFormat(); // Get things set up for capture DataLine.Info dataLineInf
public void Record_Audio(String File_Path,AudioFileFormat.Type File_Type)
{
try
{
audioFormat=getAudioFormat(); // Get things set up for capture
DataLine.Info dataLineInfo=new DataLine.Info(TargetDataLine.class,audioFormat);
targetDataLine=(TargetDataLine)AudioSystem.getLine(dataLineInfo);
//Create a thread to capture the microphone data into an audio file and start the thread running. It will run
// until the Stop button is clicked. This method will return after starting the thread.
new Record_Thread(File_Path,File_Type).start();
}
catch (Exception e)
{
System.out.println(e);
System.exit(0);
}
}
private void Play_Audio_Recording()
{
File Audio_File=new File(Current_Folder_Path+File_Name_ComboBox.getSelectedItem().toString().trim()+"."+Get_Audio_File_Type());
try
{
Audio_Clip=Applet.newAudioClip(Audio_File.toURI().toURL());
Audio_Clip.play();
}
catch (Exception e) { e.printStackTrace(); }
}
class Record_Thread extends Thread
{
String File_Path;
AudioFileFormat.Type File_Type;
Record_Thread(String File_Path) { this(File_Path,AudioFileFormat.Type.WAVE); }
Record_Thread(String File_Path,AudioFileFormat.Type File_Type)
{
this.File_Path=File_Path;
this.File_Type=File_Type;
}
public void run()
{
Audio_File=new File(File_Path);
try
{
targetDataLine.open(audioFormat);
targetDataLine.start();
AudioSystem.write(new AudioInputStream(targetDataLine),File_Type,Audio_File);
}
catch (Exception e) { e.printStackTrace(); }
}
}
您可以使用FloatControl.Type()设置音量或主增益。比如:
targetDataLine=(TargetDataLine)AudioSystem.getLine(dataLineInfo);
javax.sound.sampled.FloatControl c = (FloatControl)targetDataLine.getControl(FloatControl.Type.VOLUME);
c.setValue(c.getMaximum());
可能有用。我尝试了这个,但出现了错误,没有“c.getMaximum()”方法。尝试:需要将控件强制转换为正确的类型(FloatControl)。java.lang.IllegalArgumentException:不支持的控件类型:com.sun.media.sound.AbstractLine.getControl(AbstractLine.java:150)上的卷奇数。那是录音还是回放?也许可以尝试
FloatControl.Type.MASTER\u GAIN
。这是用于录制的。我刚刚再试了一次,结果是:java.lang.IllegalArgumentException:不支持的控件类型:Master Gain