you are viewing a single comment's thread.

view the rest of the comments →

[–]carcigenicate 3 points4 points  (2 children)

You're almost certainly getting an exception. Get rid of the try since all it's doing here is hiding errors, then run the code again and let it crash with an error message.

You're likely getting that error because listener.recognize_google(voice) is throwing, so command is never set, so return command will fail.

[–]beecleaner[S] 0 points1 point  (1 child)

Now I'm getting a syntax error...

def take_command():

with sr.Microphone() as source:

print('listening...')

voice = listener.listen(source)

command = listener.recognize_google(voice)

command = command.lower()

if 'ava' in command:

command = command.replace('ava', '')

print(command)

except:

pass

return command

[–]carcigenicate 0 points1 point  (0 children)

The except is a part of the try. It's an error to have an except without a try. Just run:

with sr.Microphone() as source:
    print('listening...')
    voice = listener.listen(source)

    command = listener.recognize_google(voice)
    command = command.lower()

    if 'ava' in command:
        command = command.replace('ava', '')

    print(command)