Python error "NameError: name 'sr' is not defined"

0 votes

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)
        type(audio)
    try:
        message = r.recognize_google(audio)
        print(message)
        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?

Nov 28, 2018 in Python by digger
• 27,620 points
1,652 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

I guess you are using speech_recognition module and missing the import. Include this line at the beginning of your script and see if it works:

import speech_recognition as sr
answered Nov 28, 2018 by Omkar
• 65,810 points

Related Questions In Python

0 votes
0 answers

what is a name error in python?

why am i getting a name error ...READ MORE

Mar 7 in Python by anonymous
61 views
0 votes
1 answer

'python' is not recognized as an internal or external command

I have met same issue when I ...READ MORE

answered Aug 24, 2018 in Python by Priyaj
• 56,100 points
59 views
0 votes
1 answer

Python `if x is not None` or `if not x is None`?

There's no performance difference, as they compile ...READ MORE

answered Sep 3, 2018 in Python by Priyaj
• 56,100 points
91 views
0 votes
1 answer

Raw_Input() Is Not Defined

For Python 3.x, use input(). For Python 2.x, ...READ MORE

answered Sep 3, 2018 in Python by Priyaj
• 56,100 points
577 views
0 votes
2 answers

Error: Speech to Text Codec cannot decode the bytes in position

import speech_recognition as sr r = sr.Recognizer() audio ='C\Users\Desktop\audiofile1.wav' with ...READ MORE

answered Nov 27, 2018 in Python by Nabarupa Das
71 views
0 votes
1 answer
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 920 points
18 views
0 votes
1 answer

Python argparse error "NameError: name 'file' is not defined"

The right datatype for destination in argpasrse module ...READ MORE

answered Nov 28, 2018 in Python by Omkar
• 65,810 points
628 views
0 votes
1 answer

How to print a message or the error if a file is not found?

To print the message that file is not ...READ MORE

answered Jan 2 in Python by Omkar
• 65,810 points
10 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.