Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. # Praat script to get pitch contour of a Sound object and output in CSV format
  2. # Each line in the CSV output starts with the name of the Sound object, followed
  3. # by a series of pitch values in Hz.
  4. # To use this script, start by selecting the Sound objects that you want to
  5. # sample the pitch for. Then, paste everything here into the script editor
  6. # window and press Ctrl-R (or Command-R on Mac).
  7.  
  8.  
  9.  
  10. # Write nothing with writeInfoLine to clear the program output
  11. writeInfoLine: ""
  12.  
  13. # Number of points in each Sound object that we want to take the pitch of
  14. numPitchPoints = 5
  15.  
  16. # Tell Praat to "remember" all currently selected Sound objects
  17. # Praat will store them as a list of Sound objects
  18. sounds# = selected# ("Sound")
  19.  
  20. # Iterate over each Sound object in the list
  21. for n to size (sounds#)
  22. # Select the nth Sound from the list
  23. selectObject: sounds#[n]
  24.  
  25. # Get the name of the current Sound
  26. soundName$ = selected$ ()
  27.  
  28. # Test if name is untitled
  29. if soundName$ == "Sound untitled"
  30. # Write it at the start of our current line of output, followed by a comma
  31. appendInfo: soundName$
  32. appendInfo: ","
  33.  
  34. # Remember the total duration of this Sound
  35. totalDuration = Get total duration
  36.  
  37. # Create Pitch object fromthis Sound
  38. # The 3 arguments below are time step (sec), pitch floor (Hz), and
  39. # pitch ceiling (Hz)
  40. To Pitch: 0.1, 75.0, 600.0
  41.  
  42. # Iterate over each point of time in the Pitch object
  43. for idx from 0 to (numPitchPoints - 1)
  44. # Calculate a timestamp proportional to the total duration of the Sound
  45. timeRatio = (idx / numPitchPoints)
  46. timestamp = totalDuration * timeRatio
  47.  
  48. # Get pitch in Hz, using linear interpolation
  49. pitch = Get value at time: timestamp, "Hertz", "Linear"
  50. if pitch == undefined
  51. pitch = -1
  52. endif
  53.  
  54. # Write the pitch to the current line of our program output
  55. # Add a comma after each pitch output (this will be useful later in R)
  56. appendInfo: pitch
  57. appendInfo: ","
  58. endfor
  59.  
  60. # Remove pitch object after we are done
  61. Remove
  62.  
  63. # Start a new line of output for the next Sound object
  64. appendInfoLine: ""
  65. endif
  66. endfor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement