-
Notifications
You must be signed in to change notification settings - Fork 64
/
combo_sound_files.Praat
93 lines (86 loc) · 2.44 KB
/
combo_sound_files.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
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
# This Praat script will merge all the sound files in a selected
# directory and concatenates them into a single sound file.
#
#
# This script is distributed under the GNU General Public License.
# Copyright 2021.08.03 feelins[[email protected]]
form Concatenate sound files
comment Directory of input sound files
text Sound_directory input_data/
choice select_merge_option: 1
button merge whole directory
button merge specific filenames
word specific_marks specific_list.txt
endform
if select_merge_option = 2
if specific_marks$ = "" or not fileReadable(specific_marks$)
exit " Please set a valid specific mark File!!! "
endif
Read Strings from raw text file: specific_marks$
totalLines = Get number of strings
curName$ = selected$("Strings", 1)
for istring from 1 to totalLines
txt$[istring] = Get string: istring
endfor
#select Strings curName$
Remove
endif
Create Strings as directory list: "directoryList", sound_directory$ + "/*"
numberOfDirs = Get number of strings
for idir to numberOfDirs
select Strings directoryList
dirname$ = Get string: idir
Create Strings as file list: "fileList", sound_directory$ + "/" + dirname$ + "/*.wav"
numberOfFiles = Get number of strings
# first option
if select_merge_option = 1
for ifile to numberOfFiles
select Strings fileList
filename$ = Get string: ifile
Read from file: sound_directory$ + "/" + dirname$ + "/" + filename$
endfor
select all
minus Strings fileList
minus Strings directoryList
Concatenate
save_file$ = sound_directory$ + "/" + dirname$ + ".wav"
Save as WAV file: save_file$
select all
minus Strings fileList
minus Strings directoryList
Remove
endif
# second option
if select_merge_option = 2
for txtIndex from 1 to totalLines
curTxt$ = txt$[txtIndex]
findFiles = 0
for ifile to numberOfFiles
select Strings fileList
filename$ = Get string: ifile
if index(filename$, curTxt$) <> 0
Read from file: sound_directory$ + "/" + dirname$ + "/" + filename$
findFiles = findFiles + 1
endif
endfor
if findFiles > 0
select all
minus Strings fileList
minus Strings directoryList
Concatenate
save_file$ = sound_directory$ + "/" + dirname$ + "_" + curTxt$ + ".wav"
Save as WAV file: save_file$
endif
select all
minus Strings fileList
minus Strings directoryList
Remove
endfor
endif
select all
minus Strings directoryList
Remove
endfor
select Strings directoryList
Remove
exit Over!