I am writing a praat script that will search through multiple files for a list of words. This is what I have so far. It only zooms in to the first word in the procedure, and doesn't loop through the rest. I think this has something to do with what is selected. For the For i through n
, only the text grid is selected, but then in the annotator, both are selected. I need the script to continue searching through each interval so that the other words in the procedure can be found as well.
directory$ = "directory"
listfile$ = "test.txt"
Read Strings from raw text file... 'directory$'/'listfile$'
last = Get number of strings
# loop through each file
for a from 1 to last
listfile2$ = listfile$ - ".txt"
select Strings 'listfile2$'
textgrid$ = Get string... 'a'
Read from file... 'directory$'/'textgrid$'
object_name$ = selected$("TextGrid")
Read from file... 'directory$'/'object_name$'.wav
# rearrange tiers
select TextGrid 'object_name$'
Duplicate tier: 3, 1, "MAU"
Remove tier: 4
Insert interval tier: 1, "subphone"
# find target word
n = Get number of intervals: 3
for i to n
@instance: "strikes"
@instance: "raindrops"
@instance: "and"
@instance: "rainbow"
@instance: "into"
@instance: "round"
@instance: "its"
@instance: "its"
procedure instance: .target_word$
label$ = Get label of interval: 3, i
if label$ == .target_word$
index = i
i += n
# get the start and end point of the word
startpoint = Get starting point... 3 index
endpoint = Get end point... 3 index
select TextGrid 'object_name$'
plus Sound 'object_name$'
View & Edit
editor TextGrid 'object_name$'
# annotation
Select... startpoint endpoint
Zoom to selection
pause Annotate stops then continue
Close
endeditor
endif # if the label = target word
endfor # for number of intervals
select TextGrid 'object_name$'
Write to text file: directory$ + "/" + object_name$ + "_editedtext.TextGrid"
select all
minus Strings 'listfile2$'
Remove
endproc
#writeInfoLine: "done!"
#select Strings 'listfile2$'
endfor # for each of the files
clearinfo
print That's it!
Edit: Here's the revised script, based on the answer.
directory$ = "/Users/directorypath"
listfile$ = "test.txt"
Read Strings from raw text file... 'directory$'/'listfile$'
last = Get number of strings
listfile2$ = listfile$ - ".txt"
# loop through each file
for a from 1 to last
select Strings 'listfile2$'
textgrid$ = Get string... 'a'
Read from file... 'directory$'/'textgrid$'
object_name$ = selected$("TextGrid")
Read from file... 'directory$'/'object_name$'.wav
# rearrange tiers
select TextGrid 'object_name$'
Duplicate tier: 3, 1, "MAU"
Remove tier: 4
Insert interval tier: 1, "subphone"
n = Get number of intervals: 3
for i to n
@instance: "strikes"
@instance: "raindrops"
@instance: "and"
@instance: "rainbow"
@instance: "into"
@instance: "round"
@instance: "its"
@instance: "its"
endfor
endfor
procedure instance: .target_word$
label$ = Get label of interval: 3, i
if label$ == .target_word$
index = i
i += n
# get the start and end point of the word
startpoint = Get starting point... 3 index
endpoint = Get end point... 3 index
select TextGrid 'object_name$'
plus Sound 'object_name$'
View & Edit
editor TextGrid 'object_name$'
# annotation
Select... startpoint endpoint
Zoom to selection
pause Annotate stops then continue
Close
endeditor
endif
endproc