Yeah as Carcigenicate said it is because command is only defined in the try block. This means that if there is an error then command is not defined. I don't know if it is just in the code you posted here but there is an indent error in the with statement
try:
with self.microphone as source:
print('Listening...')
voice = self.recognizer.listen(source)
command = self.recognizer.recognize_google(voice, language='en-IN')
print(command)
except:
raise CustomError
# or return None, command = None, etc just define command before the last line
# or don't let the function reach the return command statement
return command
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…