-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGFTAtranscription.praat
executable file
·438 lines (366 loc) · 16.4 KB
/
GFTAtranscription.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
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
#######################################################################
# Controls whether the @log_[...] procedures write to the InfoLines.
# debug_mode = 1
debug_mode = 0
continueTranscription = 1
include check_version.praat
include ../L2T-utilities/L2T-Utilities.praat
include ../L2T-Audio/L2T-Audio.praat
include ../L2T-StartupForm/L2T-StartupForm.praat
include ../L2T-WordList/L2T-WordList.praat
include ../L2T-SegmentationTextGrid/L2T-SegmentationTextGrid.praat
include ../L2T-Transcription/L2T-Transcription.praat
# Set the session parameters.
defaultExpTask = 3
defaultTestwave = 1
defaultActivity = 3
@session_parameters: defaultExpTask, defaultTestwave, defaultActivity
# Load the audio file
@audio
# Load the WordList.
@wordlist
# Load the checked segmented TextGrid.
@segmentation_textgrid
# Set the transcription-specific parameters.
@transcription_parameters
# Numeric and string constants for the Word List Table.
wordListBasename$ = wordlist.praat_obj$
wordListWorldBet$ = wordlist_columns.worldBet$
wordListTargetC1$ = wordlist_columns.targetC1$
wordListTargetC2$ = wordlist_columns.targetC2$
wordListTargetC3$ = wordlist_columns.targetC3$
wordListprosPos1$ = wordlist_columns.prosPos1$
wordListprosPos2$ = wordlist_columns.prosPos2$
wordListprosPos3$ = wordlist_columns.prosPos3$
#wordListprosPos3$ = startup_GFTA_wordlist.prosPos3$
# Column numbers from the segmented textgrid
segTextGridTrial = segmentation_textgrid_tiers.trial
segTextGridContext = segmentation_textgrid_tiers.context
# Count the trials of structure type
@count_GFTA_wordlist_structures(wordListBasename$)
nTrials = count_GFTA_wordlist_structures.nTrials
@participant: audio.read_from$, session_parameters.participant_number$
# Check whether the log and textgrid exist already
@transcription_log("check", session_parameters.experimental_task$, participant.id$, session_parameters.initials$, transcription_parameters.logDirectory$, nTrials, 0, 0)
@transcription_textgrid("check", session_parameters.experimental_task$, participant.id$, session_parameters.initials$, transcription_parameters.textGridDirectory$))
# Load or initialize the transcription log/textgrid iff
# the log/textgrid both exist already or both need to be created.
if transcription_log.exists == transcription_textgrid.exists
@transcription_log("load", session_parameters.experimental_task$, participant.id$, session_parameters.initials$, transcription_parameters.logDirectory$, nTrials, 0, 0)
@transcription_textgrid("load", session_parameters.experimental_task$, participant.id$, session_parameters.initials$, transcription_parameters.textGridDirectory$)
# Otherwise exit with an error message
else
log_part$ = "Log " + transcription_log.filename$
grid_part$ = "TextGrid " + transcription_textgrid.filename$
if transcription_log.exists
msg$ = "Initialization error: " + log_part$ + "was found, but " + grid_part$ + " was not."
else
msg$ = "Initialization error: " + grid_part$ + "was found, but " + log_part$ + " was not."
endif
exitScript: msg$
endif
# Export values to global namespace
segmentBasename$ = segmentation_textgrid.praat_obj$
segmentTableBasename$ = segmentation_textgrid.tablePraat_obj$
audioBasename$ = audio.praat_obj$
transBasename$ = transcription_textgrid.praat_obj$
transLogBasename$ = transcription_log.praat_obj$
# These are column names
transLogTrials$ = transcription_log.trials$
transLogTrialsTranscribed$ = transcription_log.trials_transcribed$
transLogEndTime$ = transcription_log.end$
transLogScore$ = transcription_log.score$
transLogTranscribeableTokens$ = transcription_log.transcribeable$
###############################################################################
# Code for Transcription #
###############################################################################
# Open an Edit window with the segmentation textgrid, so that the transcriber can examine
# the larger segmentation context to recoup from infelicitous segmenting of false starts
# and the like.
selectObject(segmentBasename$)
Edit
# Open a separate Editor window with the transcription textgrid object and audio file.
selectObject(transBasename$)
plusObject(audioBasename$)
Edit
# Set the Spectrogram settings, etc., here.
#Count remaining trials
## does this log file increment for each session? if so, this "1" should be changed to numRows
## in the log file.
@count_remaining_trials(transLogBasename$, 1)
n_trials = count_remaining_trials.n_trials
n_transcribed = count_remaining_trials.n_transcribed
n_remaining = count_remaining_trials.n_remaining
# If there are still trials to transcribe, ask the transcriber if she would like to transcribe them.
n_transcribed < n_trials
beginPause("Transcribe GFTA Trials")
comment("There are 'n_remaining' trials to transcribe.")
comment("Would you like to transcribe them?")
button = endPause("No", "Yes", 2, 1)
# If the user chooses no, skip the transcription loop and break out of this loop.
if button == 1
continueTranscription = 0
else
currentTrial = n_transcribed + 1
endif
selectObject(segmentTableBasename$)
Extract rows where column (text): "tier", "is equal to", "Trial"
Rename: "TierTimes"
# Loop through the trials of the current type
while (currentTrial <= n_trials & continueTranscription)
# Look up trial number in segmentation table. Compute trial midpoint from table.
select Table TierTimes
.table_obj$ = selected$ ()
@get_xbounds_from_table(.table_obj$, currentTrial)
trialXMid = get_xbounds_from_table.xmid
# Find bounds of the textgrid interval containing the trial midpoint
@get_xbounds_in_textgrid_interval(segmentBasename$, segTextGridTrial, trialXMid)
# Use the XMin and XMax of the current trial to extract that portion of the segmented
# TextGrid, preserving the times. The TextGrid Object that this operation creates will
# have the name:
# ::ExperimentalTask::_::ExperimentalID::_::SegmentersInitials::segm_part
selectObject(segmentBasename$)
Extract part: get_xbounds_in_textgrid_interval.xmin, get_xbounds_in_textgrid_interval.xmax, "yes"
# Convert the (extracted) TextGrid to a Table, which has the
# same name as the TextGrid from which it was created.
selectObject(segmentBasename$ + "_part")
Down to Table: "no", 6, "yes", "no"
selectObject(segmentBasename$ + "_part")
Remove
# Subset the 'segmentBasename$'_part Table to just the intervals on the Context Tier.
selectObject(segmentTableBasename$ + "_part")
Extract rows where column (text): "tier", "is equal to", "Context"
selectObject(segmentTableBasename$ + "_part")
Remove
# Count the number of segmented intervals.
selectObject(segmentTableBasename$ + "_part_Context")
numResponses = Get number of rows
# If there is more than one segmented interval, ...
if numResponses > 1
# Zoom to the entire trial in the segmentation TextGrid object and
# invite the transcriber to select the interval to transcribe.
editor 'segmentBasename$'
Zoom: get_xbounds_in_textgrid_interval.xmin, get_xbounds_in_textgrid_interval.xmax
endeditor
beginPause("Choose repetition number to transcribe")
choice("Repetition number", numResponses)
for repnum from 1 to 'numResponses'
option("'repnum'")
endfor
button = endPause("Back", "Quit", "Choose repetition number", 3)
else
repetition_number = 1
endif
# Get the Context label of the chosen segmented interval of this trial and also then
# mark it off in the transcription textgrid ready to transcribe or skip as a NonResponse.
selectObject(segmentTableBasename$ + "_part_Context")
contextLabel$ = Get value: repetition_number, "text"
# Determine the XMin and XMax of the segmented interval.
@get_xbounds_from_table(segmentTableBasename$ + "_part_Context", repetition_number)
segmentXMid = get_xbounds_from_table.xmid
@get_xbounds_in_textgrid_interval(segmentBasename$, segTextGridContext, segmentXMid)
segmentXMin = get_xbounds_in_textgrid_interval.xmin
segmentXMax = get_xbounds_in_textgrid_interval.xmax
# Add interval boundaries on each tier.
selectObject(transBasename$)
Insert boundary: transcription_textgrid.prosodicPos, segmentXMin
Insert boundary: transcription_textgrid.prosodicPos, segmentXMax
Insert boundary: transcription_textgrid.phonemic, segmentXMin
Insert boundary: transcription_textgrid.phonemic, segmentXMax
# Determine the target word and target segments.
selectObject(wordListBasename$)
targetWord$ = Get value: currentTrial, wordListWorldBet$
targetC1$ = Get value: currentTrial, wordListTargetC1$
targetC2$ = Get value: currentTrial, wordListTargetC2$
targetC3$ = Get value: currentTrial, wordListTargetC3$
prosPos1$ = Get value: currentTrial, wordListprosPos1$
prosPos2$ = Get value: currentTrial, wordListprosPos2$
prosPos3$ = Get value: currentTrial, wordListprosPos3$
if targetC1$ != "" & targetC1$ != "?"
@TranscribeSegment(targetC1$, prosPos1$, currentTrial, 1, targetWord$)
endif
if targetC2$ != "" & targetC2$ != "?"
@TranscribeSegment(targetC2$, prosPos2$, currentTrial, 2, targetWord$)
endif
if targetC3$ != "" & targetC3$ != "?"
@TranscribeSegment(targetC3$, prosPos3$, currentTrial, 3, targetWord$)
endif
##### This results in a very ungraceful way to quit midstream. Figure out a better way.
# Ask the user if they want to keep transcribing or quit.
beginPause ("")
comment ("Would you like to keep transcribing?")
clicked = endPause("Ruin everything", "Quit for now", "Continue transcribing", 3, 1)
# If the transcriber doesn't want to continue...
if clicked = 2
# If the transcriber decided to quit, then set the 'trial'
# variable so that the script breaks out of the while-loop.
continueTranscription = 0
else
# Remove the segmented interval's Table from the Praat Object list.
selectObject(segmentTableBasename$ + "_part_Context")
Remove
endif
selectObject(transLogBasename$)
@currentTime
Set string value: 1, transLogEndTime$, currentTime.t$
Set numeric value: 1, transLogTrialsTranscribed$, currentTrial
Save as tab-separated file: transcription_log.filepath$
#increment trial number
currentTrial = currentTrial + 1
endwhile
select all
Remove
procedure TranscribeSegment(.target$, .pros$, .currentTrial, .whichSegment, .word$)
# Zoom to the segmented interval in the editor window.
editor 'transBasename$'
Zoom: segmentXMin - 0.25, segmentXMax + 0.25
endeditor
# beginPause ("Make a selection in the editor window")
# comment ("Next sound to transcribe: '.target$'")
# comment ("Next sound to transcribe: '.target$' at '.pros$' in '.word$'")
# comment ("Please select the whole sound in the editor window")
# clicked = endPause ("Ruin everything", "Continue to transcribe this sound", 2, 1)
# editor 'transBasename$'
# start_time = Get start of selection
# end_time = Get end of selection
# interval_mid = (start_time + ((end_time - start_time)/2))
# endeditor
.spacing = (segmentXMax - segmentXMin)/7
start_time = segmentXMin + (.spacing * ((.whichSegment * 2) -1))
end_time = segmentXMin + .spacing + (.spacing * ((.whichSegment * 2) -1))
interval_mid = (start_time + ((end_time - start_time)/2))
# Add boundaries and text to the Phonetic, Phonemic, transCheck tiers
selectObject(transBasename$)
Insert boundary... transcription_textgrid.prosodicPos 'start_time'
Insert boundary... transcription_textgrid.prosodicPos 'end_time'
Insert boundary... transcription_textgrid.phonemic 'start_time'
Insert boundary... transcription_textgrid.phonemic 'end_time'
# Add the transcriptions to the TextGrid.
sound_int = Get interval at time... transcription_textgrid.phonemic 'interval_mid'
Set interval text... transcription_textgrid.prosodicPos 'sound_int' '.pros$'
Set interval text... transcription_textgrid.phonemic 'sound_int' '.target$'
# Prompt the user to rate production.
beginPause ("Rate the production of consonant #'.whichSegment'.")
comment ("Next sound to transcribe: '.target$' at '.pros$' in '.word$'")
comment ("Choose a phonemic transcription.")
choice ("Rating", 1)
option ("Correct")
option ("Incorrect")
option ("Untranscribeable")
endPause ("Ruin everything", "Rate Production", 2, 1)
if rating$ != "Untranscribeable"
if rating$ = "Correct"
.segmentScore = 1
else
.segmentScore = 0
endif
# Update the GFTA score.
selectObject(transLogBasename$)
.score = Get value: 1, transLogScore$
.score = .score + .segmentScore
Set numeric value: 1, transLogScore$, .score
selectObject(transBasename$)
Insert point... transcription_textgrid.score 'interval_mid' '.segmentScore'
else
# Update number of GFTA transcribeable segments.
selectObject(transLogBasename$)
.numTrabscribeable = Get value: 1, transLogTranscribeableTokens$
.numTrabscribeable = .numTrabscribeable - 1
Set numeric value: 1, transLogTranscribeableTokens$, .numTrabscribeable
selectObject(transBasename$)
Insert point... transcription_textgrid.score 'interval_mid' Not Transcribeable
endif
# Notes on the transcription of the word
beginPause ("Notes")
comment ("Any notes on the transcription of this segment?")
sentence ("trans_notes", "")
endPause ("Ruin everything", "Finish transcribing this segment", 2, 1)
if trans_notes$ != ""
#middle_of_word_time = ('current_word_end' + 'current_word_start') / 2
Insert point... transcription_textgrid.notes 'interval_mid' 'trans_notes$'
endif
selectObject(transBasename$)
Save as text file: transcription_textgrid.filepath$
selectObject(transLogBasename$)
Save as tab-separated file: transcription_log.filepath$
endproc
procedure transcribe_notes(.trial_number, .word$, .target1$, .target2$)
beginPause("Transcription Notes")
@trial_header(.trial_number, .word$, .target1$, .target2$, 0)
comment("You may enter any notes about this transcription below: ")
text("transcriber_notes", "")
comment("Should an audio and textgrid snippet be extracted for this trial?")
boolean("Extract snippet", 0)
button = endPause("Quit (without saving this trial)", "Transcribe it!", 2, 1)
if button == 1
.result_node$ = node_quit$
else
.notes$ = transcriber_notes$
.no_notes = length(.notes$) == 0
.snippet = extract_snippet
.result_node$ = node_next$
endif
endproc
#######################################################################
# PROCEDURE definitions start here
## This function is used to insert a row at the top of a table and write out
## the name and value of a string variable in that row. It's used for testing
## to show a "stack" of variable names and their values.
procedure writeLine .variable$
# Store the value of the passed variable
.value$ = '.variable$'
# If other objects are selected in Praat, store their names
.numberOfObjects = numberOfSelected ()
if .numberOfObjects > 0
for i from 1 to .numberOfObjects
.selection'i'$ = selected$ (i)
endfor
endif
# Update the table with passed variable and its value
select Table testing
Set string value... 1 variable '.variable$'
Set string value... 1 value '.value$'
Insert row... 1
# Restore Praat object selection
if .numberOfObjects > 0
select '.selection1$'
if .numberOfObjects > 1
for i from 2 to .numberOfObjects
.name$ = .selection'i'$
plus '.name$'
endfor
endif
endif
endproc
#### PROCEDURE to count the remaining trials yet to be transcribed.
procedure count_remaining_trials(.log_basename$, .row)
selectObject(.log_basename$)
.n_trials = Get value: .row, "NumberOfTrials"
.n_transcribed = Get value: .row, "NumberOfTrialsTranscribed"
.n_remaining = .n_trials - .n_transcribed
endproc
#### PROCEDURE to count GFTA wordlist structures for each of the three structure types.
procedure count_GFTA_wordlist_structures(.wordList_table$)
# Get the number of trials in the Word List table.
selectObject(.wordList_table$)
.nTrials = Get number of rows
endproc
#### PROCEDURE to find xmin and xmax from Table representation of TextGrid
# Find the xboundaries of an interval from a tabular representation of a textgrid
procedure get_xbounds_from_table(.table$, .row)
selectObject(.table$)
.xmin = Get value: .row, "tmin"
.xmax = Get value: .row, "tmax"
.xmid = (.xmin + .xmax) / 2
endproc
#### PROCEDURE to get xmin and xmax of interval in TextGrid object from time point
# Find the xboundaries of a textgrid interval that contains a given point.
# The .point argument is usually the .xmid value obtained from the above
# get_xbounds_from_table procedure.
procedure get_xbounds_in_textgrid_interval(.textgrid$, .tier_num, .point)
selectObject(.textgrid$)
.interval = Get interval at time: .tier_num, .point
.xmin = Get start point: .tier_num, .interval
.xmax = Get end point: .tier_num, .interval
.xmid = (.xmin + .xmax) / 2
endproc