在Python中使用speech_recognition模块获取TypeError

时间:2016-08-04 17:29:28

标签: python-2.7 speech-recognition speech-to-text

我想使用模块SpeechRecognition 3.4.6实时将语音转换为文本我已经安装了所有内容,现在我正在尝试一个简单的代码示例,这里是代码:

import speech_recognition as sr

# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Say something!")
    audio = r.listen(source)

# recognize speech using Sphinx
try:
    print("Sphinx thinks you said " + r.recognize_sphinx(audio))
except sr.UnknownValueError:
     print("Sphinx could not understand audio")
except sr.RequestError as e:
     print("Sphinx error; {0}".format(e)) 

我在第audio = r.listen(source)行收到错误,错误回溯是:

Traceback (most recent call last):
File "sr.py", line 4, in <module>
audio = r.listen(source)                   # listen for the first    phrase and extract it into audio data
 File "/usr/local/lib/python2.7/dist-  packages/speech_recognition/__init__.py", line 493, in listen
 buffer = source.stream.read(source.CHUNK)
 File "/usr/local/lib/python2.7/dist-packages/speech_recognition/__init__.py", line 139, in read
  return self.pyaudio_stream.read(size, exception_on_overflow = False)
  File "/usr/local/lib/python2.7/dist-packages/pyaudio.py", line 608, in read
 return pa.read_stream(self._stream, num_frames, exception_on_overflow)
 TypeError: function takes exactly 2 arguments (3 given)

2 个答案:

答案 0 :(得分:0)

你需要安装pyaudio 0.2.9,好像你有旧版本

答案 1 :(得分:0)

似乎python的版本太旧了。