Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
aquibjaved opened this issue Aug 5, 2016 · 29 comments

Comments

@aquibjaved
Copy link

aquibjaved commented Aug 5, 2016

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.

@Uberi
Copy link
Owner

Uberi commented Aug 6, 2016

Hi @aquibjaved,

  1. You don't seem to be using version 3.4.6 - the source code and line numbers are definitely off. Make sure the version is correct by running import speech_recognition as sr;print(sr.__version__) as a Python script. How was the library installed?
  2. What is your PyAudio version? It seems to be out of date - you must have version 0.2.9 or later. Try checking this by running import pyaudio as p;print(p.__version__) as a Python script.

@aquibjaved
Copy link
Author

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

@swapnilkumar25
Copy link

could you please help me to resolve the below error

/usr/bin/python3.5 /home/swapnil/PycharmProjects/speech/google_api.py
Traceback (most recent call last):
File "/home/swapnil/PycharmProjects/speech/google_api.py", line 6, in
with sr.Microphone() as source:
File "/usr/local/lib/python3.5/dist-packages/speech_recognition/init.py", line 79, in init
self.pyaudio_module = self.get_pyaudio()
File "/usr/local/lib/python3.5/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.8)

@ghost
Copy link

ghost commented Sep 23, 2017

@Uberi
Copy link
Owner

Uberi commented Sep 23, 2017

Hi @swapnilkumar25,

You need PyAudio 0.2.11 or later. You have PyAudio 0.2.8. To fix this issue, upgrade your PyAudio installation to version 0.2.11 or later.

If you installed PyAudio using Pip, this should be doable with one command: pip install --upgrade pyaudio. If issues persist, please open a new issue.

@tvikneshwar
Copy link

help to resolve this issue.
I am using PyAudio 0.2.11
Code: https://pastebin.com/raw/i73CR64n
Error log :https://pastebin.com/raw/YE18QWz9

@786adnan
Copy link

786adnan commented Apr 7, 2018

please i have upgrade pyaudio on 0.2.11 but still facing error SyntaxError: unexpected EOF while parsing
how can i fix it

@786adnan
Copy link

786adnan commented Apr 7, 2018

capture
i have upgrade pyAudio on 0.2.11 but still facing an error how can i remove it

@786adnan
Copy link

786adnan commented Apr 7, 2018

please any one help me????

@aquibjaved
Copy link
Author

aquibjaved commented Apr 7, 2018

@786adnan
Copy link

786adnan commented Apr 7, 2018

@aquibjaved sir i have check it i have also scipy; version 0.19.0 but i didn't understand what can i do next??

@786adnan
Copy link

786adnan commented Apr 7, 2018

plz guide me what should i do??

@Uberi
Copy link
Owner

Uberi commented Apr 8, 2018

Hi @786adnan,

You haven't copied all of the code into your Jupyter notebook - it's missing everything after the with statement. Be sure to copy all of the code.

Also, please don't post on other people's issues - feel free to open a new one here!

@atanudeyiitkgp
Copy link

How to solve the problem Please Help:
Note: Version of speech_recognition is 3.8.1
Version of PyAudio is 0.2.11

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

Error


TypeError Traceback (most recent call last)
in ()
6 with sr.Microphone() as source:
7 print("Say something!")
----> 8 audio = r.listen(source)
9
10 # Speech recognition using Google Speech Recognition

/Users/atanudey/anaconda2/lib/python2.7/site-packages/speech_recognition/init.pyc in listen(self, source, timeout, phrase_time_limit, snowboy_configuration)
618 raise WaitTimeoutError("listening timed out while waiting for phrase to start")
619
--> 620 buffer = source.stream.read(source.CHUNK)
621 if len(buffer) == 0: break # reached end of the stream
622 frames.append(buffer)

/Users/atanudey/anaconda2/lib/python2.7/site-packages/speech_recognition/init.pyc in read(self, size)
159
160 def read(self, size):
--> 161 return self.pyaudio_stream.read(size, exception_on_overflow=False)
162
163 def close(self):

/Users/atanudey/anaconda2/lib/python2.7/site-packages/PyAudio-0.2.11-py2.7-macosx-10.6-x86_64.egg/pyaudio.pyc in read(self, num_frames, exception_on_overflow)
606 paCanNotReadFromAnOutputOnlyStream)
607
--> 608 return pa.read_stream(self._stream, num_frames, exception_on_overflow)
609
610 def get_read_available(self):

TypeError: function takes exactly 2 arguments (3 given)

@aquibjaved
Copy link
Author

Hi @atanudeyiitkgp ,
It seems like you didn't have libportaudio-dev not installed, I was also facing the same issue but installing the library helps me.

@atanudeyiitkgp
Copy link

Hi @aquibjaved

Thanks for your reply, but when I tried to install the package using "libportaudio-dev" then also I am getting error. Its not yet installed.

While I am using "pip install libportaudio-dev" then error is
" Could not find a version that satisfies the requirement libportaudio-dev (from versions: )
No matching distribution found for libportaudio-dev"

While I am using "sudo apt-get install libportaudio-dev" then error is "sudo: apt-get: command not found"

Before that, I have also installed "portaudio" using "brew install portaudio". It is installed properly.

Please give me a solution.

@nikateonkar
Copy link

