SOX - Start and Stop Recording when silence detected

184 Views Asked by At

I'm trying to use SOX to start when there is sound and stop when there is silence. I can get it to work on the command Line:

rec recording.wav rate 32k silence 1 0.1 2% 1 3.0 2% 

But when I try to replicate in a python script:

import sox
args  = ['-d', '-t', 'wav','recording.wav', 'rate','32k', 'silence', '1', '0.1', '2%', '1', '3.0','2%']
sox.core.sox(args)

The program just ends. No errors, no file created. Nothing

1

There are 1 best solutions below

0
Hankp On

I solved this with the following code:

import os
os.environ['AUDIODRIVER']= 'alsa'
os.system('rec recording.wav rate 44k silence 1 0.1 1% 1 3.0 1%')