I am using PocketSphinx speech-to-text engine to perform a certain task (I don't think is important to add).
I want it to react when I say certain words (which it does), however, I want to create a sort of "safety loop" where I put the program into a loop that it can only get out of when I say a certain other word, just in case it accidentally picks up me saying the initial word and performing the action when I don't want it to. Though, I am having trouble with my loop. The loop is at the end of the function, but it is a recurring function, so the function will continuously be called until I physically turn it off.
def listen(): #Definition of listen() function.
wait = 0
print ("Listening!")
for word in speech:
word_string = str(word)
if (word_string == "START"): #Listens for the word "Start."
print("Primary Function Executed.")
if (word_string == "REST"): #Listens for the word "Rest."
print ("In loop")
wait = 1
while (wait == 1): #Safety loop.
for cap in speech:
cap_string = str(cap)
if (cap_string == "OKAY"):
listen()
So, I have tried this loop (the last 8 lines) without reassigning the variable "wait" to the value "1". However, then it just ignores the loop and I can say "Start" or "rest" and it will perform both functions whenever the words are said, which I don't want. I want to say "rest" to get into the loop, then "okay" to get out of it, but when I say "rest", I get another window (this is visual studios 2019 btw) that is called Break Mode, and it says
"No compatible code running. The selected debug engine does not support any code executing on the current thread (e.g. only native runtime code is executing)."
And there is another window that is titled "Exception Unhandled", which reads,
"Ad___enter__returned-1".
I know that the problem is the loop because if I ignore the loop, it runs smoothly, and it also prints "In loop", so I know that the "if" statement runs fine as well.