Command "c:\python37\python.exe -u -c "import setuptools, tokenize;file='C:\Users\Robotics\AppData\Local\Temp\pip-install-l_aug1fz\pyaudio\setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record C:\Users\Robotics\AppData\Local\Temp\pip-record-0bc3_y_3\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Robotics\AppData\Local\Temp\pip-install-l_aug1fz\pyaudio\

I am getting this error while installing pyaudio

@Akshar-S-Patel
Copy link

Traceback (most recent call last):
File "C:/Users/Axar/Desktop/Akshar Patel/Python Project/Small Python Projects/Charly.py", line 65, in
take_command()
File "C:/Users/Axar/Desktop/Akshar Patel/Python Project/Small Python Projects/Charly.py", line 46, in take_command
with sr.Microphone as source:
AttributeError: enter

Process finished with exit code 1

plz help me to solve this error

@Abdulfurkan
Copy link

Fullscreen capture 10-08-2019 111936
Getting This Error Can Anyone Help me

@Akshar-S-Patel
Copy link

Akshar-S-Patel commented Aug 12, 2019 via email

@manas0301
Copy link

@Akshar-S-Patel

Traceback (most recent call last):
File "C:/Users/Axar/Desktop/Akshar Patel/Python Project/Small Python Projects/Charly.py", line 65, in
take_command()
File "C:/Users/Axar/Desktop/Akshar Patel/Python Project/Small Python Projects/Charly.py", line 46, in take_command
with sr.Microphone as source:
AttributeError: enter

Process finished with exit code 1

plz help me to solve this error

@Akshar-S-Patel

Hey! I am facing the same error and i could not find the solution. Can you pls help me if you sorted this error. I am working on a project and struct in between due to this....PLS REPLY

@Akshar-S-Patel
Copy link

@manas0301

Hey! I am facing the same error and i could not find the solution. Can you pls help me if you sorted this error. I am working on a project and struct in between due to this....PLS REPLY

  1. Find your Python version by python --version mine is 3.7.3 for example
    the easiest way to check either you have 64 or 32 Python just open python in the terminal and on the first line it shows 64 or 32 bit.

  2. Find the appropriate .whl file from here
    https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio, for example, mine is PyAudio‑0.2.11‑cp37‑cp37m‑win_amd64.whl, for 64 bit and 32-bit
    use 32-bit .whl file and download it.

  3. Go to the folder where it is downloaded for example cd
    C:\Users\foobar\Downloads

install the .whl file with pip for example in my case:

pip install PyAudio-0.2.11-cp37-cp37m-win_amd64.whl

@atanudeyiitkgp
Copy link

atanudeyiitkgp commented Jul 28, 2020

Hi Akshar,

Please follow the below steps.

Step 1: pip install SpeechRecognition

Step 2: Code:
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
# read the audio data from the default microphone
audio_data = r.record(source, duration=5)
print("Recognizing...")
# convert speech to text
text = r.recognize_google(audio_data)
print(text)

Later I only did the above things and it works for me. You can try it, I hope it will work for you too.

Thanks,
Atanu

@aquibjaved
Copy link
Author

module 'pyaudio' has no attribute 'verssion'

please help me solving this

version not verssion I guess

@ashishburdak
Copy link

@Abdulfurkan
Its quite late but you can try -

pip install pipwin
pipwin install pyaudio

this helped me, hope so it will help you.
For more refer - https://stackoverflow.com/questions/51992375/python-package-installation-issues-pyaudio-portaudio

@gitaccsithu
Copy link

PS D:\python_exes> python .\speech.py
Traceback (most recent call last):
File "D:\python_exes\speech.py", line 8, in
with speech_recognition.Microphone() as source:
File "C:\python\python 392\lib\site-packages\speech_recognition_init_.py", line 138, in enter
self.audio.open(
File "C:\python\python 392\lib\site-packages\pyaudio.py", line 750, in open
stream = Stream(self, *args, **kwargs)
File "C:\python\python 392\lib\site-packages\pyaudio.py", line 441, in init
self._stream = pa.open(**arguments)
OSError: [Errno -9999] Unanticipated host error


I'm facing that kind of error... don't know what to do... can anyone help me pls

@kartik-mahato-56
Copy link

kartik-mahato-56 commented Sep 15, 2021

PS D:\python_exes> python .\speech.py
Traceback (most recent call last):
File "D:\python_exes\speech.py", line 8, in
with speech_recognition.Microphone() as source:
File "C:\python\python 392\lib\site-packages\speech_recognition__init__.py", line 138, in enter
self.audio.open(
File "C:\python\python 392\lib\site-packages\pyaudio.py", line 750, in open
stream = Stream(self, *args, **kwargs)
File "C:\python\python 392\lib\site-packages\pyaudio.py", line 441, in init
self._stream = pa.open(**arguments)
OSError: [Errno -9999] Unanticipated host error

I'm facing that kind of error... don't know what to do... can anyone help me pls

I have the same issue..Can someone help me please??
and I have already installed pyaudio version 0.2.11 and speech recognition version 3.8.1
and my python version is python 3.9.4

@aquibjaved
Copy link
Author

Hey guys,
can you look into following:
#20
#71

@nsisong
Copy link

nsisong commented Mar 30, 2022

for me, r.recode(source, duration = 5)
works well but when i do
r.listen(source) it just hangs here

i have installed portaudio but still not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests