-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecord.py
168 lines (132 loc) · 3.6 KB
/
record.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
"""PyAudio example: Record a few seconds of audio and save to a WAVE file."""
import pyaudio
import wave
import os
import sys
def record_sound(filename):
CHUNK = 1024
# FORMAT = pyaudio.paInt16
FORMAT = pyaudio.paUInt8
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 3
WAVE_OUTPUT_FILENAME = filename
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
print("* recording")
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)
# print(int.from_bytes(frames[0],byteorder='little'))
stream.stop_stream()
stream.close()
p.terminate()
wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()
if __name__ == "__main__":
head = os.getcwd()
while True:
name = str(input("Name: "))
cmd = 'mkdir ' + name
os.system(cmd)
os.chdir(name + '/')
# Hello
print('Say: HELLO')
file1 = "hello_1.wav"
record_sound(file1)
print('Say: HELLO')
file1 = "hello_2.wav"
record_sound(file1)
print('Say: HELLO')
file1 = "hello_3.wav"
record_sound(file1)
# Bug
print('Say: BUG')
file2 = "bug_1.wav"
record_sound(file2)
print('Say: BUG')
file2 = "bug_2.wav"
record_sound(file2)
print('Say: BUG')
file2 = "bug_3.wav"
record_sound(file2)
# Cow
print('Say: COW')
file3 = "cow_1.wav"
record_sound(file3)
print('Say: COW')
file3 = "cow_2.wav"
record_sound(file3)
print('Say: COW')
file3 = "cow_3.wav"
record_sound(file3)
# Home
print('Say: HOME')
file4 = "home_1.wav"
record_sound(file4)
print('Say: HOME')
file4 = "home_1.wav"
record_sound(file4)
print('Say: HOME')
file4 = "home_1.wav"
record_sound(file4)
# Sure
print('Say: SURE')
file5 = "sure_1.wav"
record_sound(file5)
print('Say: SURE')
file5 = "sure_2.wav"
record_sound(file5)
print('Say: SURE')
file5 = "sure_3.wav"
record_sound(file5)
# Sun
print('Say: SUN')
file6 = "sun_1.wav"
record_sound(file6)
print('Say: SUN')
file6 = "sun_2.wav"
record_sound(file6)
print('Say: SUN')
file6 = "sun_3.wav"
record_sound(file6)
# Turkey
print('Say: Turkey')
file7 = "tukey_1.wav"
record_sound(file7)
print('Say: Turkey')
file7 = "tukey_2.wav"
record_sound(file7)
print('Say: Turkey')
file7 = "tukey_3.wav"
record_sound(file7)
# Pumpkin
print('Say: PUMPKIN')
file8 = "pumpkin_1.wav"
record_sound(file8)
print('Say: PUMPKIN')
file8 = "pumpkin_2.wav"
record_sound(file8)
print('Say: PUMPKIN')
file8 = "pumpkin_3.wav"
record_sound(file8)
# Maple
print('Say: MAPLE')
file9 = "maple_1.wav"
record_sound(file9)
print('Say: MAPLE')
file9 = "maple_2.wav"
record_sound(file9)
print('Say: MAPLE')
file9 = "maple_3.wav"
record_sound(file9)
os.chdir(head)