Praat脚本:将音节层与重音层一起提取并进行额外更改

时间:2018-01-07 12:25:46

标签: praat

我想提取音节和相应的重音符号。如果一个音节没有重音,则重音部分会出现“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层:

enter image description here

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

您可以通过几个步骤完成此操作。首先,在第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

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

'no'

作为最后一步,您需要从结果中删除这些额外的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") 。让我们在Python中做到这一点(提及你拥有的所有音高形状,所以程序知道你想要摆脱哪些线):

 <input id="groupSpinner" type="number" min="1" class="form-control" ng-model="targetEntity.concurrentAccessCount">