-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreparingData.py
More file actions
66 lines (50 loc) · 2.15 KB
/
PreparingData.py
File metadata and controls
66 lines (50 loc) · 2.15 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
#### IMPORTS ####################
import sounddevice as sd
from scipy.io.wavfile import write
import time
def record_audio_and_save(save_path, n_times=50):
"""
This function will run `n_times` and everytime you press Enter you have to speak the wake word
Parameters
----------
n_times: int, default=50
The function will run n_times default is set to 50.
save_path: str
Where to save the wav file which is generated in every iteration.
"""
input("To start recording Wake Word press Enter: ")
for i in range(n_times):
fs = 44100
seconds = 2
myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=1)
sd.wait()
write(save_path + str(time.time()) + ".wav", fs, myrecording)
input(
f"Press to record next or two stop press ctrl + C ({i + 1}/{n_times}): ")
def record_background_sound(save_path, n_times=50):
"""
This function will run automatically `n_times` and record your background sounds so you can make some
keybaord typing sound and saying something gibberish.
Note: Keep in mind that you DON'T have to say the wake word this time.
Parameters
----------
n_times: int, default=50
The function will run n_times default is set to 50.
save_path: str
Where to save the wav file which is generated in every iteration.
Note: DON'T set it to the same directory where you have saved the wake word or it will overwrite the files.
"""
input("To start recording your background sounds press Enter: ")
for i in range(n_times):
fs = 44100
seconds = 2
myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=1)
sd.wait()
write(save_path + str(time.time()) + ".wav", fs, myrecording)
print(f"Currently on {i+1}/{n_times}")
# Step 1: Record yourself saying the Wake Word
# print("Recording the Wake Word:\n")
# record_audio_and_save("audio_data/", n_times=10)
# Step 2: Record your background sounds (Just let it run, it will automatically record)
# print("Recording the Background sounds:\n")
# record_background_sound("background_sound/", n_times=100)