I am trying to overlay two files (merge them into one so they plat simultaneously).

The options for sox --combine are sequence, concatenate, mix, mix-power, merge, and multiply. I've looked at the docs here and it's not entirely evident which I should use. sequence and concatenate do work when they have different sample rates but it does not overlay them.

I am trying to use mix, but it's not allowing me to set the sample rate to 41k (which from my understanding is the correct one for mp3):

To precaution against different sample rates, I'm looping through the input files and setting all their sample rates to 41k. I have the following code to do this:

sox -r 44.1k input1.mp3 output1.mp3
sox -r 44.1k input2.mp3 output2.mp3

I get this (it differs between files)

sox WARN formats: can't set sample rate 44100; using 24000
sox WARN formats: can't set sample rate 44100; using 48000

Then when I try and overlay them using the following command:

sox --combine mix output1.mp3 output2.mp3 output3.mp3 

I see this:

sox FAIL sox: Input files must have the same sample-rate

I am on Ubuntu 16.04.

As a workaround I'm using the ffmpeg command shown here: https://stackoverflow.com/questions/14498539/how-to-overlay-two-audio-files-using-ffmpeg

This is actually fine for me and gets the job done though I would be curious to know why the sox didn't work.

1 Answer 1


To change the sampling rate with sox, you need to use the rate effect to resample (which will degrade quality a tiny bit). -r just specifies the rate if it's not available in the file format, or if there are several rates possible, like for devices.

And there's no "correct" sampling rate for MP3, you'll get the best results if both input MP3s have the same sampling rate, and if you just keep this rate. If one rate is a multiple of the other rate (e.g. 48000 and 24000), use the larger one (48000).

There are a number of tools to query the sampling rates, e.g. mediainfo.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .