1

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

我试图让 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

我很乐意提供任何帮助。如果您阅读了我的问题并觉得它的表述很糟糕,请给我反馈,以便我可以尝试变得更好。亲切地

4

1 回答 1

0

您为每个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
于 2015-08-04T23:44:10.727 回答