0

I want to extract syllables together with the corresponding accents. If a syllable doesn't have an accent, there will be "no" on the accent part.

My coding example looks like this:

writeInfo: ""

selectObject: "TextGrid example"

# syllable tier is 1
# accent tier is 2
number = Get number of intervals: 1
for i from 1 to number
syllable$ = Get label of intervals: 1, i 
# It seems to be not possible to get time of interval
# I want to get the time of the whole interval, like it's done with points
syllable_time = Get time of interval: 1, i
accent = Get point at time: 2, syllable_time
accent$ = Get label of point: 2, accent
    #if no accent$
    #appendInfoLine syllable$, "      ", "no"
    #elif accent$ <> "-" and accent$ <> "%"
    #appendInfoLine syllable$, "      ", accent$
    #endif
endfor

The result should look like this:

"de:6       no
I           no
"Ra:n       H*L
"vIl        no
"an         no
"zaI        no
n@m         no
a:          no
"tOm        H*

Adding

Layers 1 and 2:

enter image description here

dgr379
  • 353
  • 3
  • 13

2 Answers2

0

Oops, did it as an interval tier for tier2 before. Now as point tier:

objName$ = selected$ ("Sound")
select TextGrid 'objName$'

intervals_1 = Get number of intervals: 1
intervals_2 = Get number of points: 2

for i from 1 to intervals_1
 syl_1$ = Get label of interval: 1, i
 start_1 = Get start point: 1, i
 end_1 = Get end point: 1, i
 for j from 1 to intervals_2
  syl_2$ = Get label of point: 2, j
  time = Get time of point: 2, j
  if syl_1$ != "" and syl_2$ != "" and time > start_1 and time < end_1
   printline 'syl_1$' 'syl_2$'
  endif
 endfor
endfor
  • It works if the boundaries of the layers collide. I'm going to add the picture of my layers in the post. – dgr379 Jun 06 '18 at 09:30
  • Oh, somehow I didn't get a notification about your edit. As you can tell, my tier 2 is a point tier, not an interval tier like on your picture. So, your script gives an error. – dgr379 Jun 06 '18 at 20:01
  • @dgr379 - d'oh I missed that, then it's even simpler logic, I'll edit again. – acousticwug Jun 06 '18 at 21:00
  • You forgot to do something like this: `time > start_1 and time < end_1` `Insert point: 2, time, "no"` before extracting labels of point tier 2. – dgr379 Jun 07 '18 at 06:39
0

You can do that in a few steps. First, add an additional 'no' to layer 2:

#Select TexGrid
selectObject: 1

number = Get number of intervals: 1

for i from 1 to number
time_start = Get start point: 1, i
#time_end = Get end point: 1, i
name$ = Get label of interval: 1, i
point$ = Get label of point: 2, i

Insert point: 2, time_start, "no"
endfor

Then, extract the information from layer 2 and save it to a file:

#Select TextGrid
selectObject: 1

number = Get number of points: 2
for n from 1 to number
accent_time = Get time of point: 2, n
syllable = Get interval at time: 1, accent_time 
syllable$ = Get label of interval: 1, syllable
accent$ = Get label of point: 2, n

writeFileLine: "myFile.txt", accent$

endfor

As the last step, you need to remove those additional 'no''s from your outcome. Let's do that in Python (Mention all the pitch shapes you have, so the program knows what lines you want to get rid of):

fo = open("myFile.txt", "r")
st = fo.read();
lis = st.split()
fo.close()


for i, choice in enumerate(lis):
    if choice == 'H*L' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == 'H*' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == 'L*H' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == 'L%' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == 'H%' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == 'L*' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == '!H*L' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == '!H*' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == 'H*L?' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == '..L' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == 'L*HL' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == '*?' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == 'L*H?' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == 'H*?' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == '..H' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == 'L*?' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == '!H' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == 'H!' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == 'HH*L' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == '!H*L?' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == '.L' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == 'L*!H' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == 'L*HL?' and lis[i-1] == 'no':
        lis.pop(i-1)
    elif choice == 'LH*L' and lis[i-1] == 'no':
        lis.pop(i-1)


with open("output.txt", "w") as my_file:
    for i in lis:
        my_file.write(i + "\n")
dgr379
  • 353
  • 3
  • 13