1

This is my first question and I do my best to be clear. I have browsed the site without finding any former question that could help me out.

I am trying to get the onset detection script in praat to loop for an entire directory. I have nested the onset detection script as an inner loop to an outer loop going through each file in a specific library. However, I can't seem to make it work. I only get the onset for the first file in my directory. The onset detection script works well on its own, and the outer loop works fine with other commands such as "get intensity" for example. Can anybody see what I am doing wrong?

Here is what I have done:

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

I would be happy for any help. If you read my question and feel it is badly formulated, please give me feedback on that so that I can try to get better. Kindly

  • You have an `exit` statement at the end of the second `for` loop. Your script exists as soon as it comes across a frame in any sound in which the value is greater than 40. Also, you are using the same control variable (`i`) twice. You'll need to use different variables. – jja Aug 04 '15 at 23:31

1 Answers1

0

You were using the same control variable for each for loop, so it was getting overwritten each time. You also had an exit where you wanted your script to jump out of the second for loop. But the exit statement stops the whole script, not the loop. To implement something like last or break you can manually increase the control variable past its end value. This is an example:

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
jja
  • 2,058
  • 14
  • 27