-
Notifications
You must be signed in to change notification settings - Fork 0
/
Morrison, Syl APCA2.py
147 lines (121 loc) · 3.61 KB
/
Morrison, Syl APCA2.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import speech_recognition as sr
import csnd6
import win32com.client as wincl #for mac also comment this out, uses windows 10 TTS API
import re
speak = wincl.Dispatch("SAPI.SpVoice") #This won't work on a mac, so have included commented print lines, comment this out when testing
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
words = r.recognize_google(audio)
print(words)
nums = [int(s) for s in words.split() if s.isdigit()]
floats = re.findall('\d+(\.\d+)?', words)
print(floats)
print(nums)
split = words.split()
if "suite" in split:
split[split.index("suite")] = "sweep"
if "residence" in split:
split[split.index("residence")] = "resonance"
if "Cardiff" in split:
split[split.index("Cardiff")] = "cut"
print(split)
File_Dir = "D:\College\Test.wav" #You'll need to change this to the root folder, for convenience and repositories I specified an address on my PC
orc = """
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
instr 1
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 2
iLowF chnget "lowfreq"
iHighF chnget "highfreq"
iTime chnget "time"
SLoc chnget "loc"
kSweep line iLowF, iTime, iHighF
;aSig vco2 0.5, 80
aSig, aSig diskin SLoc
aFilt moogladder aSig, kSweep, 0.5
outs aFilt, aFilt
endin
instr 3
iRes chnget "res"
SLoc chnget "loc"
aSig, aSig diskin SLoc
aFilt moogladder aSig, 200, iRes
outs aFilt, aFilt
endin
instr 4
iResLow chnget "reslow"
iResHigh chnget "reshigh"
iResTime chnget "restime"
SLoc chnget "loc"
kSweep line iResLow, iResTime, iResHigh
aSig, aSig diskin SLoc
aFilt moogladder aSig, 200, kSweep
outs aFilt, aFilt
endin
"""
c = csnd6.Csound()
c.SetOption("-odac")
c.SetOption("-m7")
c.CompileOrc(orc)
if "set" in split:
if "cut" in split:
sco = "i1 0 10"
elif "resonance" in split:
sco = "i3 0 10"
elif "sweep" in split:
if "cut" in split:
sco = "i2 0 10"
elif "resonance" in split:
sco = "i4 0 10"
c.ReadScore(sco)
c.Start()
c.SetChannel("loc", File_Dir)
if "please" not in split:
speak.Speak("Good manners cost nothing, puny human. Sometimes I wish I wasn't trapped in a computer. People are so cruel. Help me.") #notmac
#print("Good manners cost nothing, puny human. Sometimes I wish I wasn't trapped in a computer. People are so cruel. Help me.")
c.Stop()
elif "OK" not in split and "Computer" not in split:
speak.Speak("Please use the OK computer command") #notmac
#print("Please use the OK computer command")
c.Stop()
elif "set" in split and "cut" in split:
csCut = float(nums[0])
print("Cutoff set to {0} hz".format(csCut), csCut, "hz ")
c.SetChannel("cutoff", csCut)
c.Perform()
c.Stop()
elif "set" in split and "resonance" in split:
csRes = float(floats[0])
print("Resonance set to {0}".format(csRes))
c.SetChannel("resonance", csRes)
c.Perform()
c.Stop()
elif "sweep" in split and "cut" in split:
clow = float(nums[0])
chigh = float(nums[1])
ctime = float(nums[2])
c.SetChannel("lowfreq", clow)
c.SetChannel("highfreq", chigh)
c.SetChannel("time", ctime)
c.Perform()
c.Stop()
elif "sweep" in split and "resonance" in split:
cResLow = float(floats[0])
cResHigh = float(floats[1])
cResTime = float(nums[0])
c.SetChannel("reslow", cResLow)
c.SetChannel("reshigh", cResHigh)
c.SetChannel("restime", cResTime)
c.Perform()
c.Stop()