2016-08-04 22 views
1

speech_recognition模塊獲得類型錯誤我想將語音轉換使用SpeechRecognition 3.4.6我已經安裝了一切,現在我想從例如一個簡單的代碼模塊中實時的文字,下面的代碼:可以用Python

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) 

回答

0

您需要安裝pyaudio 0.2.9,看來你有舊版本

0

似乎python的版本太舊了。