-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultithread.py
86 lines (74 loc) · 2.36 KB
/
multithread.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import speech_recognition as sr
import pyautogui
import concurrent.futures
import time
EXIT_STATUS = False
PLAY_STATUS= False
PREVIOUS_STATUS = False
FORWARD_SPEED = 2
NEXT_STATUS = False
DELETE_STATUS = False
def def_thread():
global PLAY_STATUS,PREVIOUS_STATUS,EXIT_STATUS,FORWARD_SPEED,NEXT_STATUS,DELETE_STATUS
while not EXIT_STATUS:
if PLAY_STATUS:
pyautogui.press('right')
print('r')
time.sleep(FORWARD_SPEED)
elif DELETE_STATUS:
pyautogui.press('delete')
pyautogui.press('tab')
pyautogui.press('enter')
DELETE_STATUS = False
PLAY_STATUS = True
elif NEXT_STATUS:
pyautogui.press('right')
NEXT_STATUS = False
elif PREVIOUS_STATUS:
pyautogui.press('left')
PREVIOUS_STATUS = False
print("Exited Default Thread")
def voice_thread():
r2 = sr.Recognizer()
r3 = sr.Recognizer()
global EXIT_STATUS,PREVIOUS_STATUS,PLAY_STATUS,FORWARD_SPEED,NEXT_STATUS,DELETE_STATUS
while True:
with sr.Microphone() as source:
try:
r3.adjust_for_ambient_noise(source)
audio = r3.listen(source,timeout = 5)
text = r2.recognize_google(audio)
print(text)
except Exception as e:
print("Exception occured")
print(e)
continue
if 'exit' in text:
EXIT_STATUS = True
break
elif 'next' in text:
NEXT_STATUS = True
PLAY_STATUS = False
elif 'previous' in text or 'left' in text:
PREVIOUS_STATUS= True
elif 'pause' in text:
PLAY_STATUS = False
elif 'play' in text or 'start' in text:
PLAY_STATUS = True
elif 'slow' in text:
FORWARD_SPEED+=0.5
elif 'fast' in text:
FORWARD_SPEED-=0.5
if FORWARD_SPEED <=1:
FORWARD_SPEED=1
elif 'delete' in text:
PLAY_STATUS = False
DELETE_STATUS = True
else:
continue
print("Exited Voice Thread")
if __name__ == '__main__':
with concurrent.futures.ThreadPoolExecutor() as executor:
f1 = executor.submit(def_thread)
f2 = executor.submit(voice_thread)
print("Exited Program Successfullyy")