Java resample.wav sound file without a third-party library

Is it possible to reformat a file .wavfrom 22050 kHz to 44100 kHz in java without using any third-party library?

Perhaps use AudioInputStream?

edit: since it seems that without a third-party library this is not possible, what third-party libraries are there for re-fetching?

+5
source share
5 answers

Since you are now accepting third-party libraries, here is my suggestion

, -wav . ( ) - Jave , , . , ,

Jave

public void setSamplingRate(java.lang.Integer bitRate)

.

+4

, . 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);
    }
}

}

, . , .

+2

, .wav . , .

"" : , a, b c . z - a b.

z = (a + b)/2. b (a + 2b + c)/4. z, ! a, z b .

, d. , y, (b + c)/2. b . c, (b + 2c + d)/4. b y .

, , ! EOF. , , .

+1

... wav , . , , , .

, JSSRC . .jar.

0

, AudioInputstream. :

http://www.jsresources.org/examples/SampleRateConverter.html

Tritonius, Java. Java - , *.wav .

In addition, most of the audio related questions in Java are answered by this FAQ. This may not be relevant, but most of the information is still relevant.

http://www.jsresources.org/faq.html

0
source

All Articles