How to record 10 seconds of audio with SoX?

All we need is an easy explanation of the problem, so here it is.

I want to record 10 seconds of audio from my microphone input with SoX. I haven’t found any example in the documentation or elsewhere that would show how to do it. Here’s my current command using timeout to stop the recording. Is there a better way to do it?

timeout 10 sox -b 32 -e unsigned-integer -r 96k -c 2 -d --clobber --buffer $((96000*2*10)) /tmp/soxrecording.wav

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

A little late, but if anyone had the same question, you have to use the trim “effect” to record a set length of audio.

So to record 10 seconds of audio just append trim 0 10 at the end of your command, e.g.,

$ sox -b 32 -e unsigned-integer -r 96k -c 2 -d --clobber --buffer $((96000*2*10)) /tmp/soxrecording.wav trim 0 10

From the SoX man:

trim {position(+)}

Cuts portions out of the audio. Any number of positions may be given;
audio is not sent to the output until the first position is reached.
The effect then alternates between copying and discarding audio at
each position. Using a value of 0 for the first position parameter
allows copying from the beginning of the audio.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply