-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio_jarvis.py
58 lines (43 loc) · 1.17 KB
/
audio_jarvis.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
import speech_recognition as sr
import time
import pyautogui as pag
r = sr.Recognizer()
keywords = [("copy", 1), ("print", 1), ("snap",1), ("select all",1) ]
source = sr.Microphone(device_index=1)
def callback(recognizer, audio):
try:
speech = recognizer.recognize_sphinx(audio, keyword_entries=keywords)
if "copy" in speech:
copy()
elif "paste" in speech:
paste()
elif "snap" in speech:
snap()
elif "select all" in speech:
select_all()
except sr.UnknownValueError:
print("Oops! Didn't catch that")
def copy():
print("copying")
pag.keyDown("ctrl")
pag.press("c")
pag.keyUp("ctrl")
def paste():
print("pasting")
pag.keyDown("ctrl")
pag.press("v")
pag.keyUp("ctrl")
def snap():
print("cutting")
pag.keyDown("ctrl")
pag.press("x")
pag.keyUp("ctrl")
def select_all():
print("selcting all")
pag.keyDown("ctrl")
pag.press("a")
pag.keyUp("ctrl")
def start_recognizer():
r.listen_in_background(source, callback)
time.sleep(1000000)
start_recognizer()