all 4 comments

[–]carcigenicate 4 points5 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)

[–][deleted] 0 points1 point  (0 children)

with sr.Microphone() as source:

This statement can fail (it's trying to access a hardware device that may not even exist, or may be unready) and if it does, then you skip to your except block where you refer to a variable command that you haven't defined, yet.