-2

I have been working on converting speech to text using speech_recognition library on my Jupyter Notebook. All of a sudden, the code throws an error and I have no idea where to even start to solve this. The code is shown below:

import speech_recognition as sr
r = sr.Recognizer()

with sr.AudioFile('/audio1659122935.wav') as source:
    audio_text = r.record(source)
    
    try:
        txt = r.recognize_google(audio_text)
        print(text)
    except:
        print('Error... Try again...')

This generates the except message "Error... Try again..."

Did anyone have the same issue with using speech_recognition?

The speech_recognition version is 3.8.1 and my python version is 3.8.5

NerdOnTour
  • 634
  • 4
  • 15
user9532692
  • 584
  • 7
  • 28
  • Instead of just `print('Error... Try again...')`, print out the exception/stack trace. [How to get exception message in Python properly](https://stackoverflow.com/a/33239954) – 001 Nov 30 '21 at 16:14
  • Remove (unwrap) the `try: except:`. You can never know what error is happening if you do what you're now doing. – AKX Nov 30 '21 at 16:14
  • OMG it was just a simple mistake of using a wrong variable text! Thanks guys! – user9532692 Nov 30 '21 at 16:17

1 Answers1

0

It was just a simple mistake using the wrong variable text. Also just unwrap the try except clause to see where the error occurs.

user9532692
  • 584
  • 7
  • 28