Sox – End Recording When Silence is Detected

audioscriptingsox

I'm writing a script that uses sox to record me talking.
Now I need sox to wait until it detects sound before it begins recording, and I do have that figured out. But I also need sox to exit once there has been silence for at least 3 seconds.
As it is now, I have to manually kill sox once I finish talking, otherwise sox just waits again until I talk some more, appending to the output file (That's not what I want).
Here is the command for recording I am using now:

rec /tmp/recording.flac rate 32k silence 1 0.1 3% -1 3.0 3%

Again, just to be clear, Sox should wait until I start talking, and then record until I stop talking, then the sox program should quit.

Best Answer

Remove the negative sign from your original command:

rec /tmp/recording.flac rate 32k silence 1 0.1 3% 1 3.0 3%

When the "below count" is negative, the silence command will trim all silences from the middle of the file. When it's positive, it trims silence from the end of the file.

Related Question