Search code examples
pythonsox

SoX commands for Windows


I have these SoX commands that work on Linux, but not on Windows because the Windows version does not ship with play or rec anymore. How can I rework these to use only sox?

rec -c 1 -r 48k -q -n noiseprof - trim 0 5
rec -c 1 -r 48k -q -t flac - noisered - 0.21 silence -l 1 0.0 1% 1 3.0 5% pad 1 0
play -t mp3 - -q

I'm using them in Python for speech recognition and would like to use a statement like this

sox = shutil.which('sox') or glob.glob('C:\Program Files*\sox*\sox.exe')[0]

to make it platform independent.


Solution

  • Exerpt from sox manual:

    The play and rec commands are provided so that basic playing and recording is as simple as

    play existing-file.wav

    and

    rec new-file.wav

    These two commands are functionally equivalent to

    sox existing-file.wav -d

    and

    sox -d new-file.wav

    The -d option means to select the default audio device for input (if it comes first) or output (if comes last).