2017-02-13 3 views
0

ich diesen Befehl von Windows-cmd laufen Linie erfolgreich:Laufen `sox.exe` von Python

c:\cygwin\bin\sox.exe -r 16000 -c 1 c:/work/out/in_fixed.s32 c:/work/out/out_float.f32

aber ich versage es von Python laufen:

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]) 

Ther Fehler :

/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. 

Wie startet man diesen Befehl von Python richtig?

Antwort

1

Versuchen Trennung Ihre Argumente

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

Wenn das nicht funktioniert, können Sie CMD Nutzung zwingen, mit shell=True.

+0

Danke. Funktioniert nicht. Ich muss 16000 und 1 in Anführungszeichen setzen, also funktioniert das: subprocess.call ([sox, '-r', '16000', '-c', '1', in_fixed, out_float]). Könnten Sie bitte die Antwort korrigieren? Dennoch ist diese Lösung nicht sehr praktisch; Ich möchte meine Argumente immer noch in einer Variablen übergeben. – Danijel

+1

Dann übergeben als eine Variable und rufen Sie 'sox.split()' ... offensichtlich wird das nicht funktionieren, wenn es Leerzeichen in Ihrem Befehl gibt. –