-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconvertwav_to_16khz.praat
56 lines (41 loc) · 1.56 KB
/
convertwav_to_16khz.praat
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
##change sampling rate of .wav to 16kHz
clearinfo
form directory_path
text directory
endform
@convertAllWav: directory$, 16000, 1
##call convertWav recersively
procedure convertAllWav: .directory$, .resampleRate, .nestDepth
.directory$['.nestDepth'] = .directory$
# convert wav files in current directory
@convertWav: .directory$['.nestDepth'], .resampleRate
#search inner directories
.listname$ = "dir" + .directory$['.nestDepth']
.strings['.nestDepth'] = Create Strings as directory list: .listname$, .directory$['.nestDepth']
.numDirectories['.nestDepth'] = Get number of strings
for .i['.nestDepth'] to .numDirectories['.nestDepth']
selectObject: .strings['.nestDepth']
.innerDirectoryName$ = Get string: .i['.nestDepth']
.curDirectory$ = .directory$['.nestDepth'] + "/" + .innerDirectoryName$
@convertAllWav: .curDirectory$, .resampleRate, .nestDepth + 1
endfor
.nestDepth -= 1
endproc
##resample .wav files in .directory$ by .resampleRate
procedure convertWav: .directory$, .resampleRate
#make list object, which contains .wav file names
.listName$ = "wav" + .directory$
.strings = Create Strings as file list: .listName$, .directory$ + "/*.wav"
.numFiles = Get number of strings
for .i to .numFiles
selectObject: .strings
.fileName$ = Get string: .i
Read from file: .directory$ + "/" + .fileName$
#convert to monoral
do("Convert to mono")
#resample wav file
Resample: .resampleRate, 50
appendInfoLine: .directory$ + "/" + .fileName$
nowarn Save as WAV file: .directory$ + "/" + .fileName$
endfor
endproc