Answer the question
In order to leave comments, you need to log in
How to stop speech recognition after the desired "phrase"?
I am making a voice assistant and I want that after a certain phrase, all commands will stop being executed until I say the same phrase. I made such a function, but if you REPEATEDly say the desired """phrase""", then nothing works. We need to do something with the second """for""". What needs to be changed? I can explain the code if needed.
def stop():
global text, tr
tr = 0
variants1 = ['остановись', 'так приостановись', 'игнорь щас', 'выключи распознавание', 'не слушай плиз']
for z in variants1:
if (z in text)&(tr == 0):
word = text
word = word.replace('остановись','')
word = word.replace('так приостановись','')
word = word.replace('игнорь щас','')
word = word.replace('выключи распознавание','')
word = word.replace('не слушай плиз','')
commands.clear()
commands.append(word)
variants2 = [word]
for v in variants2:
if (v in text)&(tr == 0):
commands.remove(word)
commands.extend(commands1)
tr = 1
text = ''
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question