-
Notifications
You must be signed in to change notification settings - Fork 0
/
Speech Recognition Filter - Class Implementation.py
112 lines (97 loc) · 3.5 KB
/
Speech Recognition Filter - Class Implementation.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#OOP Speech Rec
import speech_recognition as sr
import re
from Tkinter import *
import csnd6
import win32com.client as wincl
class Application(Frame):
def speech_rec(self):
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
words = r.recognize_google(audio)
self.nums = [int(s) for s in words.split() if s.isdigit()]
self.floats = re.findall('\d+(\.\d+)?', words)
self.split = words.split()
self.generate_score()
def generate_score(self):
if "cut" in self.split:
self.sco = """i"set_cutoff" 0 [60*60*24*7]"""
self.c.ReadScore(self.sco)
elif "resonance" in self.split:
self.sco = """i"set_resonance" 0 [60*60*24*7]"""
self.c.ReadScore(self.sco)
self.send_events()
def send_events(self):
if "please" not in self.split:
self.speak.Speak("Good manners cost nothing, puny human")
self.c.Stop()
elif "OK" not in self.split and "Computer" not in self.split:
self.speak.Speak("Please use the OK computer command")
self.c.Stop()
elif "set" in self.split and "cut" in self.split:
csCut = float(self.nums[0])
print("Cutoff set to {0} hz".format(csCut), csCut, "hz ")
self.c.SetChannel("cutoff", csCut)
elif "set" in self.split and "resonance" in self.split:
csRes = float(self.floats[0])
print("Resonance set to {0}".format(csRes))
self.c.SetChannel("resonance", csRes)
#if button pressed then run speech_rec again
def create_widgets(self):
frame = Frame(master = root)
frame.pack()
self.speech_rec = Button(self)
self.speech_rec["text"] = "Speech"
self.speech_rec["command"] = self.speech_rec()
self.speech_rec.pack({"side":"left"})
self.exit = Button(self)
self.exit["text"] = "Stop"
self.exit["command"] = frame.quit
self.exit["fg"] = "red"
self.exit.pack({"side":"right"})
def __init__(self, master = None): #Constructor
Frame.__init__(self, master)
self.Pack()
self.create_widgets()
self.orc = """
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
instr set_cutoff
kFreq init 200
kFreq chnget "cutoff"
SLoc chnget "loc"
print 100
aSig vco2 0.5, 80
;aSig, aSig diskin SLoc
aFilt moogladder aSig, kFreq, 0.5
outs aFilt, aFilt
endin
instr set_resonance
iRes init 0.5
iRes chnget "res"
SLoc chnget "loc"
aSig vco2 0.5, 80
;aSig, aSig diskin SLoc
aFilt moogladder aSig, 200, iRes
outs aFilt, aFilt
endin
instr unused
prints "running"
endin
"""
File_Dir = "D:\College\Test.wav"
self.speak = wincl.Dispatch("SAPI.SpVoice")
self.c = csnd6.Csound()
self.c.SetOption("-odac")
self.c.SetOption("-m7")
self.c.CompileOrc(self.orc)
self.c.ReadScore("""i"unused" 0 [60*60*24*7]""")
self.c.Start()
self.c.SetChannel("SLoc", File_Dir)
self.c.Stop() #ideally on stop button press
root = Tk()
app = Application(root)
root.mainloop()