1

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
dgr379
  • 353
  • 3
  • 13
  • Can you please add a Minimal Working Example with the code of the script you already have, so we can build from it? – Stefano Jan 06 '18 at 13:00
  • @Stefano I've added what I have come up with so far. – dgr379 Jan 06 '18 at 16:47
  • I would rather loop through the words and extract the syllables for each word, although now I am not sure what you are trying to achieve. Are you aiming at having a file with two columns, one indicatinf a syllable and one indicating which word the syllable is from? – Stefano Jan 06 '18 at 17:43
  • @Stefano You are right. So now I'll have a column of words with some of them repeated if it's a more than one-syllable word. – dgr379 Jan 06 '18 at 17:58

1 Answers1

4

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
Stefano
  • 1,405
  • 11
  • 21