13

I'm trying to use the speech recognition module with python 3.5.1 to make my jarvis AI voice activated! I have looked through stack overflow and found some questions similar to mine but they did not have the answer that i needed, i need an answer individualized for this. I have downloaded all the necessary packages and still no luck, i get this error:

ImportError: No module named 'speech_recognition'

If I run:

python -m speech_recognition

In terminal it runs only in terminal, i can talk to it and it isn't nearly spot on but it hears me and and can interpret some words. I have downloaded all the packages in terminal from this sites instructions.

https://pypi.python.org/pypi/SpeechRecognition/

When i run my code in IDLE my code gets the error shown above. I'm on a iMac running macOS Sierra 10.12.2, if anyone has the answer that would be helpful. Thank you!

heres my code:

import speech_recognition
import pyttsx

speech_engine = pyttsx.init('sapi5') # see         
speech_engine.setProperty('rate', 150)

def speak(text):
   speech_engine.say(text)
   speech_engine.runAndWait()

recognizer = speech_recognition.Recognizer()

def listen():
    with speech_recognition.Microphone() as source:
        recognizer.adjust_for_ambient_noise(source)
        audio = recognizer.listen(source)

    try:
        return recognizer.recognize_sphinx(audio) 
        # or: return recognizer.recognize_google(audio)
    except speech_recognition.UnknownValueError:
        print("Could not understand audio")
    except speech_recognition.RequestError as e:
        print("Recog Error; {0}".format(e))

    return ""



speak("Say something!")
speak("I heard you say " + listen())
Sergei Glimis
  • 390
  • 2
  • 5
  • 17

12 Answers12

22

Install Speech Recognition using

pip install SpeechRecognition

Senthuja
  • 520
  • 1
  • 7
  • 19
5

I upgraded my python to 3.7 in mac, but then I was facing similar issue.

pip3 install SpeechRecognition

this worked for me

Supreet Singh
  • 882
  • 12
  • 9
2

Try this in windows command prompt for python 3.7 32 bit

python -m pip install -U pip

pip install winspeech

pip install SpeechRecognition
Viktor
  • 2,623
  • 3
  • 19
  • 28
Arun Singh
  • 21
  • 3
1

OS X Sierra comes with Python 2.7.10. Since you are using Python 3.5.1, you have presumably installed it yourself and you now have two versions of Python. IDLE is clearly running with the Python version for which you did not install the speech_recognition module.

What to do depends on your set-up. I'd start by running idle3 from the command line, instead of idle. If your module is installed for Python 3, that's all you need. If this doesn't work, check everything with an eye to the different versions and straighten them out the way you want them.

alexis
  • 48,685
  • 16
  • 101
  • 161
  • wait how would i go at running IDLE 3 in the terminal? – Sergei Glimis Jan 23 '17 at 01:38
  • 1
    i figured it out i wrote: python3 -m speech_recognition in terminal – Sergei Glimis Jan 23 '17 at 01:40
  • what do i do now i can't downgrade python to 2.7.10 can i? – Sergei Glimis Jan 23 '17 at 01:41
  • 1
    can i use pip3 to install it now, i tried and it says You are using pip version 7.1.2, however version 9.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. so i update and then it say Requirement already up-to-date: pip in /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg – Sergei Glimis Jan 23 '17 at 01:47
  • Thank you, you have diagnosed the problem but how do i fix it? – Sergei Glimis Jan 23 '17 at 02:21
  • If it works when you type `python3 -m speech_recognition`, you have already installed it for Python 3; so don't worry about `pip3`, you don't need that anymore. To launch IDLE 3, type `idle3` or `idle3 ` (lowercase) at the terminal. – alexis Jan 23 '17 at 09:39
  • Ok but when i type in (python3 -m speech_recognition) it gives the error: /Library/Frameworks/Python.framework/Versions/3.5/bin/python3: No module named speech_recognition. if i run (pip3 install SpeechRecognition) to download it for python 3, it gives me the error: (error: could not create '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/speech_recognition': Permission denied) You are using pip version 7.1.2, however version 9.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. – Sergei Glimis Jan 24 '17 at 02:14
  • Then I update the pip with (pip install --upgrade pip) and it says its already up to date?!?!?!: Requirement already up-to-date: pip in /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg – Sergei Glimis Jan 24 '17 at 02:16
  • I need help ;( i feel hopeless (and when it works in terminal the code can barely understand what i'm saying. When i say "now" it thinks i'm say "no" and vise versa and when i say "what's up" it thinks i'm say WhatsApp almost always. How do you get it to understand you is that what some of those other modules are for, like the pocket sphinx one what does that do does that help it understand you?? – Sergei Glimis Jan 24 '17 at 02:22
  • I'm afraid I know nothing about python's speech recognition modules-- and it's a different question, so you should write a new question to conform with the rules of the site. Make sure to make it as specific as possible, phrase it so that it's about programming, and **not** to ask for a software recommendation-- that's not permitted. – alexis Jan 24 '17 at 08:37
  • Anyway speech recognition is a hard problem. You get better performance with models you can "train" to your voice, often by reading aloud known texts. But don't be surprised if the little free module you downloaded and run from your script doesn't give you usable performance. – alexis Jan 24 '17 at 08:38
  • ok thank you Alexis i will keep it in mind, and i will ask another question. – Sergei Glimis Jan 24 '17 at 23:28
1

enter image description here

Try This it will work! I had faced the same problem.

 pip install SpeechRecognition
Md.Rakibuz Sultan
  • 759
  • 1
  • 8
  • 13
1

for python3 try running the command to install the SpeechRecognition module: pip3 install SpeechRecognition

Mayunga6
  • 11
  • 1
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33088508) – hide1nbush Nov 07 '22 at 07:58
0

In may case the error was - No module named speechRecognition incase that's the case with you try editing the import code and use import speech_recognition as sr It worked for me. Sometimes pip gives these issues

0

First, make sure you have all the requirements listed in the “Requirements”:

Install Xcode in Unix Development mode. Install Xcode - Command Line tools (Type 'Xcode-select —install' in the terminal )

**

Install Port or Brew (port  [or] Brew  )
sudo brew install portaudio [or] sudo port install portaudio (for loading mic drivers)
sudo pip install pyaudio [or] sudo easy_install install pyaudio (Mic Sources)
sudo pip install SpeechRecognition [or] sudo easy_install install SpeechRecognition
sudo port install FLAC.

**

The Coding Bus
  • 443
  • 1
  • 6
  • 19
0

I solved this problem. I just installed SpeechRecognition in project properties. Settings -> Project:(nameofyourproject)-> Python: Interpreter. Click on plus and find SpeechRecognition, install it.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 18 '22 at 06:48
0

in pychaem tap the hint(alt+enter) and tap install packages while select the package or tap F2 to take to it .

-1

What worked for me was, I installed jupyter notebooks again and on anaconda prompt and then I executed pip install SpeechRecognition

followed by

pip install PyAudio-0.2.11-cp39-cp39-win_amd64.whl

again.

Arju Mann
  • 1
  • 2
-3

user must be root so use

sudo pip install --upgrade pip

It will work.

Mr. T
  • 11,960
  • 10
  • 32
  • 54
Omy
  • 255
  • 3
  • 4