0

我想提取音节和相应的重音。如果一个音节没有重音,重音部分就会有“no”。

我的编码示例如下所示:

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

结果应如下所示:

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

添加

第 1 层和第 2 层:

在此处输入图像描述

4

2 回答 2

0

糟糕,之前将其作为 tier2 的间隔层。现在作为点层:

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
于 2018-06-06T03:24:07.663 回答
0

您可以通过几个步骤做到这一点。'no'首先,在第 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

然后,从第 2 层提取信息并将其保存到文件中:

#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

作为最后一步,您需要'no'从结果中删除那些额外的 's。让我们在 Python 中执行此操作(提及您拥有的所有音高形状,以便程序知道您要删除哪些行):

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")
于 2018-06-06T09:46:57.550 回答