gpt4 book ai didi

python - 即使我有最新的 PyAudio,也会出现 PyAudio 错误

转载 作者:行者123 更新时间:2023-12-04 07:59:02 25 4
gpt4 key购买 nike

我正在尝试运行以下 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 ,我得到以下信息:

Requirement already satisfied: pyaudio in/usr/local/lib/python3.5/dist-packages (0.2.11)

最佳答案

您的错误消息表明它使用的是安装在 python2.7 中的 pyaudio,但底部的错误消息引用了 python3 中的 pyaudio。尝试显式使用 python3 来调用程序。您可以通过执行以下操作来确保:

  • 更改文件顶部的 shebang 行以告诉 shell 使用什么来执行脚本:
  • #!/usr/bin/env python3
  • 调用脚本时直接在命令行调用:
  • $ python3 myscript.py
    这些将解决您的问题并使用正确版本的 python 来运行程序。

    关于python - 即使我有最新的 PyAudio,也会出现 PyAudio 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66551659/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com