-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathReorganize in order-step1.praat
executable file
·105 lines (90 loc) · 2.65 KB
/
Reorganize in order-step1.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
94
95
96
97
98
99
100
101
102
103
104
105
# Reorganize files in order: Step 1 (or can be used independently)
# From original recording & annotation to individual ones
# Textgrid compulsory, sound files optional
# Textgrids are 'exploded', sub-tiers are maintained
# No silence interval added
# By Katrina Kechun Li (2020.7.19)
# Update on 2021.9.27: Now check the content of "temp" directory first, and if not empty, it will ask you to delete the files in the folder first.
form Explode TextGrid...
integer Tier 1
boolean Preserve_times 0
endform
# Change the directory here:
# dir$ = ""
###################
# Specify the path that you want to save the exploded individual files
dir$ = ""
###################
sound = numberOfSelected("Sound")
if sound
sound = selected("Sound")
endif
textgrid = selected("TextGrid")
# Check if the diretory is empty, and if not, exit the script
strings = Create Strings as file list: "list", dir$ + "/*.TextGrid"
num_of_strings = Get number of strings
if num_of_strings > 0
exitScript: "Delete all the files in the folder first"
endif
selectObject: textgrid
interval = Is interval tier: tier
if !interval
exit Not an interval tier
endif
intervals = Get number of intervals: tier
n = 0
for i to intervals
selectObject: textgrid
start = Get start point: tier, i
end = Get end point: tier, i
label$ = Get label of interval: tier, i
if label$ <> "" and startsWith(label$,"$") = 0
n = n+1
textgrid[n] = Extract part: start, end, preserve_times
Rename: label$
if sound
selectObject: sound
sound[n] = Extract part: start, end, "rectangular", 1, preserve_times
Rename: label$
endif
endif
endfor
nocheck selectObject: undefined
for i from 1 to n
plusObject: textgrid[i]
plusObject: sound[i]
endfor
# Other non-recognised types will be saved with the type suffix
m = numberOfSelected()
writeInfoLine: "m=",tab$,m
# We need to generate all the filenames in the first step, with all files "selected". Once we select individual files, we can no longer refer back to the chunk.
for i from 1 to m
s'i' = selected('i')
s'i'$ = selected$('i')
appendInfo: s'i'$,newline$
endfor
appendInfo: newline$
for i from 1 to m
select s'i'
type$ = extractWord$(s'i'$,"")
name$ = extractWord$(s'i'$," ")
if type$ = "Sound"
filename$ = dir$+name$+".wav"
Save as WAV file: filename$
appendInfo: filename$, newline$
elsif type$ = "TextGrid"
filename$ = dir$+name$+".TextGrid"
Save as text file: filename$
appendInfo: filename$, newline$
else
filename$ = dir$+name$
Save as text file: filename$
appendInfo: filename$, newline$
endif
endfor
nocheck selectObject: undefined
for i from 1 to n
plusObject: textgrid[i]
plusObject: sound[i]
endfor
Remove