子进程返回 No such file or directory for file that exists
Subprocess returning No such file or directory for file that exists
我有一段代码试图使用 SpeechRecognition(在 PyPi 中可用)提交音频文件以转录为 bing 语音 api:
filename = 'part' + str(entry['srcID']) + '.flac'
with open(filename, 'w') as filehandle:
harkclient.getSeparatedAudio(handle=filehandle, srcID=entry['srcID'])
with speech_recognition.AudioFile(path.join(path.dirname(path.realpath(__file__)), filename)) as source:
audio = speechclient.record(source)
抛出以下异常:
File "./websocket_server.py", line 105, in send_data
with speech_recognition.AudioFile(path.join(path.dirname(path.realpath(__file__)), filename)) as source:
File "/srv/www/harkvisualizer/harkenv/local/lib/python2.7/site-packages/speech_recognition/__init__.py", line 195, in __enter__
], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
文件存在
(harkenv) root@ip-172-31-28-12:/srv/www/harkvisualizer# ls | grep flac
part0.flac
我打印了传递给 AudioFile() 函数的路径,这是正确的。我还播放了音频文件,以确保它符合我的预期。我尝试在 popen 调用的源代码中添加 shell=True arg,因为我读到了一些潜在的问题,但它没有解决。这是虚拟环境中的 运行,在将数据发送到浏览器的 websocket 代码块中(我正在转换文本并将其发送到网页)。我不确定这是否是个问题。
系统信息:
Python venv 和系统版本:
(harkenv) root@ip-172-31-28-12:/srv/www/harkvisualizer# which python
/srv/www/harkvisualizer/harkenv/bin/python
(harkenv) root@ip-172-31-28-12:/srv/www/harkvisualizer# python --version
Python 2.7.6
root@ip-172-31-28-12:/srv/www/harkvisualizer# /usr/bin/python --version
Python 2.7.6
我的 SpeechRecognition 库版本 是 3.4.6。
根据完整代码片段发布此问题的答案:
https://github.com/Uberi/speech_recognition/blob/master/speech_recognition/init.py#L195
您的盒子里缺少 flac encoder/decoder:
sudo apt-get install flac
我有一段代码试图使用 SpeechRecognition(在 PyPi 中可用)提交音频文件以转录为 bing 语音 api:
filename = 'part' + str(entry['srcID']) + '.flac'
with open(filename, 'w') as filehandle:
harkclient.getSeparatedAudio(handle=filehandle, srcID=entry['srcID'])
with speech_recognition.AudioFile(path.join(path.dirname(path.realpath(__file__)), filename)) as source:
audio = speechclient.record(source)
抛出以下异常:
File "./websocket_server.py", line 105, in send_data
with speech_recognition.AudioFile(path.join(path.dirname(path.realpath(__file__)), filename)) as source:
File "/srv/www/harkvisualizer/harkenv/local/lib/python2.7/site-packages/speech_recognition/__init__.py", line 195, in __enter__
], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
文件存在
(harkenv) root@ip-172-31-28-12:/srv/www/harkvisualizer# ls | grep flac
part0.flac
我打印了传递给 AudioFile() 函数的路径,这是正确的。我还播放了音频文件,以确保它符合我的预期。我尝试在 popen 调用的源代码中添加 shell=True arg,因为我读到了一些潜在的问题,但它没有解决。这是虚拟环境中的 运行,在将数据发送到浏览器的 websocket 代码块中(我正在转换文本并将其发送到网页)。我不确定这是否是个问题。
系统信息:
Python venv 和系统版本:
(harkenv) root@ip-172-31-28-12:/srv/www/harkvisualizer# which python
/srv/www/harkvisualizer/harkenv/bin/python
(harkenv) root@ip-172-31-28-12:/srv/www/harkvisualizer# python --version
Python 2.7.6
root@ip-172-31-28-12:/srv/www/harkvisualizer# /usr/bin/python --version
Python 2.7.6
我的 SpeechRecognition 库版本 是 3.4.6。
根据完整代码片段发布此问题的答案:
https://github.com/Uberi/speech_recognition/blob/master/speech_recognition/init.py#L195
您的盒子里缺少 flac encoder/decoder:
sudo apt-get install flac