python语音识别出错

时间:2015-11-09 22:40:21

标签: python python-3.4 voice-recognition

我一直在尝试获得Python语音识别方面的一些知识,我编写了一个简单的程序,它接受用户所说的内容,并输出它所认为的#39;用户说过。

我的代码是:

   import speech_recognition as sr
   r = sr.Recognizer()
   with sr.Microphone() as source:
   print("Say something!")
   audio = r.listen(source)

   try:
       print("Google Speech Recognition thinks you said " + r.recognize_google(audio))
   except sr.UnknownValueError:
       print("Google Speech Recognition could not understand audio")
   except sr.RequestError as e:
       print("Could not request results from Google Speech Recognition service; {0}".format(e))

我的错误是:

Traceback (most recent call last):
File "C:/Python34/speech.py", line 9, in <module>
with sr.Microphone() as source:
File "C:\Python34\lib\site-packages\speechrecognition-3.1.3-py3.4.egg\speech_recognition\__init__.py", line 61, in __init__
self.format = pyaudio.paInt16 # 16-bit int sampling
AttributeError: 'module' object has no attribute 'paInt16'

任何帮助将不胜感激, 谢谢, - space482

2 个答案:

答案 0 :(得分:0)

pyAudio是Speech_recognition用于连接到用户麦克风的模块。当您使用以下示例:

with sr.Microphone() as source:

.Microphone()类取决于16位的音频格式aka pyaudio.paInt16。当前,此模块中使用的API只能使用1声道(单声道音频),因此可以使用install pyaudio将位大小设置为特定大小。但是,此默认大小需要更新以使用Speech_recognition。要更新此模块,请使用:

pip3 install PyAudio --upgrade

答案 1 :(得分:-1)

Google语音识别使用PyAudio作为依赖项。它可能没有正确安装。尝试从这个非官方的存储库安装:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio

步骤:

  • 下载您的特定版本
  • 确保(32/64)位与Python(32/64)位匹配
  • 使用pip
  • 安装.whl文件