textgrid-formants.praat 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/praat --run
  2. # Read in the sound and textgrid files passed as command line arguments.
  3. form File
  4. sentence soundfile
  5. sentence textgrid
  6. endform
  7. Read from file... 'soundfile$'
  8. sound$ = selected$("Sound")
  9. Read from file... 'textgrid$'
  10. textGrid$ = selected$("TextGrid")
  11. # Loop through the textgrid and print the words along with their start times.
  12. appendInfoLine: "Words:"
  13. select TextGrid 'textGrid$'
  14. numberOfWords = Get number of intervals: 1
  15. for i from 1 to numberOfWords
  16. select TextGrid 'textGrid$'
  17. word$ = Get label of interval: 1, i
  18. startTime = Get start point: 1, i
  19. endTime = Get end point: 1, i
  20. appendInfoLine: startTime, " ", word$
  21. endfor
  22. # Loop through the textgrid's phonemes, and print the formant values at the midpoint.
  23. select TextGrid 'textGrid$'
  24. numberOfPhonemes = Get number of intervals: 2
  25. select Sound 'sound$'
  26. To Pitch: 0, 75, 600
  27. select Sound 'sound$'
  28. To Formant (burg)... 0 5 5000 0.025 50
  29. appendInfoLine: "Phonemes:"
  30. for i from 1 to numberOfPhonemes
  31. select TextGrid 'textGrid$'
  32. phoneme$ = Get label of interval: 2, i
  33. startTime = Get start point: 2, i
  34. endTime = Get end point: 2, i
  35. duration = endTime - startTime
  36. midpoint = startTime + duration/2
  37. select Pitch 'sound$'
  38. f0 = Get value at time... midpoint Hertz Linear
  39. select Formant 'sound$'
  40. f1 = Get value at time... 1 midpoint Hertz Linear
  41. f2 = Get value at time... 2 midpoint Hertz Linear
  42. f3 = Get value at time... 3 midpoint Hertz Linear
  43. appendInfoLine: startTime, " ", phoneme$, " ", f0, " ", f1, " ", f2, " ", f3
  44. endfor