G
G
GRIMSHOT2021-07-06 23:17:48
Python
GRIMSHOT, 2021-07-06 23:17:48

How to check if an element is in a text array?

I am writing a voice assistant, I made a text array of options for commands that can be set to an assistant, and I can’t check if there is a given word or expression that was said into the microphone in the array

voice = r.recognize_google(audio, language = "ru-RU").lower()


    cmdList = {
        "hello": ('привет','добрый день','добрый вечер','доброе утро'),
    }

    for x in cmdList["hello"]:  #посмотрел в интернете примеры, этот код надо исправить
        if cmdList == voice:
            speak("Доброго времени суток мой Господин")  
            break
        else:
            speak("Не вели казнить! Я не знаю такую команду")
            break

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2021-07-06
@GRIMSHOT

if voice in cmdList['hello']:
    speak("Доброго времени суток мой Господин")  
else:
    speak("Не вели казнить! Я не знаю такую команду")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question