, . javax.sound API:
import java.io.File;
import javax.sound.sampled.AudioFileFormat.Type;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import com.sun.media.sound.WaveFileReader;
import com.sun.media.sound.WaveFileWriter;
public class Resample {
public static void main(String[] argv) {
try {
File wavFile = new File("C:\\Temp\\test.wav");
File dstFile = new File("C:\\Temp\\test_half.wav");
WaveFileReader reader = new WaveFileReader();
AudioInputStream audioIn = reader.getAudioInputStream(wavFile);
AudioFormat srcFormat = audioIn.getFormat();
AudioFormat dstFormat = new AudioFormat(srcFormat.getEncoding(),
srcFormat.getSampleRate() / 2,
srcFormat.getSampleSizeInBits(),
srcFormat.getChannels(),
srcFormat.getFrameSize(),
srcFormat.getFrameRate() / 2,
srcFormat.isBigEndian());
AudioInputStream convertedIn = AudioSystem.getAudioInputStream(dstFormat, audioIn);
WaveFileWriter writer = new WaveFileWriter();
writer.write(convertedIn, Type.WAVE, dstFile);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
, . , .