如何让嵌套循环在 Praat 中工作以检测整个目录中的开始?
How can I get nested loops to work in Praat to detect onset in an entire directory?
这是我的第一个问题,我会尽力说清楚。我浏览了该网站,但没有找到任何可以帮助我解决问题的问题。
我正在尝试让 praat 中的开始检测脚本循环整个目录。我将起始检测脚本作为一个内循环嵌套到一个外循环,该外循环遍历特定库中的每个文件。但是,我似乎无法让它发挥作用。我只得到目录中第一个文件的开头。
开始检测脚本本身运行良好,外循环与其他命令一起运行良好,例如 "get intensity"。
谁能看到我做错了什么?
这是我所做的:
form Get Intensity
sentence Directory .\
comment If you want to analyze all the files, leave this blank
word Base_file_name
comment The name of result file
text textfile intensity_VOT_list.txt
endform
#Print one set of headers
fileappend "'textfile$'" File name'tab$'
fileappend "'textfile$'" 'newline$'
Create Strings as file list... wavlist 'directory$'/'base_file_name$'*.wav
n = Get number of strings
for i from 1 to n
select Strings wavlist
filename$ = Get string... i
Read from file... 'directory$'/'filename$'
soundname$ = selected$ ("Sound")
To Intensity... 100 0
labelline$ = "'soundname$''tab$'"
fileappend "'textfile$'" 'labelline$'
select Intensity 'soundname$'
numberOfFrames = Get number of frames
fileappend "'textfile$'" 'numberOfFrames'
fileappend "'textfile$'" 'newline$'
for i from 1 to numberOfFrames
intensity = Get value in frame: i
if intensity > 40
time = Get time from frame: i
onsetresultline$ = "voice onset time for 'soundname$' is 'tab$''time''tab$'"
fileappend "'textfile$'" 'onsetresultline$'
fileappend "'textfile$'" 'newline$'
exit
endif
endfor
endfor
我很乐意提供任何帮助。如果您阅读我的问题并觉得它的表述不当,请给我反馈,以便我可以努力变得更好。
亲切
您在每个 for
循环中使用相同的控制变量,因此每次都会被覆盖。您还有一个 exit
,您希望您的脚本跳出第二个 for 循环。但是 exit
语句停止了整个脚本,而不是循环。要实现 last
或 break
之类的功能,您可以手动将控制变量增加到超过其最终值。这是一个例子:
form Get Intensity
sentence Directory .\
comment If you want to analyze all the files, leave this blank
word Base_file_name
comment The name of result file
text textfile intensity_VOT_list.txt
endform
#Print one set of headers
fileappend "'textfile$'" File name'tab$'
fileappend "'textfile$'" 'newline$'
strings_object = Create Strings as file list... wavlist 'directory$'/'base_file_name$'*.wav
n = Get number of strings
for i to n
select strings_object
filename$ = Get string... i
Read from file... 'directory$'/'filename$'
soundname$ = selected$ ("Sound")
intensity_object = To Intensity... 100 0
labelline$ = "'soundname$''tab$'"
fileappend "'textfile$'" 'labelline$'
select intensity_object
numberOfFrames = Get number of frames
fileappend "'textfile$'" 'numberOfFrames'
fileappend "'textfile$'" 'newline$'
for j to numberOfFrames ; Renamed your second i into j
intensity = Get value in frame: j
if intensity > 40
time = Get time from frame: j
onsetresultline$ = "voice onset time for 'soundname$' is 'tab$''time''tab$'"
fileappend "'textfile$'" 'onsetresultline$'
fileappend "'textfile$'" 'newline$'
j += numberOfFrames ; This will break out of the loop
endif
endfor
endfor
这是我的第一个问题,我会尽力说清楚。我浏览了该网站,但没有找到任何可以帮助我解决问题的问题。
我正在尝试让 praat 中的开始检测脚本循环整个目录。我将起始检测脚本作为一个内循环嵌套到一个外循环,该外循环遍历特定库中的每个文件。但是,我似乎无法让它发挥作用。我只得到目录中第一个文件的开头。 开始检测脚本本身运行良好,外循环与其他命令一起运行良好,例如 "get intensity"。 谁能看到我做错了什么?
这是我所做的:
form Get Intensity
sentence Directory .\
comment If you want to analyze all the files, leave this blank
word Base_file_name
comment The name of result file
text textfile intensity_VOT_list.txt
endform
#Print one set of headers
fileappend "'textfile$'" File name'tab$'
fileappend "'textfile$'" 'newline$'
Create Strings as file list... wavlist 'directory$'/'base_file_name$'*.wav
n = Get number of strings
for i from 1 to n
select Strings wavlist
filename$ = Get string... i
Read from file... 'directory$'/'filename$'
soundname$ = selected$ ("Sound")
To Intensity... 100 0
labelline$ = "'soundname$''tab$'"
fileappend "'textfile$'" 'labelline$'
select Intensity 'soundname$'
numberOfFrames = Get number of frames
fileappend "'textfile$'" 'numberOfFrames'
fileappend "'textfile$'" 'newline$'
for i from 1 to numberOfFrames
intensity = Get value in frame: i
if intensity > 40
time = Get time from frame: i
onsetresultline$ = "voice onset time for 'soundname$' is 'tab$''time''tab$'"
fileappend "'textfile$'" 'onsetresultline$'
fileappend "'textfile$'" 'newline$'
exit
endif
endfor
endfor
我很乐意提供任何帮助。如果您阅读我的问题并觉得它的表述不当,请给我反馈,以便我可以努力变得更好。 亲切
您在每个 for
循环中使用相同的控制变量,因此每次都会被覆盖。您还有一个 exit
,您希望您的脚本跳出第二个 for 循环。但是 exit
语句停止了整个脚本,而不是循环。要实现 last
或 break
之类的功能,您可以手动将控制变量增加到超过其最终值。这是一个例子:
form Get Intensity
sentence Directory .\
comment If you want to analyze all the files, leave this blank
word Base_file_name
comment The name of result file
text textfile intensity_VOT_list.txt
endform
#Print one set of headers
fileappend "'textfile$'" File name'tab$'
fileappend "'textfile$'" 'newline$'
strings_object = Create Strings as file list... wavlist 'directory$'/'base_file_name$'*.wav
n = Get number of strings
for i to n
select strings_object
filename$ = Get string... i
Read from file... 'directory$'/'filename$'
soundname$ = selected$ ("Sound")
intensity_object = To Intensity... 100 0
labelline$ = "'soundname$''tab$'"
fileappend "'textfile$'" 'labelline$'
select intensity_object
numberOfFrames = Get number of frames
fileappend "'textfile$'" 'numberOfFrames'
fileappend "'textfile$'" 'newline$'
for j to numberOfFrames ; Renamed your second i into j
intensity = Get value in frame: j
if intensity > 40
time = Get time from frame: j
onsetresultline$ = "voice onset time for 'soundname$' is 'tab$''time''tab$'"
fileappend "'textfile$'" 'onsetresultline$'
fileappend "'textfile$'" 'newline$'
j += numberOfFrames ; This will break out of the loop
endif
endfor
endfor