-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstartup_check_segmentation.praat
1790 lines (1638 loc) · 75.1 KB
/
startup_check_segmentation.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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Script: startup_check_segmentation.praat
# Repository: https://github.com/LearningToTalk/Segmentation/
#=========================================================#
# Global variables (other than those defined in startup section on basis of user input)
#=========================================================#
# Praat procedure.
procedure$ = "Check_segmentation"
# Segmentation Log table columns
sl_segmenter = 1
sl_segmenter$ = "Segmenter"
sl_startDate = 2
sl_startDate$ = "StartDate"
sl_endDate = 3
sl_endDate$ = "EndDate"
#sl_xmin = 4
#sl_xmin$ = "ExperimentXMin"
sl_nTrials = 4
sl_nTrials$ = "NumberOfTrials"
sl_segTrials = 5
sl_segTrials$ = "NumberOfTrialsSegmented"
# Audio-Anonymization Log table columns
al_xmin = 1
al_xmin$ = "XMin"
al_xmax = 2
al_xmax$ = "XMax"
# TextGrid tier numbers and tier names
tg_trial = 1
tg_trial$ = "Trial"
tg_word = 2
tg_word$ = "Word"
tg_context = 3
tg_context$ = "Context"
tg_repetition = 4
tg_repetition$ = "Repetition"
tg_notes = 5
tg_notes$ = "SegmNotes"
# Trial-Segmentations Log table columns
tl_xmin = 1
tl_xmin$ = "XMin"
tl_xmax = 2
tl_xmax$ = "XMax"
#===============================================#
# Start-up section
#===============================================#
debug_mode = 1
# The startup wizard is a set of linked nodes: [n1] <-> [n2] <-> [n3] <-> ...
# Each node is a procedure that displays a form to the user. During each
# procedure, a value called .result_node$ is computed which indicates
# whether the wizard should go forward, backward or abort.
# Values for .result_node$
node_quit$ = "quit"
node_next$ = "next"
node_back$ = "back"
# Map a .result_node$ value onto the name of node in the wizard.
procedure next_back_quit(.status$, .next_step$, .last_step$, .quit$)
if .status$ == node_next$
.result$ = .next_step$
elsif .status$ == node_back$
.result$ = .last_step$
else
.result$ = .quit$
endif
endproc
# Name the nodes of the start-up procedure.
startup_node_quit$ = "quit"
startup_node_task$ = "task"
startup_node_segment$ = "segment"
startup_node_initials$ = "initials"
startup_node_checker_initials$ = "checker_initials"
startup_node_location$ = "location"
startup_node_testwave$ = "testwave"
startup_node_subject$ = "subject"
startup_node_segdata$ = "segdata"
startup_node_audio$ = "audio"
startup_node_wordlist$ = "wordlist"
# [STARTUP WIZARD EVENT LOOP]
startup_node$ = startup_node_initials$
if debug_mode
writeInfoLine("Node: ", startup_node$)
appendInfoLine("")
endif
# Start-up wizard runs as long as the user has not quit or finished.
while (startup_node$ != startup_node_quit$) and (startup_node$ != startup_node_segdata$)
# [INITIALS, LOCATION]
if startup_node$ == startup_node_initials$
@startup_initials()
@log_initials()
@next_back_quit(startup_initials.result_node$, startup_node_testwave$, "", startup_node_quit$)
startup_node$ = next_back_quit.result$
# [TASK, TIMEPOINT]
elsif startup_node$ == startup_node_testwave$
@startup_testwave()
@log_testwave()
@next_back_quit(startup_testwave.result_node$, startup_node_subject$, startup_node_initials$, startup_node_quit$)
startup_node$ = next_back_quit.result$
# [SUBJECT]
elsif startup_node$ == startup_node_subject$
# [LOCAL FILE SYSTEM VARIABLES] Use results from the previous nodes to generate filepaths
drive$ = startup_initials.drive$
audio_drive$ = startup_initials.audio_drive$
task$ = startup_testwave.task$
testwave$ = startup_testwave.testwave$
segmenters_initials$ = startup_initials.initials$
@segmentation_filepaths(drive$, audio_drive$, task$, testwave$, segmenters_initials$)
@log_segmentation_filepaths()
audio_dir$ = segmentation_filepaths.audio_dir$
audioAnon_dir$ = segmentation_filepaths.audioAnon_dir$
segmentLog_dir$ = segmentation_filepaths.segmentLog_dir$
textGrid_dir$ = segmentation_filepaths.textGrid_dir$
wordList_dir$ = segmentation_filepaths.wordList_dir$
wl_trial = segmentation_filepaths.wl_trial
wl_trial$ = segmentation_filepaths.wl_trial$
wl_word = segmentation_filepaths.wl_word
wl_word$ = segmentation_filepaths.wl_word$
# Prompt for ID
@startup_id()
@log_startup_id()
@next_back_quit(startup_id.result_node$, startup_node_audio$, startup_node_testwave$, startup_node_quit$)
startup_node$ = next_back_quit.result$
# [AUDIO FILE]
elsif startup_node$ == startup_node_audio$
id_number$ = startup_id.id_number$
@startup_load_audio(audio_dir$, task$, id_number$)
@log_load_audio()
@next_back_quit(startup_load_audio.result_node$, startup_node_wordlist$, "", startup_node_quit$)
startup_node$ = next_back_quit.result$
# [WORD LIST TABLE]
elsif startup_node$ == startup_node_wordlist$
audio_sound$ = startup_load_audio.audio_sound$
experimental_ID$ = startup_load_audio.experimental_ID$
@startup_wordlist(task$, experimental_ID$, drive$, wordList_dir$)
@log_startup_wordlist()
@next_back_quit(startup_wordlist.result_node$, startup_node_segdata$, "", startup_node_quit$)
startup_node$ = next_back_quit.result$
endif
endwhile
# [SEGMENTATION DATA]
# Load or initialize data objects:
# 1. A segmentation log
# 2. An audio-anonymization log
# 3. A TextGrid
if startup_node$ == startup_node_segdata$
wordList_table$ = startup_wordlist.wordList_table$
n_trials = startup_wordlist.n_trials
# [SEGMENTATION LOG]
# Make string variables for the segmentation log's basename,
# filename, and filepath on the local filesystem, using the
# 'subject's experimental ID, which was chosen during the previous
# step in the start-up procedure (see the code block for the
# 'startup_node_subject$' node above) and the 'segmentLog_dir$'
# variable that is imported from the '...Directories.praat' file.
segmentLog_basename$ = "'task$'_'experimental_ID$'_'segmenters_initials$'segmentLog"
segmentLog_filename$ = "'segmentLog_basename$'.txt"
segmentLog_filepath$ = "'segmentLog_dir$'/'segmentLog_filename$'"
# Make a name for the segmentation log Praat Table.
segmentLog_table$ = "'experimental_ID$'_SegmentLog"
# Determine whether a segmentation log exists on the local file
# system. If a segmentation log exists, then the current session
# is a continuation of a previous session during which the same
# subject's audio file was segmented.
segmentLog_exists = fileReadable(segmentLog_filepath$)
# Use the 'segmentLog_exists' variable to determine whether the
# segmentation log needs to be loaded or created from scratch.
if (segmentLog_exists)
# If a segmentation log exists on the local file system,
# first read it in as a Praat Table, then rename that table
# according to the 'segmentLog_table$' variable.
Read Table from tab-separated file... 'segmentLog_filepath$'
select Table 'segmentLog_basename$'
Rename... 'segmentLog_table$'
# Furthermore, if there is an extant segmentation log, then
# either the current segmentation session is a continuation of a
# segmentation session that was not completed, or the segmenter
# has re-opened a file that he / she already segmented, so ..
# Get the values for the NumberOfTrials and the NumberOfTrialsSegmented.
n_trials_total = Get value... 1 'sl_nTrials$'
n_trials_segmented = Get value... 1 'sl_segTrials$'
# Check to see if there are any trials left to be segmented.
if ('n_trials_segmented' >= 'n_trials_total')
# If there are no more trials to be segmented in this file,
# first display an error message to the segmenter,
# and then quit this segmentation session.
beginPause ("'procedure$' - Initialization error 5. Reopening finished file.")
comment ("You seem to be continuing a segmentation session for ")
comment (" 'experimental_ID$', but the 'segmentLog_filename$'")
comment(" registers that you have segmented all the trials.")
comment ("If you did not already segment this file, report this")
comment(" error to your Segmentation Guru.")
endPause ("Quit segmenting", 1, 1)
# Transition to the 'startup_node_quit$' node.
startup_node$ = startup_node_quit$
else
# Furthermore, if there is an extant segmentation log, then
# the current segmentation session is a continuation of a
# previous session for the same subject, and so there should
# also be an anonymized-audio log file, and a segmentation
# TextGrid that can be read from the local filesystem.
# [AUDIO-ANONYMIZATION LOG]
# Make string variables for the audio-anonymization log's
# basename, filename, and filepath on the local filesystem.
audioLog_basename$ = "'task$'_'experimental_ID$'_'segmenters_initials$'audioLog"
audioLog_filename$ = "'audioLog_basename$'.txt"
audioLog_filepath$ = "'audioAnon_dir$'/'audioLog_filename$'"
audioLog_table$ = "'experimental_ID$'_AudioLog"
# Look for the audio-anonymization log on the local filesystem.
audioLog_exists = fileReadable(audioLog_filepath$)
if (audioLog_exists)
# If the audio-anonymization log exists on the local
# filesystem, read it in as a Praat Table and then rename
# it according to the 'audioLog_table$' variable.
Read Table from tab-separated file... 'audioLog_filepath$'
select Table 'audioLog_basename$'
Rename... 'audioLog_table$'
# Sort the rows of the audio-anonymization log in
# ascending order of their XMin value.
select Table 'audioLog_table$'
Sort rows... 'al_xmin$'
# Anonymize the audio file on the fly.
select Table 'audioLog_table$'
n_anonymizations = Get number of rows
for anon to n_anonymizations
select Table 'audioLog_table$'
anon_xmin = Get value... 'anon' 'al_xmin$'
anon_xmax = Get value... 'anon' 'al_xmax$'
select Sound 'audio_sound$'
Set part to zero... 'anon_xmin' 'anon_xmax' at nearest zero crossing
endfor
else
# If the audio-anonymization log doesn't exist on the local
# filesystem, first display an error message to the segmenter,
# and then quit this segmentation session.
beginPause ("'procedure$' - Initialization error 4. Cannot load audio log file.")
comment ("You seem to be continuing a segmentation session for subject 'experimental_ID$'.")
comment ("But there doesn't seem to be an audio-anonymization log for this subject")
comment (" on the local filesystem.")
comment ("Check that the following directory exists on the local filesystem:")
comment (" 'audioAnon_dir$'")
comment ("Also check that this directory contains a file named 'task$'_'experimental_ID$'_'segmenters_initials$'audioLog.txt." )
endPause ("Quit segmenting & check filesystem", 1, 1)
# Transition to the 'startup_node_quit$' node.
startup_node$ = startup_node_quit$
endif
# [SEGMENTATION TEXTGRID]
# Make string variables for the segmentation TextGrid's
# basename, filename, and filepath on the local filesystem.
textGrid_basename$ = "'task$'_'experimental_ID$'_'segmenters_initials$'segm"
textGrid_filename$ = "'textGrid_basename$'.TextGrid"
textGrid_filepath$ = "'textGrid_dir$'/'textGrid_filename$'"
textGrid_object$ = "'experimental_ID$'_Segmentation"
# Look for the segmentation TextGrid in the filesystem.
textGrid_exists = fileReadable(textGrid_filepath$)
if (textGrid_exists)
# If the segmentation TextGrid exists on the local
# filesystem, read it in as a Praat TextGrid object, and
# then rename it according to the 'textGrid_object$' variable.
Read from file... 'textGrid_filepath$'
select TextGrid 'textGrid_basename$'
Rename... 'textGrid_object$'
# At this point, each of the data files necessary to
# segment an audio file have been read in from the local
# filesystem. So, segmentation can begin.
# Transition to the 'startup_node_segment$' node.
startup_node$ = startup_node_segment$
else
# If the segmentation TextGrid doesn't exist on the local
# filesystem, first display an error message to the segmenter,
# and then quit this segmentation session.
beginPause ("'procedure$' - Initialization error 3. Cannot load segmentation log file.")
comment ("You seem to be continuing a segmentation session for subject 'experimental_ID$'."
comment ("But there doesn't seem to be a segmentation TextGrid for this subject")
comment (" on the local filesystem.")
comment ("Check that the following directory exists on the local filesystem:")
comment (" 'textGrid_dir$'")
comment ("Also check that this directory contains a file named 'task$'_'experimental_ID$'_'segmenters_initials$'segm.TextGrid"
endPause ("Quit segmenting & check filesystem", 1, 1)
# Transition to the 'startup_node_quit$' node.
startup_node$ = startup_node_quit$
endif
endif
## # This is the end of the conditional about whether there are more trials to be segmented.
else
# If a segmentation log doesn't exist on the local file system,
# then this means the segmenter has not made any progress on
# segmenting this subject's audio recording. Hence, the
# segmentation log, the audio-anonymization log, and the
# segmentation TextGrid all need to be created.
# [SEGMENTATION LOG]
# Create the segmentation log as a Praat Table, and initialize
# its values.
current_time$ = replace$(date$(), " ", "_", 0)
Create Table with column names... 'segmentLog_table$' 1 'sl_segmenter$' 'sl_startDate$' 'sl_endDate$' 'sl_nTrials$' 'sl_segTrials$'
select Table 'segmentLog_table$'
Set string value... 1 'sl_segmenter$' 'segmenters_initials$'
Set string value... 1 'sl_startDate$' 'current_time$'
Set string value... 1 'sl_endDate$' 'current_time$'
Set numeric value... 1 'sl_nTrials$' 'n_trials'
Set numeric value... 1 'sl_segTrials$' 0
# [AUDIO-ANONYMIZATION LOG]
# Make string variables for the audio-anonymization log's
# basename, filename, and filepath on the local filesystem.
audioLog_basename$ = "'task$'_'experimental_ID$'_'segmenters_initials$'audioLog"
audioLog_filename$ = "'audioLog_basename$'.txt"
audioLog_filepath$ = "'audioAnon_dir$'/'audioLog_filename$'"
audioLog_table$ = "'experimental_ID$'_AudioLog"
# Create the audio-anonymization log as a Praat Table with
# 1 row. It needs to be guaranteed that the audio-anonymization
# log has at least 1 row; otherwise, there will be trouble
# if the segmenter tries to quit and resume without adding
# an interval that needs to be anonymized. Initialize the
# audio-anonymization log with the interval [0, 0.01] muted.
Create Table with column names... 'audioLog_table$' 1 'al_xmin$' 'al_xmax$'
select Table 'audioLog_table$'
Set numeric value... 1 'al_xmin$' 0
Set numeric value... 1 'al_xmax$' 0.01
# [SEGMENTATION TEXTGRID]
# Make string variables for the segmentation TextGrid's
# basename, filename, and filepath on the local filesystem.
textGrid_basename$ = "'task$'_'experimental_ID$'_'segmenters_initials$'segm"
textGrid_filename$ = "'textGrid_basename$'.TextGrid"
textGrid_filepath$ = "'textGrid_dir$'/'textGrid_filename$'"
textGrid_object$ = "'experimental_ID$'_Segmentation"
# Create the segmentation TextGrid as a Praat TextGrid object
# with five tiers: Trial, Word, Context, Repetition, SegmNotes,
# of which only SegmNotes is a Point Tier.
select Sound 'audio_sound$'
To TextGrid... "'tg_trial$' 'tg_word$' 'tg_context$' 'tg_repetition$' 'tg_notes$'" 'tg_notes$'
select TextGrid 'audio_sound$'
Rename... 'textGrid_object$'
# [TEST FILE PATHNAMES]
# Attempt to save the TextGrid, the audio-anonymization log,
# and the segmentation log to the local filesystem before
# moving on to segmenting. This will ensure that when
# actual data is saved later on in the script, doing so
# will succeed.
select TextGrid 'textGrid_object$'
Save as text file... 'textGrid_filepath$'
select Table 'audioLog_table$'
Save as tab-separated file... 'audioLog_filepath$'
select Table 'segmentLog_table$'
Save as tab-separated file... 'segmentLog_filepath$'
# At this point, all of the data necessary to continue with
# the segmentation session has either been read from the
# local filesystem or created from scratch.
# Transition to the 'startup_node_segment$' node.
startup_node$ = startup_node_segment$
endif
endif
# [NODE] Get the segmenter's initials, the checker's initials and where the checker is working from
procedure startup_initials()
beginPause ("'procedure$' - Initializing session, step 1.")
#### HERE Perhaps delete the query about the segmenter's initials, or add a default value of
#### "search" so that the checking could proceed by searching for ...segmentLog.txt files for
#### a given child's PID and then checking to see if segmentation is complete, and providing
#### a scroll-down menu of choices?
# Prompt the user to enter the segmenter's initials.
comment ("Please enter the segmenter's initials in the field below.")
word ("Segmenters initials", "")
# Prompt the user to enter the user's initials.
comment ("Please enter your initials in the field below.")
word ("Your initials", "")
# Prompt the user to specify where the script is being run.
comment ("Please specify where the machine is on which you are working.")
optionMenu ("Location", 1)
option ("WaismanLab")
option ("ShevlinHallLab")
option ("Mac via RDC")
option ("Mac via VPN")
option ("Other (Beckman)")
option ("Other (not Beckman)")
button = endPause ("Quit", "Continue", 2)
# Use the 'button' variable to determine which node to transition to next.
if button == 1
.result_node$ = node_quit$
else
# If the checker has entered initials and location and wishes to
# continue to the next step of the start-up procedure (button = 2),
# then set the value of the .segmenters_initials$ variable and so on.
.segmenters_initials$ = segmenters_initials$
.checker_initials$ = your_initials$
.location$ = location$
# Use the value of the '.location$' variable to set up the 'drive$' variables.
if (.location$ == "WaismanLab")
.drive$ = "L:/"
.audio_drive$ = "L:/"
elsif (.location$ == "ShevlinHallLab")
.drive$ = "//l2t.cla.umn.edu/tier2/"
.audio_drive$ = "//l2t.cla.umn.edu/tier2/"
elsif (.location$ == "Mac via RDC")
.drive$ = "I:/"
.audio_drive$ = "I:/"
elsif (.location$ == "Mac via VPN")
.drive$ = "/Volumes/tier2/"
.audio_drive$ = "/Volumes/tier2onUSB/"
elsif (.location$ == "Other (Beckman)")
.drive$ = "/Volumes/tier2/"
.audio_drive$ = "/LearningToTalk/Tier2/"
elsif (.location$ == "Other (not Beckman)")
exit Contact Mary Beckman and your segmentation guru to request another location
endif
.result_node$ = node_next$
endif
endproc
# console output for debugging
procedure log_initials()
if debug_mode
appendInfoLine("---- log_initials() ----")
appendInfoLine("Exit Status: ", startup_initials.result_node$)
if startup_initials.result_node$ == node_next$
appendInfoLine("derived values: ")
appendInfoLine(tab$, ".initials$: ", startup_initials.segmenter_initials$)
appendInfoLine(tab$, ".initials$: ", startup_initials.checker_initials$)
appendInfoLine(tab$, ".drive$: ", startup_initials.drive$)
appendInfoLine(tab$, ".audio_drive$: ", startup_initials.audio_drive$)
endif
appendInfoLine("")
endif
endproc
# [NODE] Get the experimental task and the timepoint ("testwave") of the recording
procedure startup_testwave()
beginPause ("'procedure$' - Initializing session, step 3 (task and test wave of recording).")
comment ("Please choose the experimental task of the recording.")
optionMenu ("Task", 2)
option ("NonWordRep")
option ("RealWordRep")
option ("GFTA")
# Prompt the segmenter to specify the testwave (i.e., the "TimePoint") of the data.
comment ("Please specify the test wave of the recording.")
optionMenu ("Testwave", 1)
option ("TimePoint1")
option ("TimePoint2")
option ("Other")
button = endPause ("Back", "Quit", "Continue", 3)
# Use the 'button' variable to determine which node to transition to next.
if button == 1
.result_node$ = node_back$
elsif button == 2
.result_node$ = node_quit$
elsif button == 3
# If the segmenter chooses to 'Continue', then store the value
# of the 'task$' and 'testwave$' variables
.testwave$ = testwave$
.task$ = task$
.result_node$ = node_next$
endif
endproc
# console output for debugging
procedure log_testwave()
if debug_mode
appendInfoLine("---- log_testwave() ----")
appendInfoLine("Exit Status: ", startup_testwave.result_node$)
if startup_testwave.result_node$ == node_next$
appendInfoLine("derived values: ")
appendInfoLine(tab$, ".task$: ", startup_testwave.task$)
appendInfoLine(tab$, ".testwave$: ", startup_testwave.testwave$)
endif
appendInfoLine("")
endif
endproc
##### HERE check and revise the following to include the directories where expanded
##### textgrids and log files are stored after checking.
# [SUBNODE] Setup directory path names for navigating the local filesystem.
procedure segmentation_filepaths(.drive$, .audio_drive$, .task$, .testwave$, .segmenters_initials$)
segmenter_dir$ = .drive$ + "Segmenting/Segmenters/" + .segmenters_initials$
# The directory to where the ...SegmentationLog.txt file is written when a segmenter first
# starts segmenting a file and from where the segmentation log is read on subsequent
# segmentation sessions for a file when segmentation is still in progress.
.segmentLog_dir$ = segmenter_dir$ + "/Logs" + .task$
# The directory to where the ...segm.TextGrid file is written when a segmenter first
# starts segmenting a file and from where the segmentation textgrid file is read on
# subsequent segmentation sessions for a file when segmentation is still in progress.
.textGrid_dir$ = segmenter_dir$ + "/Segmentation" + .task$
# Shared directories that will not be affected by the process of segmentation.
data_dir$ = .drive$ + "DataAnalysis/" + .task$ + "/" + .testwave$
# The directory from where audio files are read.
.audio_dir$ = .audio_drive$ + "DataAnalysis/" + .task$ + "/" + .testwave$ + "/Recordings"
# The directory from where word list tables are read.
.wordList_dir$ = data_dir$ + "/WordLists"
# Shared directory that will changed by the process of segmentation.
# The directory to where anonymized audio log files are written.
.audioAnon_dir$ = data_dir$ + "/AudioAnonymizationLogs"
# Word List table columns
if .task$ == "RealWordRep"
.wl_trial = 1
.wl_trial$ = "TrialNumber"
.wl_word = 3
.wl_word$ = "Word"
elsif .task$ == "NonWordRep"
.wl_trial = 1
.wl_trial$ = "TrialNumber"
.wl_word = 3
.wl_word$ = "Orthography"
elsif .task$ == "GFTA"
.wl_trial = 1
.wl_trial$ = "word"
.wl_word = 3
.wl_word$ = "ortho"
endif
endproc
# console output for debugging
procedure log_segmentation_filepaths()
if debug_mode
appendInfoLine("---- log_segmentation_filepaths() ----")
appendInfoLine("input parameters: ")
appendInfoLine(tab$, ".drive$: ", segmentation_filepaths.drive$)
appendInfoLine(tab$, ".audio_drive$: ", segmentation_filepaths.audio_drive$)
appendInfoLine(tab$, ".task$: ", segmentation_filepaths.task$)
appendInfoLine(tab$, ".testwave$: ", segmentation_filepaths.testwave$)
appendInfoLine(tab$, ".segmenters_initials$: ", segmentation_filepaths.segmenters_initials$)
appendInfoLine("")
appendInfoLine("derived values: ")
appendInfoLine(tab$, ".segmentLog_dir$: ", segmentation_filepaths.segmentLog_dir$)
appendInfoLine(tab$, ".textGrid_dir$: ", segmentation_filepaths.textGrid_dir$)
appendInfoLine(tab$, ".audio_dir$: ", segmentation_filepaths.audio_dir$)
appendInfoLine(tab$, ".wordList_dir$: ", segmentation_filepaths.wordList_dir$)
appendInfoLine(tab$, ".audioAnon_dir$: ", segmentation_filepaths.audioAnon_dir$)
appendInfoLine(tab$, ".wl_trial: ", segmentation_filepaths.wl_trial)
appendInfoLine(tab$, ".wl_trial$: ", segmentation_filepaths.wl_trial$)
appendInfoLine(tab$, ".wl_word: ", segmentation_filepaths.wl_word)
appendInfoLine(tab$, ".wl_word$: ", segmentation_filepaths.wl_word$)
appendInfoLine("")
endif
endproc
##### HERE Perhaps expand the following with a search through the relevent ones of
##### the LogsRealWordRep or LogsNonWordRep subdirectories of all segmenters
##### subdirectories of the Segmenters directories?
# [NODE] Prompt the user to choose the subject's experimental ID.
procedure startup_id()
# Open a dialog box and prompt the user to specify the subject's 3-digit id no.
beginPause ("'procedure$' - Initializing session, step 5 (participant ID).")
comment ("Please enter the participant's 3-digit ID number in the field below.")
word ("id number", "")
button = endPause ("Back", "Quit", "Continue", 3, 1)
# Use the 'button' variable to determine which node to transition to next.
if button == 1
.result_node$ = node_back$
elsif button == 2
.result_node$ = node_quit$
else
# If the segmenter wishes to continue to the next step in the
# start-up procedure (ie. loading the data files necessary to
# segment an audio recording) (button = 3), then transition to
# the next node.
.id_number$ = id_number$
.result_node$ = node_next$
endif
endproc
# console output for debugging
procedure log_startup_id()
if debug_mode
appendInfoLine("---- log_startup_id() ----")
appendInfoLine("Exit Status: ", startup_id.result_node$)
if startup_id.result_node$ == node_next$
appendInfoLine(tab$, "derived values: ")
appendInfoLine(tab$, ".id_number$: ", startup_id.id_number$)
endif
appendInfoLine("")
endif
endproc
# [AUDIO FILE]
procedure startup_load_audio(.audio_dir$, .task$, .id_number$)
# Make the pattern to search for
.ext$ = if (macintosh or unix) then "WAV" else "wav" endif
.audio_pattern$ = .audio_dir$ + "/" + .task$ + "_" + .id_number$ + "*." + .ext$
# Determine which .wav (or .WAV) file in the 'audio_dir$' directory has a filename
# that includes the id number of the subject presently being segmented.
Create Strings as file list: "wavFile", .audio_pattern$
n_wavs = Get number of strings
# The resulting Strings object 'wavFile' should list exactly one .wav (or .WAV)
# filename that corresponds to the correct audio file for this subject.
if (n_wavs > 0)
# If the Strings object 'wavFile' has at least one filename,
# use the filename in this Strings object to make string
# variables for the filename, basename, and filepath of the
# audio file on the local filesystem.
select Strings wavFile
.audio_filename$ = Get string... 1
.audio_basename$ = .audio_filename$ - ".wav" - ".WAV"
.audio_filepath$ = "'.audio_dir$'/'.audio_filename$'"
# Also make the corresponding experimental_ID$ variable that need later.
.experimental_ID$ = mid$(.audio_basename$, length(.task$)+2, length(.audio_basename$))
.audio_sound$ = "'.experimental_ID$'_Audio"
# Remove the Strings object from the Praat object list.
select Strings wavFile
Remove
# Read in the audio file, and rename it to the value of the
# 'audio_sound$' string variable.
Read from file... '.audio_filepath$'
select Sound '.audio_basename$'
Rename... '.audio_sound$'
.result_node$ = node_next$
else
# If the Strings object 'wavFile' has no filenames on it,
# then the script was unable to find a candidate .wav file.
# Display an error message to the segmenter and then
# quit this segmentation session.
beginPause ("'procedure$' - Initialization error 1. Cannot load audio file.")
comment ("There doesn't seem to be an audio file for subject '.id_number$'")
comment (" on the local filesystem.")
comment ("Check that the following directory exists on the local filesystem:")
comment ("'.audio_dir$'")
comment ("Also check that this directory contains a wave file whose basename")
comment (" begins with 'task$'_'id_number$'.")
endPause ("Quit segmenting & check filesystem", 1, 1)
.result_node$ = node_quit$
endif
endproc
# console output for debugging
procedure log_load_audio()
if debug_mode
appendInfoLine("---- log_load_audio() ----")
appendInfoLine("Exit Status: ", startup_load_audio.result_node$)
appendInfoLine("input parameters: ")
appendInfoLine(tab$, ".audio_dir$: ", startup_load_audio.audio_dir$)
appendInfoLine(tab$, ".task$: ", startup_load_audio.task$)
appendInfoLine(tab$, ".id_number$: ", startup_load_audio.id_number$)
appendInfoLine("")
appendInfoLine("derived values: ")
appendInfoLine(tab$, ".ext$: ", startup_load_audio.ext$)
appendInfoLine(tab$, ".audio_pattern$: ", startup_load_audio.audio_pattern$)
if startup_load_audio.result_node$ == node_next$
appendInfoLine(tab$, ".audio_filename$: ", startup_load_audio.audio_filename$)
appendInfoLine(tab$, ".audio_basename$: ", startup_load_audio.audio_basename$)
appendInfoLine(tab$, ".audio_filepath$: ", startup_load_audio.audio_filepath$)
appendInfoLine(tab$, ".experimental_ID$: ", startup_load_audio.experimental_ID$)
appendInfoLine(tab$, ".audio_sound$: ", startup_load_audio.audio_sound$)
endif
appendInfoLine("")
endif
endproc
# [WORD LIST TABLE]
procedure startup_wordlist(.task$, .experimental_ID$, .drive$, .wordList_dir$)
# Make string variables for the word list table's basename,
# filename, and filepath on the local filesystem, using the
# 'subject's experimental ID.
.wordList_basename$ = "'.task$'_'.experimental_ID$'_WordList"
.wordList_filename$ = "'.wordList_basename$'.txt"
.wordList_filepath$ = "'.wordList_dir$'/'.wordList_filename$'"
.wordList_table$ = "'.experimental_ID$'_WordList"
.wordList_exists = fileReadable(.wordList_filepath$)
# What we do with this information depends on the task, because ...
if .task$ == "GFTA"
# If the task is GFTA, there is usually just one file for everyone.
if (.wordList_exists == 0)
.wordList_basename$ = "GFTA_info"
.wordList_filepath$ = "'.drive$'DataAnalysis/GFTA/GFTA_info.txt"
endif
# But in either case we want the Table Object to be called the same
# thing so we'll reset the wordList_table$ variable.
.wordList_table$ = "gfta_wordlist"
endif
# Determine again whether a Word List table exists on the local file system.
.wordList_exists = fileReadable(.wordList_filepath$)
if (.wordList_exists)
# Read the word list table from the local filesystem, and then rename
# it according to the 'wordList_table$' variable.
Read Table from tab-separated file... '.wordList_filepath$'
select Table '.wordList_basename$'
Rename... '.wordList_table$'
# Determine the number of trials (both Familiarization and Test trials)
# in this experimental session.
select Table '.wordList_table$'
.n_trials = Get number of rows
.result_node$ = node_next$
else
# If there is no Word List table on the local filesystem, first
# display an error message to the segmenter and then quit this
# segmentation session.
beginPause ("'procedure$' - Initialization error 2. Cannot load word list file.")
comment ("There doesn't seem to be a word list table for this subject on the local filesystem.")
comment ("Check that the following directory exists on the local filesystem:")
comment ("'.wordList_dir$'")
comment ("Also check that this directory contains a word list table whose filename is '.task$'_'.experimental_ID$'_WordList.txt.")
endPause ("Quit segmenting & check filesystem", 1, 1)
.result_node$ = node_quit$
endif
endproc
# console output for debugging
procedure log_startup_wordlist()
if debug_mode
appendInfoLine("---- log_startup_wordlist() ----")
appendInfoLine("Exit Status: ", startup_wordlist.result_node$)
appendInfoLine("input parameters: ")
appendInfoLine(tab$, ".task$: ", startup_wordlist.task$)
appendInfoLine(tab$, ".experimental_ID$: ", startup_wordlist.experimental_ID$)
appendInfoLine(tab$, ".wordList_dir$: ", startup_wordlist.wordList_dir$)
appendInfoLine("")
appendInfoLine("derived values: ")
appendInfoLine(tab$, ".wordList_basename$: ", startup_wordlist.wordList_basename$)
appendInfoLine(tab$, ".wordList_filename$: ", startup_wordlist.wordList_filename$)
appendInfoLine(tab$, ".wordList_filepath$: ", startup_wordlist.wordList_filepath$)
appendInfoLine(tab$, ".wordList_table$: ", startup_wordlist.wordList_table$)
appendInfoLine(tab$, ".wordList_exists: ", startup_wordlist.wordList_exists)
if startup_wordlist.result_node$ != node_quit$
appendInfoLine(tab$, ".n_trials: ", startup_wordlist.n_trials)
endif
appendInfoLine("")
endif
endproc
#===============================================#
# End of start-up procedure
#===============================================#
##### Should the initialization processes be divided out and kept in this
##### startup_check_segmentation.praat file?
#===============================================#
# Check segmentation procedure
#===============================================#
# The Check segmentation procedure is run only if the Start-Up procedure
# finished on the 'startup_node_segment$' node.
# Check whether the Start-Up procedure finished on the
# 'startup_node_segment$' node.
if (startup_node$ == startup_node_segment$)
# [INITIALIZING] - Here starts a stretch of code to initialize variables, etc.
# [TRIAL]
# Initialize a 'trial' variable, which denotes the current row of
# the Word List table, by getting the number of trials already
# segmented.
select Table 'segmentLog_table$'
n_trials_segmented = Get value... 1 'sl_segTrials$'
trial = 'n_trials_segmented' + 1
# [TRIAL NUMBER]
# Initialize a variable for the Trial Number of the current trial.
# Note that the Trial Number differs from the 'trial' variable
# in that the 'trial' variable denotes the row of the word list
# table, while the Trial Number is an alphanumeric code that denotes
# whether the trial was Familiarization or Test, and then the
# ordinal number within each of the trial types---eg. Fam2 or Test4.
select Table 'wordList_table$'
trial_number$ = Get value... 'trial' 'wl_trial$'
# [TARGET WORD]
# Initialize a variable for the Target Word of the current trial.
select Table 'wordList_table$'
trial_word$ = Get value... 'trial' 'wl_word$'
# [SAME TARGET WORD SEQUENCE]
# Initialize variables for tracking whether the current trial
# is in a sequence of of trials that have the same Target Word
# (or a "same-target sequence", abbreviated "STS").
# First determine if the current trial is in an STS by comparing the
# Target Word of the current trial to the respective Target Words
# of the previous and next trials.
trial_in_STS = 0
previous_trial = 'trial' - 1
if (previous_trial > 0)
# If the current trial is not the first trial in the session,
# then check the previous trial's Target Word.
select Table 'wordList_table$'
previous_trial_word$ = Get value... 'previous_trial' 'wl_word$'
# Compare the Target Words of the current and previous trials.
if (trial_word$ == previous_trial_word$)
# If the current and previous trials have the same Target Word,
# then modify the 'trial_in_STS' variable.
trial_in_STS = 1
endif
endif
next_trial = 'trial' + 1
if (next_trial < n_trials)
# If the current trial is not the last trial in the session,
# then check the next trial's Target Word.
select Table 'wordList_table$'
next_trial_word$ = Get value... 'next_trial' 'wl_word$'
# Compare the Target Words of the current and next trials.
if (trial_word$ == next_trial_word$)
# If the current and next trials have the same Target WOrd,
# then modify the 'trial_in_STS' variable.
trial_in_STS = 1
endif
endif
# Second, determine the position of the current trial in
# an STS, by comparing the Target Word of the current trial to the
# Target Word of previous trial(s).
position_in_STS = 1
compare_trial = 'trial' - 1
while (compare_trial)
# If the comparison trial is still greater than zero, determine
# the Target Word of the comparison trial.
select Table 'wordList_table$'
compare_trial_word$ = Get value... 'compare_trial' 'wl_word$'
# Compare the Target Word of the comparison trial to the Target
# Word of the current trial.
if (compare_trial_word$ == trial_word$)
# If the comparison trial and the current trial have the same
# Target Word, then the current trial is a part of a multi-trial STS.
# Hence, increment the current trial's 'position_in_STS' variable.
position_in_STS = 'position_in_STS' + 1
# And then move the comparison trial up to the previous trial
# on the Word List.
compare_trial = 'compare_trial' - 1
else
# If the comparison trial and the current trial have different
# Target Words, then the end of the STS that contains the
# current trial has been found.
# Hence, break out of this while-loop.
compare_trial = 0
endif
endwhile
# Use the 'position_in_STS' variable to determine the suffix of the
# current trial's Context labels.
if (position_in_STS == 1)
# If the current trial is the first trial in an STS, then the
# suffix of its Context labels is an empty string.
context_suffix$ = ""
else
# If the current trial is a non-initial trial in an STS, then
# the suffix of its Context labels reflects this.
context_suffix$ = "_ConsecTarget'position_in_STS'"
endif
# [TABLE OF XMIN AND XMAX VALUES FOR CURRENT TRIAL]
# Initialize a Praat Table object that records the xmin and xmax
# of each segmentation for the current trial.
if trial_word$ == "teddy bear"
# This handles the one case (so far) where the trial word has a space in it.
trial_segmentations_table$ = "Trial_'trial_number$'_teddy_bear"
else
trial_segmentations_table$ = "Trial_'trial_number$'_'trial_word$'"
endif
Create Table with column names... 'trial_segmentations_table$' 0 'tl_xmin$' 'tl_xmax$'
# [DURATION AND BOUNDARIES OF VISIBLE WAVEFORM]
# Initialize constants and variables that determine the duration
# and boundaries of the visible waveform in the Editor window.
# Set constants for the xmin and xmax of the audio Sound object.
select Sound 'audio_sound$'
audio_xmin = Get start time
audio_xmax = Get end time
# Set a constant for the duration of the waveform that is visible
# in the Editor window.
segment_window_dur = 10
# Set constants for the padding that is added to the left and right,
# respectively, of a trial's xmax boundary when the segmenter moves
# on to segment the next trial.
segment_newTrial_xmin_pad = 1
segment_newTrial_xmax_pad = 'segment_window_dur' - 'segment_newTrial_xmin_pad'
# Set constants for the padding that is added to the left and right,
# respectively, of a segmentation's xmax boundary when the segmenter
# confirms the boundary locations of that segmentation.
segment_selection_xmin_pad = 3
segment_selection_xmax_pad = 'segment_window_dur' - 'segment_selection_xmin_pad'
# Set constants for the padding that is added to the left and right,
# respectively, of a selection's xmin and xmax boundary when the
# Editor window zooms in on that selection to confirm it as a
# segmentable repetition.
segment_selection_zoom_pad = 1
mute_selection_zoom_pad = 1
trial_zoom_pad = 1
# Initialize variables for the start and end time of the Editor
# window, using the number of trials that have been segmented
# so far (ie. that were segmened in a previous session).
# Check the number of trials that have been segmented so far.
if (n_trials_segmented == 0)
# If no trials have been segmented so far, then the
# Audio-Anonymization Log table may provide some insight into
# how far the segmenter was able to progress in a previous
# session.
# Check if the Audio-Anonymization Log table includes any rows
# on it.
select Table 'audioLog_table$'
n_intervals_muted = Get number of rows
if (n_intervals_muted > 0)
# If at least one interval has been muted, then use the xmax
# boundary of the latest muted interval as the initial xmin
# value of the Editor window for this segmentation session.
# The initial xmax value is determined from the constant
# 'segment_window_dur'.
select Table 'audioLog_table$'
segment_window_xmin = Get value... 'n_intervals_muted' 'al_xmin$'
segment_window_xmax = 'segment_window_xmin' + 'segment_window_dur'
else
# If no intervals have been muted, then initialize the xmin
# value of the Editor window to the xmin of the audio Sound
# object, and let the xmax value be determined by the
# 'segment_window_dur' constant.