praat

Praat scripting: How to extract max of pitch for every syllable?


I want to extract the maximum pitch for every syllable. I have a piece of code, but it throws an error:

writeInfoLine: ""

selectObject: "TextGrid example", "Pitch example"

# syllable tier is 1 
number = Get number of intervals: 1
for i from 1 to number
name$ = Get label of interval: 1, i
start_time = Get start time of interval: 1, i
end_time = Get end time of interval: 1, i
max_pitch = Get maximum: start_time, end_time, "Hertz", "Parabolic"
appendInfoLine: name$, "      ", max_pitch
endfor

Solution

  • Here's a script with instructions on how to run it. It jumps back and forth between your TextGrid and Pitch object.

    # open your wav file and textgrid into objects window
    # select wav file
    # run script
    
    clearinfo
    
    objName$ = selected$ ("Sound")
    To Pitch: 0, 75, 600
    
    select TextGrid 'objName$'
    intervals = Get number of intervals: 1
    
    printline 'intervals' intervals in textgrid
    
    for i from 1 to intervals
     # need var$ because it's a string
     lab$ = Get label of interval: 1, i
     start = Get start time of interval: 1, i
     end = Get end time of interval: 1, i
     # now look at the Intensity object
     select Pitch 'objName$'
     max = Get maximum: start, end, "Hertz", "Parabolic"
     printline 'start' 'end' 'lab$' 'max'
     # reset for next iteration
     select TextGrid 'objName$'
    endfor