我有一段代码尝试使用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代码块中运行,该代码块将数据发送到浏览器(我正在转换文本并将其发送到网页)。我不确定这是不是一个问题。
系统信息:
venv和system的Python版本:
(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。
答案 0 :(得分:1)
根据完整的代码段发布此答案:
Debugging Chart Mapping Windows-1252 Characters to UTF-8 Bytes to Latin-1 Characters
你的盒子里没有flac编码器/解码器:
sudo apt-get install flac