-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacquisition.py
95 lines (88 loc) · 2.51 KB
/
acquisition.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
import asyncio
import sounddevice as sd
import numpy as np
import matplotlib.pyplot as plt
import acquisition as acq
#-------------------------------------------
# Sound Acquisition
#-------------------------------------------
data = {
"rate": 22050,
"duration": 3,
"channels": 1,
"rec": [],
"rec11k": [],
"filtered": [],
"framesMatrix": [],
"minIndex": 0,
"maxIndex": 0,
"smoothEnergy": [],
"simples": 0,
"startTime": 0,
"endTime": 0,
"length": 0,
"prefN": 0,
"currHamming": [],
"windowedHamming": [],
"tresholdEnergy": 0,
"size": 0,
"summary": 0,
"booleanFrameEnergy": [],
"whileData": []
}
class CommandRecorder(object):
def __init__(self, sampleRate = data["rate"], channels = data["channels"]):
self.sampleRate = sampleRate
self.channels = channels
async def record_sound(self, recDuration = data["duration"]):
samplesToRecord = int((recDuration) * self.sampleRate)
print('Recording sound!')
rec = sd.rec(samplesToRecord, samplerate=self.sampleRate,
channels=self.channels)
#sd.wait()
await asyncio.sleep(recDuration)
return rec[:, 0]
async def plot22k(self):
plt.figure()
t = np.arange(data["rate"] * data["duration"])
plt.plot(t, data["rec"])
plt.title("Input Speech [Sample Rate: 22050]")
plt.ylabel("Amplitude")
plt.xlabel("Sample")
plt.show()
async def plot11k(self):
plt.figure()
plt.plot(data["rec11k"])
plt.title("Input Speech [Sample Rate: 11025]")
plt.ylabel("Amplitude")
plt.xlabel("Sample")
plt.show()
async def convertToLowerFreq(self):
for i in range(len(data["rec"])):
if i % 2:
data["rec11k"].append(data["rec"][i])
async def reiniData():
acq.data = {
"rate": 22050,
"duration": 3,
"channels": 1,
"rec": [],
"rec11k": [],
"filtered": [],
"framesMatrix": [],
"minIndex": 0,
"maxIndex": 0,
"smoothEnergy": [],
"simples": 0,
"startTime": 0,
"endTime": 0,
"length": 0,
"prefN": 0,
"currHamming": [],
"windowedHamming": [],
"tresholdEnergy": 0,
"size": 0,
"summary": 0,
"booleanFrameEnergy": [],
"whileData": []
}