I am making a speech recognition program in python where I want that when I say “above”, it will continuously run the loop to press the down key until I again don’t say above, but now after I included threading to make the speech recognizer run continuously, the whole main loop is not recognizing the res
from speech import *
import queue
import threading
import pyautogui
import keyboard
import time
import sys
def speech_func(res_queue):
while True:
res = speech()
res_queue.put(res)
res_queue = queue.Queue()
prc=threading.Thread(target=speech_func, args=(res_queue,))
prc.start()
flower_active=False
while True:
res = res_queue.get()
if "above" in res:
flower_active = not flower_active
while flower_active:
keyboard.press_and_release('down')
time.sleep(0.1)
if "after" in res:
pyautogui.moveTo(1010,130)
pyautogui.click()
if "before" in res:
pyautogui.moveTo(890,130)
pyautogui.click()
if "music" in res:
pyautogui.moveTo(1680,130)
pyautogui.click()
if "below" in res:
keyboard.press_and_release('pageup')
if "ending" in res:
prc.join()
sys.exit(0)
If I remove the threading everything works fine except the down arrow which when i say “above” will start running the loop but won’t stop even if I say “above” again
Piyush Mandal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.