-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathL2T-SegmentationTextGrid.praat
More file actions
417 lines (403 loc) · 16.8 KB
/
Copy pathL2T-SegmentationTextGrid.praat
File metadata and controls
417 lines (403 loc) · 16.8 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
procedure segmentation_textgrid_tiers: .activity$
# String constants for the tiers of a Segmentation TextGrid (1-5) and the
# tiers of a Checked Segmentation TextGrid (1-9)
.trial = 1
.trial$ = "Trial"
.word = 2
.word$ = "Word"
.context = 3
.context$ = "Context"
.repetition = 4
.repetition$ = "Repetition"
.segm_notes = 5
.segm_notes$ = "SegmNotes"
.check_trial = 6
.check_trial$ = "CheckedTrial"
.check_word = 7
.check_word$ = "CheckedWord"
.check_context = 8
.check_context$ = "CheckedContext"
.check_repetition = 9
.check_repetition$ = "CheckedRepetition"
.check_notes = 10
.check_notes$ = "CheckedNotes"
.to_review = 11
.to_review$ = "ToReview"
# Gather the string constants into a vector---which string constants are
# gathered depends on the [.activity$].
@praat_activities
if .activity$ == "Segment a recording"
.slot1$ = .trial$
.slot2$ = .word$
.slot3$ = .context$
.slot4$ = .repetition$
.slot5$ = .segm_notes$
.length = 5
# A few other string constants that facilitate creating a new
# Segmentation TextGrid.
.all_tiers$ = .slot1$
for i from 2 to .length
.all_tiers$ = .all_tiers$ + " " + .slot'i'$
endfor
.point_tiers$ = .segm_notes$
elif .activity$ == "Check a segmented TextGrid"
.slot1$ = .trial$
.slot2$ = .word$
.slot3$ = .context$
.slot4$ = .repetition$
.slot5$ = .segm_notes$
.slot6$ = .check_trial$
.slot7$ = .check_word$
.slot8$ = .check_context$
.slot9$ = .check_repetition$
.slot10$ = .check_notes$
.slot11$ = .to_review$
.length = 11
# A few other string constants that facilitate creating a new
# Segmentation TextGrid.
.all_tiers$ = .slot1$
for i from 2 to .length
.all_tiers$ = .all_tiers$ + " " + .slot'i'$
endfor
.point_tiers$ = .segm_notes$ + " " + .check_notes$ + " " + .to_review$
elif .activity$ == "Transcribe a recording"
# Numeric and string constants for the Segmented TextGrid.
.trial = 1
.trial$ = "Trial"
.word = 2
.word$ = "Word"
.context = 3
.context$ = "Context"
.repetition = 4
.repetition$ = "Repetition"
.segmnotes = 5
.segmnotes$ = "SegmNotes"
endif
endproc
procedure segmentation_textgrid_error: .directory$
... .participant_number$
printline
printline
printline <<<>>> <<<>>> <<<>>> <<<>>> <<<>>> <<<>>> <<<>>> <<<>>> <<<>>>
printline
printline ERROR :: No Segmentation TextGrid was loaded
printline
printline Make sure the following directory exists on your computer:
printline '.directory$'
printline
printline Also, make sure that directory contains a Segmentation TextGrid
... for participant '.participant_number$'.
printline
printline <<<>>> <<<>>> <<<>>> <<<>>> <<<>>> <<<>>> <<<>>> <<<>>> <<<>>>
printline
printline
endproc
procedure initialize_segmentation_textgrid
@participant: segmentation_log.write_to$,
... session_parameters.participant_number$
select 'audio.praat_obj$'
To TextGrid... "'segmentation_textgrid_tiers.all_tiers$'"
... 'segmentation_textgrid_tiers.point_tiers$'
Rename... 'participant.id$'_Segm'session_parameters.initials$'
.praat_obj$ = selected$()
endproc
procedure segmentation_log_is
.activity$ = session_parameters.activity$
@praat_activities
if .activity$ == "Segment a recording"
.ready = 1
elif .activity$ == "Check a segmented TextGrid"
# Check whether the Segmentation Log exists on the Praat Objects list.
.on_objects_list = segmentation_log.praat_obj$ <> ""
# Check whether the Segmentation Log has unchecked trials.
select 'segmentation_log.praat_obj$'
.n_trials = Get value... 'segmentation_log.row_on_segmentation_log'
... 'segmentation_log_columns.trials$'
.n_checked = Get value... 'segmentation_log.row_on_segmentation_log'
... 'segmentation_log_columns.segmented_trials$'
.has_unchecked_trials = .n_checked < .n_trials
# Determine whether the Segmentation Log is [.ready] for the Segmentation
# TextGrid to be loaded.
.ready = .on_objects_list * .has_unchecked_trials
endif
endproc
procedure prepare_segmented_textgrid: .praat_obj$
select '.praat_obj$'
.n_tiers = Get number of tiers
.ready_to_check = 0
if .n_tiers < 11
if .n_tiers == 5
@segmentation_textgrid_tiers: session_parameters.activity$
select '.praat_obj$'
## PFR: Added calls to [Insert interval tier] so that CheckedTrial and
## CheckedWord tiers would be added to the original segmentation tiers
## when it is first being checked.
Insert interval tier: segmentation_textgrid_tiers.check_trial,
... segmentation_textgrid_tiers.check_trial$
Insert interval tier: segmentation_textgrid_tiers.check_word,
... segmentation_textgrid_tiers.check_word$
## /PFR 2014-08-01
Insert interval tier: segmentation_textgrid_tiers.check_context,
... segmentation_textgrid_tiers.check_context$
Insert interval tier: segmentation_textgrid_tiers.check_repetition,
... segmentation_textgrid_tiers.check_repetition$
Insert point tier: segmentation_textgrid_tiers.check_notes,
... segmentation_textgrid_tiers.check_notes$
Insert point tier: segmentation_textgrid_tiers.to_review,
... segmentation_textgrid_tiers.to_review$
.ready_to_check = 1
else
printline The Segmented TextGrid has a wrong number of tiers.
printline It should have either 5 or 11 tiers, but it has '.n_tiers'.
printline Please fix the structure of the Segmented TextGrid and then
... rerun this script.
endif
elif .n_tiers == 11
# Then everything is good, so don't do anything.
.ready_to_check = 1
elif .n_tiers > 11
printline The Segmented TextGrid has a wrong number of tiers.
printline It should have either 5 or 11 tiers, but it has '.n_tiers'. printline Please fix the structure of the Segmented TextGrid and then
... rerun this script.
endif
endproc
procedure segmentation_textgrid
# Import constants from the [session_parameters] namespace.
.initials$ = session_parameters.initials$
.workstation$ = session_parameters.workstation$
.experimental_task$ = session_parameters.experimental_task$
.testwave$ = session_parameters.testwave$
.participant_number$ = session_parameters.participant_number$
.activity$ = session_parameters.activity$
.experiment_directory$ = session_parameters.experiment_directory$
# Set up the [segmentation_textgrid_tiers] namespace.
@segmentation_textgrid_tiers: .activity$
# The behavior of the procedure depends primarily on the [.activity$].
@praat_activities
if .activity$ == "Segment a recording"
# Set up the path to the segmenter's working [.directory$].
.directory$ = .experiment_directory$ + "/" +
... "Segmentation" + "/" +
... "Segmenters" + "/" +
... .initials$ + "/" +
... "TextGrids"
# Parse the full [participant.id$] from the path of the Segmentation Log
@participant: segmentation_log.write_to$,
... session_parameters.participant_number$
# If the Segmentation Log was created at run time---i.e., not [.read_from$]
# the filesystem, then the TextGrid needs to be created at run time as well.
if segmentation_log.read_from$ == ""
prinline Creating a blank Segmentation TextGrid
# Create a blank Segmentation TextGrid.
@initialize_segmentation_textgrid
# Set up the [.read_from$], [.write_to$] and [.praat_obj$] strings.
.read_from$ = ""
.write_to$ = .directory$ + "/" +
... .experimental_task$ + "_" +
... participant.id$ + "_" +
... .initials$ + "segm.Textgrid"
.praat_obj$ = initialize_segmentation_textgrid.praat_obj$
else
.pattern$ = .directory$ + "/" +
... .experimental_task$ + "_" +
... .participant_number$ + "*" +
... .initials$ + "segm.TextGrid"
# Use the [.pattern$] to determine the filename of the Segmentation
# TextGrid.
@filename_from_pattern: .pattern$, "Segmentation TextGrid"
if filename_from_pattern.filename$ <> ""
.read_from$ = .directory$ + "/" + filename_from_pattern.filename$
.write_to$ = .directory$ + "/" + filename_from_pattern.filename$
printline Loading Segmentation TextGrid
... 'filename_from_pattern.filename$' from '.directory$'
Read from file... '.read_from$'
Rename... 'participant.id$'_Segm'.initials$'
.praat_obj$ = selected$()
else
.read_from$ = ""
.write_to$ = ""
.praat_obj$ = ""
endif
endif
# When checking a Segmented TextGrid...
elif .activity$ == "Check a segmented TextGrid"
# Only load a Segmentation TextGrid if the [segmentation_log_is] [.ready]
@segmentation_log_is
if segmentation_log_is.ready
# Get the intials of the segmenter who segmented the TextGrid.
@segmenters_initials: segmentation_log.read_from$
.segmenters_initials$ = segmenters_initials.initials$
# Get the [checking_initials] as well.
@checking_initials: segmentation_log.read_from$, .initials$
.checking_initials$ = checking_initials.initials$
# Use the segmenter's initials, among other pieces of information, to
# set up the path to that segmenter's working [.directory$]
.directory$ = .experiment_directory$ + "/" +
... "Segmentation" + "/" +
... "Segmenters" + "/" +
... .segmenters_initials$ + "/" +
... "TextGrids"
# The [.pattern$] used to search for a Segmented TextGrid depends on
# whether the user is continuing a previous session or if this is her
# first session checking these segmentations.
if ! segmentation_log.continuing_previous_session
.pattern$ = .directory$ + "/" +
... .experimental_task$ + "_" +
... .participant_number$ + "*" +
... .segmenters_initials$ + "segm.TextGrid"
else
.pattern$ = .directory$ + "/" +
... .experimental_task$ + "_" +
... .participant_number$ + "*" +
... .checking_initials$ + "segm.TextGrid"
endif
# Use the [.pattern$] to determine the filename of the Segmentation
# TextGrid.
@filename_from_pattern: .pattern$, "Segmented TextGrid"
if filename_from_pattern.filename$ <> ""
# Use the [.filename$] to set up the [.read_from$] and [.write_to$]
# paths.
.read_from$ = .directory$ + "/" + filename_from_pattern.filename$
if ! segmentation_log.continuing_previous_session
.write_to$ = replace$(.read_from$, "'.segmenters_initials$'segm",
... "'.checking_initials$'segm", 1)
else
.write_to$ = .read_from$
endif
# Use the [.read_from$] path to determine the [participant]'s [.id$].
@participant: .read_from$, .participant_number$
# Read in the Segmented TextGrid.
printline Loading Segmented TextGrid 'filename_from_pattern.filename$'
... from '.directory$'
Read from file... '.read_from$'
# Rename the Segmented TextGrid, and store this object's name.
Rename... 'participant.id$'_Segm'.checking_initials$'
.praat_obj$ = selected$()
# Prepare the Segmented TextGrid to be checked by optionally adding
# the 4 tiers for checking.
printline Preparing '.praat_obj$' to be checked
@prepare_segmented_textgrid: .praat_obj$
if prepare_segmented_textgrid.ready_to_check
select '.praat_obj$'
Save as text file... '.write_to$'
else
.praat_obj$ = ""
endif
else # no [.filename$] was found from the [.pattern$]
# If no [.filename$] was found, then set the [.read_from$] and
# [.write_to$] paths to empty strings.
.read_from$ = ""
.write_to$ = ""
# Set the name of the [.praat_obj$] to an empty string as well.
.praat_obj$ = ""
endif
else # the [segmentation_log_is] not [.ready]
endif
# When tagging turbulence events or adding place-transcription to turbulence tags...
elif (.activity$ == "Tag turbulence events" | .activity$ == "Add place-transcription to RWR TP1 turbulence tags")
# Set up the path to the [.directory$] of checked segmented TextGrids.
.directory$ = .experiment_directory$ + "/" +
... "TurbulenceTagging" + "/" +
... "SegmentedTextGrids"
# Set up the string [.pattern$] used to find a checked segmented TextGrid.
.pattern$ = .directory$ + "/" +
... .experimental_task$ + "_" +
... .participant_number$ + "*" + "segm.TextGrid"
# Search for a checked segmented TextGrid using the [.pattern$]
@filename_from_pattern: .pattern$, "Segmented TextGrid"
if filename_from_pattern.filename$ <> ""
# Use the [.directory$] and [.filename$] strings to set up the path
# from which the checked segmented TextGrid is [.read_from$].
.read_from$ = .directory$ + "/" + filename_from_pattern.filename$
# Use the [.read_from$] path to determine the [participant]'s [.id$].
@participant: .read_from$, .participant_number$
# Parse the checker's [.initials$] from the path that the TextGrid was
# [.read_from$].
.checkers_initials$ = mid$(.read_from$, rindex(.read_from$, "_") + 1, 2)
# The [.write_to$] path is an empty string because any modifications to
# the checked segmented TextGrid that are made during turbulence tagging
# should be considered accidental and should not be saved.
.write_to$ = ""
# Read in the checked segmented TextGrid
printline Loading Checked Segmented TextGrid
... 'filename_from_pattern.filename$' from '.directory$'
Read from file... '.read_from$'
Rename... 'participant.id$'_CheckedSegm'.checkers_initials$'
.praat_obj$ = selected$()
else
# Set all string constants to empty strings.
.read_from$ = ""
.write_to$ = ""
.praat_obj$ = ""
# Print an error message.
@segmentation_textgrid_error: .directory$, .participant_number$
endif
# When tagging burst events...
elif .activity$ == "Tag burst events"
# Set up the path to the [.directory$] of checked segmented TextGrids.
.directory$ = .experiment_directory$ + "/" +
... "BurstTagging" + "/" +
... "SegmentedTextGrids"
# Set up the string [.pattern$] used to find a checked segmented TextGrid.
.pattern$ = .directory$ + "/" +
... .experimental_task$ + "_" +
... .participant_number$ + "*" + "segm.TextGrid"
# Search for a checked segmented TextGrid using the [.pattern$]
@filename_from_pattern: .pattern$, "Segmented TextGrid"
if filename_from_pattern.filename$ <> ""
# Use the [.directory$] and [.filename$] strings to set up the path
# from which the checked segmented TextGrid is [.read_from$].
.read_from$ = .directory$ + "/" + filename_from_pattern.filename$
# Use the [.read_from$] path to determine the [participant]'s [.id$].
@participant: .read_from$, .participant_number$
# Parse the checker's [.initials$] from the path that the TextGrid was
# [.read_from$].
.checkers_initials$ = mid$(.read_from$, rindex(.read_from$, "_") + 1, 2)
# The [.write_to$] path is an empty string because any modifications to
# the checked segmented TextGrid that are made during turbulence tagging
# should be considered accidental and should not be saved.
.write_to$ = ""
# Read in the checked segmented TextGrid
printline Loading Checked Segmented TextGrid
... 'filename_from_pattern.filename$' from '.directory$'
Read from file... '.read_from$'
Rename... 'participant.id$'_CheckedSegm'.checkers_initials$'
.praat_obj$ = selected$()
else
# Set all string constants to empty strings.
.read_from$ = ""
.write_to$ = ""
.praat_obj$ = ""
# Print an error message.
@segmentation_textgrid_error: .directory$, .participant_number$
endif
elif (.activity$ == "Transcribe a recording" | .activity$ == "Other")
# Set up the path to the [.directory$] of segmented TextGrids.
.directory$ = .experiment_directory$ + "/Segmentation/TextGrids"
.pattern$ = .directory$ + "/" +
... .experimental_task$ + "_" +
... .participant_number$ + "*" + "segm.TextGrid"
# Search for a checked segmented TextGrid using the [.pattern$]
@filename_from_pattern: .pattern$, "Segmented TextGrid"
if filename_from_pattern.filename$ <> ""
.read_from$ = .directory$ + "/" + filename_from_pattern.filename$
printline Loading Segmented TextGrid 'filename_from_pattern.filename$'
... from '.directory$'
Read from file... '.read_from$'
.praat_obj$ = selected$()
@textgrid2table: .praat_obj$
.tablePraat_obj$ = selected$()
# The [.write_to$] path is an empty string because any modifications to
# the checked segmented TextGrid that are made during transcription
# should be considered accidental and should not be saved.
.write_to$ = ""
else
# Set all string constants to empty strings.
.read_from$ = ""
.write_to$ = ""
.praat_obj$ = ""
# Print an error message.
@segmentation_textgrid_error: .directory$, .participant_number$
endif
endif
endproc