-
Notifications
You must be signed in to change notification settings - Fork 0
/
train.py
52 lines (40 loc) · 936 Bytes
/
train.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
import pyaudio
import wave
from dejavu import Dejavu
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 11000
RECORD_SECONDS = 4
config = {
"database": {
"host": "127.0.0.1",
"user": "root",
"passwd": "",
"db": "dejavu",
},
"database_type" : "mysql",
}
pR = pyaudio.PyAudio()
stream = pR.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
print("* recording")
framesR = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
dataR = stream.read(CHUNK)
framesR.append(dataR)
print("* done recording")
stream.stop_stream()
stream.close()
pR.terminate()
wf = wave.open("train/rec.wav", 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(pR.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(framesR))
wf.close()
djvR = Dejavu(config)
djvR.fingerprint_directory("train", [".wav"])