form output filename
    sentence output result.txt
endform

sound$ = Read from file: "sound/dhl_part.wav"
textgrid$ = Read from file: "sound/dhl_part.TextGrid"

############################
### MAKE Intensity Object  #
############################
selectObject: "Sound dhl_part"
To Intensity: 100, 0.0, 1

# Select TextGrid file

selectObject: "TextGrid dhl_part"

# Find out how many intervals there are in tier 2
num_intervals = Get number of intervals... 2

# Add name for F0
writeInfoLine: "phone",tab$,"word",tab$,"dB"

# to the output file
writeFileLine: output$, "phone",tab$,"word",tab$,"dB"

# Loop the interval tiers
for i from 1 to num_intervals

    phone$ = Get label of interval: 2, i

    if phone$ == "ae" or phone$ == "ei"
       ... or phone$ == "eh" or phone$ == "iy"

        startTime = Get start point: 2, i
        endTime = Get end point: 2, i
        midTime = startTime + (endTime - startTime)/2
        phone_duration = (endTime - startTime)*1000


       #################
        # IDENTIFY WORD 
        ################
        word_index = Get interval at time: 1, midTime
        word$ = Get label of interval: 1, word_index
        word_start = Get starting point: 1, word_index
        word_end = Get end point: 1, word_index
        word_duration = (word_end - word_start)*1000

        appendInfo: phone$,tab$,word$,tab$
        # output
        appendFile: output$, phone$,tab$,word$,tab$

        ########################
        # Measure Intensity (dB)
        ########################
        selectObject: "Intensity dhl_part"
        dB = Get mean: startTime, endTime, "dB"

        appendInfoLine: fixed$(dB,2)
        #output
        appendFileLine: output$, fixed$(dB,2)

        selectObject: "TextGrid dhl_part"

    endif
endfor