How do you change the sample rate of an audio file? In my app I append multiple audio files in .wav
format which have a sample rate of 24,000 Hz and I want to convert the resulting file's sample rate to 20,050 Hz. I tried creating a new AudioFormat
and setting the sample rate to 20,050 Hz like this:
appendedFiles = new AudioInputStream(
new SequenceInputStream(appendedFiles, clip),
new AudioFormat(appendedFiles.getFormat().getEncoding(),
20050,
appendedFiles.getFormat().getSampleSizeInBits(),
appendedFiles.getFormat().getChannels(),
appendedFiles.getFormat().getFrameSize(),
appendedFiles.getFormat().getFrameRate(),
appendedFiles.getFormat().isBigEndian()
),
appendedFiles.getFrameLength() + clip.getFrameLength());
but this doesn't completely work, it slows down the audio and thickens the voice.