我想把音节和相应的重音一起提取出来。如果一个音节没有重音,重音部分就会有"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层:
发布于 2018-06-06 17:46:58
您可以在几个步骤中做到这一点。首先,将额外的'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
然后,从第二层提取信息并保存到文件中:
#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'
。让我们用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-06 11:24:08
哦,以前是作为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
https://stackoverflow.com/questions/48137070
复制相似问题