Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This script reads lines from a text file (edit filename$)
- # and adds them line by line as labels for intervals in a selected TextTier in the selected TextGrid object.
- #
- # You should check that the boundaries are correct before running the script.
- # The script will jump over intervals labeled as "_". Use this marking if there are intervals that
- # you will remove later.
- #
- #
- #this isn't my script but I wanted to be able to share my edits and make sure I had a backup.
- #find the original here: https://phonetics.linguistics.ucla.edu/facilities/acoustic/praat.html
- soundname$ = selected$ ("TextGrid", 1)
- select TextGrid 'soundname$'
- stringlength = 0
- filelength = 0
- firstnewline = 0
- oldlabel$ = ""
- newlabel$ = ""
- filename$ = "D:\utay\diffsinger\labelstoinsert.txt"
- tier = 1
- starting_interval = 1
- overwrite = 1
- if fileReadable (filename$)
- numberOfIntervals = Get number of intervals... tier
- if starting_interval > numberOfIntervals
- exit There are not that many intervals in the IntervalTier!
- endif
- leftoverlength = 0
- # Read the text file and put it to the string file$
- file$ < 'filename$'
- if file$ = ""
- exit The text file is empty.
- endif
- filelength = length (file$)
- leftover$ = file$
- # Loop through intervals from the selected interval on:
- for interval from starting_interval to numberOfIntervals
- oldlabel$ = Get label of interval... tier interval
- if oldlabel$ <> "_"
- # Here we read a line from the text file and put it to newlabel$:
- firstnewline = index (leftover$, newline$)
- newlabel$ = left$ (leftover$, (firstnewline - 1))
- leftoverlength = length (leftover$)
- leftover$ = right$ (leftover$, (leftoverlength - firstnewline))
- # Then we check if the interval label is empty. If it is or if we decided to overwrite,
- # we add the new label we collected from the text file:
- if overwrite = 1
- Set interval text... tier interval 'newlabel$'
- elsif oldlabel$ = ""
- Set interval text... tier interval 'newlabel$'
- else
- exit Stopped labeling, will not overwrite old labels!
- endif
- endif
- endfor
- else
- exit The label text file 'filename$' does not exist where it should!
- endif
Advertisement
Add Comment
Please, Sign In to add comment