Running `sox.exe` from Python



我成功地从Windows cmd行运行了以下命令:

c:cygwinbinsox.exe -r 16000 -c 1 c:/work/out/in_fixed.s32 c:/work/out/out_float.f32

但是,我无法从 Python 运行它:

import subprocess
if __name__ == "__main__":
    sox = 'c:/cygwin/bin/sox.exe'
    in_fixed = 'c:/work/out/in_fixed.s32'
    out_float = 'c:/work/out/out_fixed.f32'
    cmnd = '-r 16000 -c 1 ' + in_fixed + ' ' + out_float
    subprocess.call([sox, cmnd])

错误是:

/usr/bin/sox FAIL sox: Rate value ` 16000 -c 1 c:/work/out/in_fixed.s32 c:/work/out/out_fixed.f32' is not a positive number. 

如何从python正确启动此命令?

尝试分离参数

subprocess.call([sox, '-r', str(16000), '-c', str(1), in_fixed, out_float])

如果这不起作用,您可以使用 shell=True 强制使用 CMD .

最新更新