Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Praat script to get pitch contour of a Sound object and output in CSV format
- # Each line in the CSV output starts with the name of the Sound object, followed
- # by a series of pitch values in Hz.
- # To use this script, start by selecting the Sound objects that you want to
- # sample the pitch for. Then, paste everything here into the script editor
- # window and press Ctrl-R (or Command-R on Mac).
- # Write nothing with writeInfoLine to clear the program output
- writeInfoLine: ""
- # Number of points in each Sound object that we want to take the pitch of
- numPitchPoints = 5
- # Tell Praat to "remember" all currently selected Sound objects
- # Praat will store them as a list of Sound objects
- sounds# = selected# ("Sound")
- # Iterate over each Sound object in the list
- for n to size (sounds#)
- # Select the nth Sound from the list
- selectObject: sounds#[n]
- # Get the name of the current Sound
- soundName$ = selected$ ()
- # Test if name is untitled
- if soundName$ == "Sound untitled"
- # Write it at the start of our current line of output, followed by a comma
- appendInfo: soundName$
- appendInfo: ","
- # Remember the total duration of this Sound
- totalDuration = Get total duration
- # Create Pitch object fromthis Sound
- # The 3 arguments below are time step (sec), pitch floor (Hz), and
- # pitch ceiling (Hz)
- To Pitch: 0.1, 75.0, 600.0
- # Iterate over each point of time in the Pitch object
- for idx from 0 to (numPitchPoints - 1)
- # Calculate a timestamp proportional to the total duration of the Sound
- timeRatio = (idx / numPitchPoints)
- timestamp = totalDuration * timeRatio
- # Get pitch in Hz, using linear interpolation
- pitch = Get value at time: timestamp, "Hertz", "Linear"
- if pitch == undefined
- pitch = -1
- endif
- # Write the pitch to the current line of our program output
- # Add a comma after each pitch output (this will be useful later in R)
- appendInfo: pitch
- appendInfo: ","
- endfor
- # Remove pitch object after we are done
- Remove
- # Start a new line of output for the next Sound object
- appendInfoLine: ""
- endif
- endfor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement