praat

Praat scripting: How to extract intervals of different tiers corresponding to each other?


I have a TextGrid file with 2 tiers, one corresponds to words and another one to syllables. I already creating a column of syllables in my table and now I need to make a column with words where each syllable should correspond to the word it belongs to. So the result should look like:

e.g. This is my sentence.

This 
is
my
sentence 
sentence

(I can try to explain it more thoroughly, if it is not clear.)

This is what I have so far. It works, but needs some modification.

writeInfo: ""

selectObject: "TextGrid example"
num = Get number of intervals: 2 #for the syllable tier
number = Get number of intervals: 1 #for the word tier


for m from 1 to num
    ends = Get end time of interval: 2, m
    for n from 1 to number
        word$ = Get label of interval: 1, n
        endw = Get end time of interval: 1, n
        if ends == endw
            appendInfoLine: word$
        endif

    endfor
endfor

Solution

  • This should work. It loops through each syllable and gets the label of the corresponding interval on the word tier. It assumes there are no empty intervals. If you need to do further analysis, you can use writeFile and appenFileLine and write to a file rather then the Info window.

    writeInfo: ""
    
    selectObject: "TextGrid example"
    num = Get number of intervals: 2 #for the syllable tier
    
    for m from 1 to num
        syllable$ = Get label of interval: 2, m
        syllable_start = Get start time of interval: 2, m
        word = Get interval at time: 1, syllable_start
        word$ = Get label of interval: 1, word
        appendInfoLine: "'word$','syllable$'"
    endfor