【问题标题】:Praat scripting: Extracting syllable tier together with accent tier with extra changesPraat 脚本:提取音节层和重音层并进行额外更改
【发布时间】:2018-06-07 05:01:08
【问题描述】:

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

【问题讨论】:

    标签: praat


    【解决方案1】:

    您只需几个步骤即可完成。首先,在第 2 层添加一个额外的'no'

    #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'。让我们在 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")
    

    【讨论】:

      【解决方案2】:

      糟糕,之前是作为 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
      

      【讨论】:

      • 如果图层的边界发生冲突,它会起作用。我将在帖子中添加我的图层图片。
      • 哦,不知何故我没有收到有关您的编辑的通知。如您所知,我的第 2 层是点层,而不是像您图片上的间隔层。所以,你的脚本出错了。
      • @dgr379 - 哦,我错过了,然后它的逻辑更简单,我会再次编辑。
      • 在提取点层 2 的标签之前,您忘记执行以下操作:time &gt; start_1 and time &lt; end_1 Insert point: 2, time, "no"
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-01
      • 1970-01-01
      • 2011-04-25
      相关资源
      最近更新 更多