# Label Menu # jm 2012-03-09 # # You can define your own set of labels (see customization section below). # Labels are presented as buttons or pop up menu. # Selecting a label and clicking the Insert button adds the selected label as intervall text # to the selected interval in the active tier. # The label menu remains visible until you finish the annotation of a file. # # Usage: # 1 - Select a Sound and a TextGrid object. # 2 - Run the script. # 3 - Add an interval and select it in the TextGrid editor. # 4 - Choose a label in the label menu and click Insert. # 5 - Repeat steps 3 and 4 until the end of the file. # 6 - Click Stop in the label menu. # Don't forget to save your TextGrid! ##### Start Customization ##### # List of labels [labels$], separated by a customizable separator [separator$] labels$ = "

,i:,I,y:,Y,e:,2:,E:,E,9,u:,U,o:,O,a,a:" separator$ = "," # Max number of labels shown as buttons. # If you have more labels than this they will be placed in a pop up menu and use up less screen space. maxlabels = 30 ##### End Customization ##### # Put the labels in an array [tag$] and count labels [nol] len = length (labels$) nol = 1 tag$ [1] = "" # Loop through the labels string for i to len # extract one character char$ = mid$ (labels$, i, 1) if char$ <> separator$ # add character to the current label tag$ ['nol'] = tag$ ['nol'] + char$ else # if character is separator, increase label count and initialize next label nol = nol+1 tag$ ['nol'] = "" endif endfor # Sloppy test of object window selection nos = numberOfSelected () if nos <> 2 exit Please select a Sound object and a TextGrid object. endif # Enquire names and object IDs name$ = selected$ ("Sound") gridID = selected ("TextGrid") Edit # Generate the label menu and process user interactions until Stop is clicked stop = 2 repeat # the label menu (implemented as pause window) beginPause ("Label menu") comment ("Add an interval and select it. Then choose a label and click Insert.") comment ("When finished click Stop to close the menu.") # buttons or pop up menu if nol <= maxlabels choice ("Label", 1) else optionMenu ("Label", 1) endif # generate options from labels for i to nol thistag$ = tag$ ['i'] option ("'thistag$'") endfor stop = endPause ("Stop", "Insert", 2, 1) # insert selected label if stop = 2 # enter editor environment editor TextGrid 'name$' # query selected interval intstart = Get starting point of interval intend = Get end point of interval intmid = intstart+((intend-intstart)/2) # Since we can't query the currently selected tier, we need to extract it, # enquire it's name and remove it. # Then we search the TextGrid for a tier with that name # and insert the label into this tier. Extract entire selected tier # leave editor environment endeditor tiername$ = selected$("TextGrid") Remove select gridID noti = Get number of tiers for i to noti tname$ = Get tier name... 'i' if tname$ = tiername$ tiernum = i endif endfor # now we can actually insert the selected label into the correct interval of the active tier intnum = Get interval at time... 1 'intmid' Set interval text... 1 'intnum' 'label$' endif until stop = 1