首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Praat脚本:提取音节层和带有额外更改的重音层

Praat脚本:提取音节层和带有额外更改的重音层
EN

Stack Overflow用户
提问于 2018-01-07 20:25:46
回答 2查看 370关注 0票数 0

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

我的编码示例如下所示:

代码语言:javascript
运行
复制
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

结果应该如下所示:

代码语言:javascript
运行
复制
"de:6       no
I           no
"Ra:n       H*L
"vIl        no
"an         no
"zaI        no
n@m         no
a:          no
"tOm        H*

添加

第1和第2层:

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-06-06 17:46:58

您可以在几个步骤中做到这一点。首先,将额外的'no'添加到第2层:

代码语言:javascript
运行
复制
#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

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

代码语言:javascript
运行
复制
#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语言来做这件事(提到你拥有的所有音调形状,这样程序就知道你想要去掉哪些线条):

代码语言:javascript
运行
复制
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")
票数 0
EN

Stack Overflow用户

发布于 2018-06-06 11:24:08

哦,以前是作为tier2的间隔层使用的。现在作为点层:

代码语言:javascript
运行
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48137070

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档