python
  • python-2.7
  • 2017-02-13 29 views 0 likes 
    0

    sox.exe`我從Windows CMD運行此命令成功行:運行`在Python

    c:\cygwin\bin\sox.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正確啓動此命令?

    回答

    1

    嘗試分開你的論點

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

    如果不工作,你可以強制使用CMD與shell=True

    +0

    謝謝。不工作。我需要將16000和1放在引號中,所以這是有效的:subprocess.call([sox,'-r','16000','-c','1',in_fixed,out_float])。請鄒先生解決答案。不過,這個解決方案不是很方便;我仍然想在一個變量中傳遞我的參數。 – Danijel

    +1

    然後作爲一個變量傳遞並調用'sox.split()'...顯然,當你的命令中有空格時不起作用。 –

    相關問題