2017-04-20 79 views
1

我想使用SVOX/pico2wave從Python代碼編寫wav文件。當我從文件寫入就好終端執行該行:Python子程序調用在寫入文件時拋出錯誤

/usr/bin/pico2wave -w=/tmp/tmp_say.wav "Hello world." 

我驗證過pico2wave位於/usr/bin

這是我的Python代碼:

from subprocess import call 

call('/usr/bin/pico2wave -w=/tmp/tmp_say.wav "Hello world."') 

...這將引發此錯誤:

Traceback (most recent call last): 
    File "app/app.py", line 63, in <module> 
    call('/usr/bin/pico2wave -w=/tmp/tmp_say.wav "Hello world."') 
    File "/usr/lib/python2.7/subprocess.py", line 168, in call 
    return Popen(*popenargs, **kwargs).wait() 
    File "/usr/lib/python2.7/subprocess.py", line 390, in __init__ 
    errread, errwrite) 
    File "/usr/lib/python2.7/subprocess.py", line 1024, in _execute_child 
    raise child_exception 
OSError: [Errno 2] No such file or directory 

回答

2

documentation

Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names). If passing a single string, either shell must be True (see below) or else the string must simply name the program to be executed without specifying any arguments.

所以,你可能有

嘗試
call(['/usr/bin/pico2wave', '-w=/tmp/tmp_say.wav', '"Hello world."']) 
相關問題