1

This is my code:

import speech_recognition as sr r = sr.Recognizer() with sr.Microphone() as source: print("Go ahead!") audio = r.listen(source) try: text = r.recognize_google(audio) print("Understood: %s" % text) except: print("Couldnt recognize your voice") 

But if I start the program it says Go ahead! but nothing else happens... Is it because I might have to gran python the microphone somehow? Im on Mac It doesn't print an error message or say Couldnt recognize your voice

4
  • What's the Python version you are using and what's the error printed if you remove both "try" and "except"? Commented Jul 6, 2020 at 12:42
  • it docent print an error message and im on python 3.7 Commented Jul 6, 2020 at 12:44
  • As you said nothing happens, which means the code has not entered the try except block I believe. When you run this code, is it showing something in your terminal? any message? Commented Jul 6, 2020 at 12:51
  • It says Go ahead! but nothing else Commented Jul 6, 2020 at 14:40

3 Answers 3

2

The problem was using the integrated terminal. Using an external Terminal like iTerm or the default terminal app will solve the problem

Sign up to request clarification or add additional context in comments.

3 Comments

Did you find a solution by now how to use the integrated terminal?
unfortunately not
I was using alacrity and it wasn't working for me as well. Now I'm using a regular terminal and it works for me. Thank you!
0

Firstly try using Python up to 3.6.

Then install the following:

xcode-select --install brew remove portaudio brew install portaudio pip3 install pyaudio 

Now it should work. Also, in order to debug your code, remove the block try/except. It will help you checking what's wrong.

2 Comments

@JGStyle, after "r = sr.Recognizer()", add "r.dynamic_energy_threshold = False" (on the next row)
unfortunately still the same results
0

It was all about the threshold for me, my macbook's microphone is too sensitive for its own good and it wasn't "stuck" per say. It was simply listening endlessly since it thought I wasn't done talking.

You can verify this by opening the microphone interface on the side and lowering it all the way down as soon as you finish talking and will then proceed to the "recognizing" step, but that's far from an ideal solution.

What you can do though is increasing the threshold sensitivity which might work just fine for you.

r.energy_threshold = 5000 

Even with this, my microhpone was still too sensitive, so I opted for a push to talk solution where I would hold a button, speak, then release the button.

Here's a nice freeware that you can use. That said, it does not work for M1 out of the box so you have to build it from source (this is as easy as running two commands or three, if you have an xcode error)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.