【问题标题】:How can I get nested loops to work in Praat to detect onset in an entire directory?如何让嵌套循环在 Praat 中工作以检测整个目录中的开始?
【发布时间】:2015-08-05 07:44:10
【问题描述】:

这是我的第一个问题,我会尽力说清楚。我浏览了该网站,但没有找到任何可以帮助我的问题。

我正在尝试让 praat 中的发病检测脚本循环整个目录。我已将发病检测脚本作为内循环嵌套到遍历特定库中每个文件的外循环。但是,我似乎无法让它工作。我只得到我目录中第一个文件的开始。 发病检测脚本本身运行良好,外部循环与其他命令(例如“获取强度”)一起运行良好。 谁能看到我做错了什么?

这是我所做的:

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 语句。只要在任何声音中遇到值大于 40 的帧,您的脚本就会存在。此外,您使用了相同的控制变量 (i) 两次。您需要使用不同的变量。

标签: nested-loops praat


【解决方案1】:

您对每个 for 循环使用相同的控制变量,因此每次都会被覆盖。您还有一个exit,您希望您的脚本在其中跳出第二个 for 循环。但是exit 语句会停止整个脚本,而不是循环。要实现lastbreak 之类的东西,您可以手动将控制变量增加到超过其最终值。这是一个例子:

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

【讨论】:

    猜你喜欢
    • 2020-11-08
    • 2022-06-25
    • 1970-01-01
    • 2017-05-13
    • 1970-01-01
    • 2018-11-05
    • 1970-01-01
    • 2011-04-17
    • 2010-12-04
    相关资源
    最近更新 更多