I have written a demo project for voice recognition bot. But I am facing some error which shows that the object has no attribute. I have attached the code below
def speak(audio):
print('Computer: ' + audio)
engine.say(audio)
engine.runAndWait()
function of myCommand:
def myCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
query = r.recognize_google(audio, language='en-in')
print('User: ' + query + '\n')
except sr.UnknownValueError:
speak('Sorry sir! I didn\'t get that! Try typing the command!')
query = str(input('Command: '))
return query
Main function:
if __name__ == '__main__':
while True:
query = myCommand()
print(query)
query = query.lower()
print(query)
if 'open youtube' in query:
speak('okay')
webbrowser.open('www.youtube.com')
elif 'open google' in query:
speak('okay')
webbrowser.open('www.google.co.in')
else:
query = query
speak('Searching...')
try:
try:
res = client.query(query)
results = next(res.results).text
speak('WOLFRAM-ALPHA says - ')
speak('Got it.')
speak(results)
except:
results = wikipedia.summary(query, sentences=2)
speak('Got it.')
speak('WIKIPEDIA says - ')
speak(results)
except:
webbrowser.open('www.google.com')
speak('please give me Next Command! Sir!')
query = query.lower() AttributeError: 'NoneType' object has no attribute 'lower'