speech_recognition: Getting error while using speech_recognition module in python.Error: TypeError: function takes exactly 2 arguments (3 given)

I want to convert speech to text in real time using the module SpeechRecognition 3.4.6 I’ve installed everything and now I am trying a simple code from example, here’s the code:

import speech_recognition as sr

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


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)) `



I am getting error on line `audio=r.listen(sourc
  `import speech_recognition as sr
      r = sr.Recognizer()
      with sr.Microphone() as source:
          print("Say something!")
          audio = r.listen(source)
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)) 

I am getting error on line 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)

How to fix this problem.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 29 (3 by maintainers)

Most upvoted comments

Hi, thank you for the reply. I’ve checked everything and actually there were few packages like libportaudio-dev was not installed. It’s working fine now. thanks