-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrec_transpose_func.py
More file actions
67 lines (55 loc) · 1.5 KB
/
rec_transpose_func.py
File metadata and controls
67 lines (55 loc) · 1.5 KB
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
import sounddevice as sd
import numpy as np
import time
M = 15
global x, y
x = np.zeros((M, 1))
y = 0
def myFiltrar (data):
global x,y
x[0] = data
y = y + x[0] * 1
y = y * (1 / float(M))
return np.transpose(y)
def sumar ():
global x,y
for k in range(1, M):
y = y + x[k] * 1
y = y * (1 / float(M))
for k in range(M - 1, -1, -1):
x[k] = x[k - 1]
fs = 44100
duration = 5 # seconds
myrecording = sd.rec(duration * fs, samplerate=fs, channels=1, dtype='float32')
print "Recording Audio"
sd.wait()
print "Audio recording complete, play audio"
sd.play(myrecording, fs)
sd.wait()
print "Played audio complete"
np.savetxt('data.csv', (myrecording), delimiter=',')
# noisy Gaussian
mu, sigma = 0, 0.1 # mean and standard deviation
s = np.random.normal(mu, sigma, len(myrecording))
s = np.array(([s,]))
s = s.transpose()
# apply Noisy Gaussian
myrecording = myrecording + s
print "Play audio with noise"
sd.play(myrecording, fs)
sd.wait()
print "Played with noise audio complete"
np.savetxt('data2.csv', (myrecording), delimiter=',')
#Applying Filter moving average
Y = np.zeros(np.size(myrecording), dtype='float32')
start = time.time() #Measure time of computing
for j in range(0, np.size(myrecording, 0)):
Y[j] = myFiltrar(myrecording[j])
sumar()
end = time.time()
elapsed = end - start
print(elapsed)
print "Play Audio without Noise"
sd.play(Y, fs)
sd.wait()
print "Play without Noise Audio Complete"