maeblythe

Insert Labels Praat Script

Sep 7th, 2024
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. # This script reads lines from a text file (edit filename$)
  2. # and adds them line by line as labels for intervals in a selected TextTier in the selected TextGrid object.
  3. #
  4. # You should check that the boundaries are correct before running the script.
  5. # The script will jump over intervals labeled as "_". Use this marking if there are intervals that
  6. # you will remove later.
  7. #
  8. #
  9. #this isn't my script but I wanted to be able to share my edits and make sure I had a backup.
  10. #find the original here: https://phonetics.linguistics.ucla.edu/facilities/acoustic/praat.html
  11. soundname$ = selected$ ("TextGrid", 1)
  12. select TextGrid 'soundname$'
  13. stringlength = 0
  14. filelength = 0
  15. firstnewline = 0
  16. oldlabel$ = ""
  17. newlabel$ = ""
  18.  
  19. filename$ = "D:\utay\diffsinger\labelstoinsert.txt"
  20. tier = 1
  21. starting_interval = 1
  22. overwrite = 1
  23.  
  24. if fileReadable (filename$)
  25. numberOfIntervals = Get number of intervals... tier
  26. if starting_interval > numberOfIntervals
  27. exit There are not that many intervals in the IntervalTier!
  28. endif
  29. leftoverlength = 0
  30. # Read the text file and put it to the string file$
  31. file$ < 'filename$'
  32. if file$ = ""
  33. exit The text file is empty.
  34. endif
  35. filelength = length (file$)
  36. leftover$ = file$
  37. # Loop through intervals from the selected interval on:
  38. for interval from starting_interval to numberOfIntervals
  39. oldlabel$ = Get label of interval... tier interval
  40. if oldlabel$ <> "_"
  41. # Here we read a line from the text file and put it to newlabel$:
  42. firstnewline = index (leftover$, newline$)
  43. newlabel$ = left$ (leftover$, (firstnewline - 1))
  44. leftoverlength = length (leftover$)
  45. leftover$ = right$ (leftover$, (leftoverlength - firstnewline))
  46. # Then we check if the interval label is empty. If it is or if we decided to overwrite,
  47. # we add the new label we collected from the text file:
  48. if overwrite = 1
  49. Set interval text... tier interval 'newlabel$'
  50. elsif oldlabel$ = ""
  51. Set interval text... tier interval 'newlabel$'
  52. else
  53. exit Stopped labeling, will not overwrite old labels!
  54. endif
  55. endif
  56. endfor
  57. else
  58. exit The label text file 'filename$' does not exist where it should!
  59. endif
Advertisement
Add Comment
Please, Sign In to add comment