-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvoicher.py
99 lines (64 loc) · 1.52 KB
/
voicher.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
import soundfile as sf
import sounddevice as sd
import matplotlib.pyplot as plt
import os
import numpy as np
def readEditWritePlayWav():
data, samplerate = sf.read("in.wav")
print data.shape
print samplerate
plt.plot(data)
plt.show()
samplerate = int(samplerate * 1.5)
sf.write("out.wav", data, samplerate)
os.system("afplay out.wav")
def recordEditPlay1():
fs = 44100
sd.default.samplerate = fs
sd.default.channels = 2
print "start recording..."
duration = 5 # seconds
myRec = sd.rec(duration * fs)
sd.wait() # wait until finish recording
print "start playing..."
sd.play(myRec)
sd.wait() # wait until finish playing
print "start recording while playing..."
myRec2 = sd.playrec(myRec)
sd.wait()
print "start playing mix..."
sd.play(myRec2)
sd.wait()
def recordEditPlay2():
fs = 44100
sd.default.samplerate = fs
sd.default.channels = 2
print "start recording..."
duration = 10 # seconds
myRec = sd.rec(duration * fs)
sd.wait()
print "start playing..."
sd.play(myRec, int(fs * 1.5))
sd.wait()
# for i, one in enumerate(data):
# one[0] *= 2
# one[1] *= 2
def PSOLA():
data, samplerate = sf.read("in.wav")
print data.shape
print samplerate
newData = np.zeros((data.shape[0] * 2, data.shape[1]))
j = 0
for i in range(data.shape[0]):
newData[j] = data[i]
newData[j+1] = data[i]
j += 2
# sd.play(data, samplerate)
# sd.wait()
sd.play(newData, samplerate * 2)
sd.wait()
if __name__ == "__main__":
# readEditWritePlayWav()
# recordEditPlay1()
# recordEditPlay2()
PSOLA()