python - 即使我有最新的 PyAudio,PyAudio 也会出错
问题描述
我正在尝试运行以下 python 程序,但我遇到了一些错误。该程序旨在将语音转换为文本,它使用的是我使用 CMUSphinx 训练的声学模型。
编码:
#!/usr/bin/env python
import os
import speech_recognition as sr
from pocketsphinx import AudioFile
hmm = '/home/ridwan/sphinx/other2/model_parameters/other2.ci_cont' #folder of the acoustic model
lm = '/home/ridwan/sphinx/other2/etc/other2.lm.DMP' #language model
dict = '/home/ridwan/sphinx/other2/etc/other2.dic' #the phonetic dictionary
#model_path = get_model_path()
#data_path = get_data_path()
r = sr.Recognizer()
with sr.Microphone() as source:
print("Please wait. Calibrating microphone...")
# listen for 5 seconds and create the ambient noise energy level
r.adjust_for_ambient_noise(source, duration=5)
print("Say something!")
audio = r.listen(source)
config = {
'verbose': False,
'audio_file': audio,
'buffer_size': 2048,
'no_search': False,
'full_utt': False,
'hmm': hmm,
'lm': lm,
'dict': dict
}
audio = AudioFile(**config)
for phrase in audio:
print(phrase)
追溯:
Traceback (most recent call last):
File "main2.py", line 15, in <module>
with sr.Microphone() as source:
File "/usr/local/lib/python2.7/dist-packages/speech_recognition/__init__.py", line 79, in __init__
self.pyaudio_module = self.get_pyaudio()
File "/usr/local/lib/python2.7/dist-packages/speech_recognition/__init__.py", line 113, in get_pyaudio
raise AttributeError("PyAudio 0.2.11 or later is required (found version {})".format(pyaudio.__version__))
AttributeError: PyAudio 0.2.11 or later is required (found version 0.2.10)
但是我已经安装了 PyAudio 0.2.11。当我这样做时pip install pyaudio
,我得到以下信息:
已满足要求:/usr/local/lib/python3.5/dist-packages (0.2.11) 中的 pyaudio
解决方案
您的错误消息表明它正在使用安装在 python2.7 中的 pyaudio,但底部的错误消息是引用 python3 中的 pyaudio。尝试显式使用 python3 来调用程序。您可以通过执行以下操作来确保:
- 更改文件顶部的 shebang 行以告诉 shell 使用什么来执行脚本:
#!/usr/bin/env python3
- 调用脚本时直接在命令行调用它:
$ python3 myscript.py
这些将解决您的问题并使用正确版本的 python 来运行程序。
推荐阅读
- jenkins - 无法使用 AppiumDriverLocalService 在 Jenkins 上运行 Appium 测试
- react-native - 如何在 React Native 中默认打开登录屏幕
- qt - 使用样式表设置 QLabel backgroundLabel 图像
- sql - 根据日期范围将数据填充到表中
- focus - 未捕获的类型错误:无法读取 null 的属性“焦点”
- javascript - 鼠标向上时如何获取td,div标签的id
- java - JScrollPane 内的内部 JScrollPane 工作不正常
- c# - EF Table-Per-Type:向现有父级添加新子级
- tfs - 在构建期间查找规则集文件
- php - 电子邮件未从服务器发送