Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
in Python by (47.6k points)

I am running a python script for speech-recognition:

def readAudioFile(audio_file):

    r = sr.Recognizer()

    file = sr.AudioFile(audio_file)

    with file as source:

        audio = r.record(source)



        message = r.recognize_google(audio)


        print("Data extracted from phone conversation:\n" + message)

    except sr.UnknownValueError:

        print("Google Speech Recognition could not understand audio")

But when I run this, I get NameError: name 'sr' is not defined error. How to solve this?

1 Answer

0 votes
by (106k points)
edited by

It looks like from the code that you are using speech_recognition module but you are missing the import. Include the below-mentioned line at the beginning of your script and see if it works:

import speech_recognition as sr

To know more about this you can have a look at the following video:-

Related questions

+1 vote
1 answer
+10 votes
1 answer
0 votes
1 answer

Browse Categories