How to change the bitrate using SoX

2.9k Views Asked by At

I'm trying to change the bitrate of the given audio file, the following code generate an audio with 1411 kbps

sox -t wav input.wav -C 320 output.wav speed 0.86 reverb 52 50 100 100 0 0;

enter image description here

Can anyone guide me to how I can change the audio bitrate to 320kbps

2

There are 2 best solutions below

0
On BEST ANSWER

It turns it out that changing bitrate supported only if the output audio mp3 not wav, so the command should be :

sox -t wav input.wav -C 320 output.mp3 speed 0.86 reverb 52 50 100 100 0 0
0
On

First, a note on terms. Bit-rate is commonly used when working with mp3 or other compressed audio formats. Sample-rate is commonly used when working with wav or other uncompressed audio formats. Bit-rate is a measure of the average storage consumed per unit of time for an entire stream. Sample-rate is the number of samples per second, per channel. With your 16-bit, 2-channel wav sampling at a 44.1 kHz rate, that is 44100 samples per second where each sample includes 16 bits for each of 2 channels. In other words 44100 * 16 * 2 = 1,411,200 bits per second. So you could reach your 320 kbps goal by changing to a 10 kHz sample-rate.

Uncompressed audio will likely sound pretty awful at 10 kHz, but using sox to change sample-rate can be done. This may be useful if you are doing signal processing or working in some other environment where listening to the result is not your goal. The simplest example for resampling a wav is something like this:

sox input.wav -r 10k output.wav

Order of file names and arguments are important. Let's take a more complete example to work through what is happening.

sox -r 44.1k input.wav -r 10k output.wav

Any file format descriptor flags will be applied to the next filename on the command line. So here, we are forcing sox to treat input.wav as if it has a sample rate of 44.1 kHz even if the wav header says something different. The output wav file will be generated with a 10 kHz sample rate, downsampling the audio as needed. So, the input file must come before the output file. Any file format descriptors must be specified before the file name that they apply to.

Any file format types not specified on the command line will be interpreted from the file, if possible. If you can trust your wav headers, it is best to let sox discover the input file format and just focus on specifying the output format you want.