我正在编写一个 praat 脚本,它将在多个文件中搜索单词列表。这就是我到目前为止所拥有的。它只放大到过程中的第一个单词,而不遍历其余单词。我认为这与选择的内容有关。对于For i through n
,仅选择了文本网格,但随后在注释器中,两者都被选中。我需要脚本继续搜索每个间隔,以便也可以找到过程中的其他单词。
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!
编辑:这是根据答案修改后的脚本。
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