-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprocess_speech.py
69 lines (43 loc) · 1.3 KB
/
process_speech.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
import os
import soundfile as sf
import numpy as np
speech_path = "corpus/"
train_path = speech_path + "train/"
test_path = speech_path + "test/"
valid_path = speech_path + "valid/"
file_list_train = os.listdir(train_path)
for files in file_list_train:
full_path = train_path + files
speech,fs = sf.read(full_path)
crop_length = 96000
length = speech.shape[0]
if(length<crop_length):
zeros = np.zeros(crop_length-length)
speech = np.concatenate([speech,zeros])
else:
speech = speech[0:96000]
sf.write(full_path,speech,fs)
file_list_test = os.listdir(test_path)
for files in file_list_test:
full_path = test_path + files
speech,fs = sf.read(full_path)
crop_length = 96000
length = speech.shape[0]
if(length<crop_length):
zeros = np.zeros(crop_length-length)
speech = np.concatenate([speech,zeros])
else:
speech = speech[0:96000]
sf.write(full_path,speech,fs)
file_list_valid = os.listdir(valid_path)
for files in file_list_valid:
full_path = valid_path + files
speech,fs = sf.read(full_path)
crop_length = 96000
length = speech.shape[0]
if(length<crop_length):
zeros = np.zeros(crop_length-length)
speech = np.concatenate([speech,zeros])
else:
speech = speech[0:96000]
sf.write(full_path,speech,fs)