Praat将两层结合成一层

时间:2015-11-05 03:40:09

标签: praat

我在textgrid中有两个层,我想将它们组合成一个层。每一层都是不同的发言者。每层内的间隔不重叠。这可能吗?我已经看到很多Praat脚本会合并或连接但没有任何东西可以合并它们。我尝试使用Python tgt模块来做这件事,但这是一个缓慢的过程。我已经挖掘了一段时间,所以对于如何解决这个问题的任何建议都非常感谢!感谢。

1 个答案:

答案 0 :(得分:1)

前段时间我编写a script用于查找不重叠的区间,也用于不同发言者的层级。尽管任务不同,但脚本创建的TextGrid可以用于您想要的任务。

该脚本的逻辑位于a procedure,可以包含在您正在使用的任何脚本中(或者如果您已经进入那种事情,可以将其添加到其中)。

如果您包含该程序(要么进行物理复制或include),您可以

old = selected("TextGrid")
@toNonOverlappingTiers()
new = selected("TextGrid")

之后,new TextGrid会有一个单层,所有来自其他层的间隔都会缩小"。此新层中具有非零标签的每个间隔将表示最多一层中标记间隔中包含的old TextGrid的块。 old中的任何标记区间都未包含未标记的区间。其余标签会告诉您包含它们的唯一标记间隔的层数。

因此,在运行上面的示例后,您可以执行

# Loop through intervals in the new TextGrid
selectObject: new
for i to do("Get number of intervals...", 1)
  label$ = Get label of interval: 1, i
  # Since your original TextGrid had no overlapping intervals
  # you only want labeled intervals (there will be no zeros)
  if label$ != ""
    # Get the midpoint, to match to intervals in a different
    # tier in the original TextGrid
    tier = number(label$)
    start    = Get start point: 1, i
    end      = Get end point:   1, i
    midpoint = ((end - start) / 2) + start

    # Get the original label
    selectObject: old
    j = Get interval at time: tier, midpoint
    original$ = Get label of interval: tier, j

    # Apply the original label to the new TextGrid
    selectObject: new
    Set interval text: 1, i, original$
  endif
endfor

出于档案目的:

# This procedure is a part of the tgutils plugin
# Please see http://cpran.net/plugins/tgutils for more details
procedure toNonOverlappingIntervals ()
  # Original TextGrid
  .tg = selected("TextGrid")
  .tiers = Get number of tiers

  .start = Get start time
  .end = Get end time

  # Overlap TextGrid
  .id = Create TextGrid: .start, .end, "overlap", ""

  # Populate overlap tier with "flattened" intervals from all tiers
  for .tier to .tiers
    selectObject: .tg
    .intervals = Get number of intervals: .tier

    for .interval to .intervals-1
      selectObject: .tg
      .end = Get end point: .tier, .interval
      # We use nocheck because there might already be a boundary there
      selectObject: .id
      nocheck Insert boundary: 1, .end
    endfor

  endfor

  # Cycle through the flattened intervals to check how many spoken intervals
  # align with each. A segment in the overlap tier will be considered to have no
  # overlap if and only if there is one tier with a speech labeled interval which
  # coincides with it.

  selectObject: .id
  .flat_intervals = Get number of intervals: 1
  for .interval to .flat_intervals
    .start = Get start point: 1, .interval
    .end = Get end point: 1, .interval
    .midpoint = (.end - .start) / 2 + .start

    # Count how many speakers are speaking over that flattened interval
    .speakers = 0
    for .tier to .tiers
      selectObject: .tg
      .interval_number = Get interval at time: .tier, .midpoint
      .label$ = Get label of interval: .tier, .interval_number
      if .label$ != ""
        # Increment the number of speakers for each labeled coinciding interval
        # on any tier. We also save the tier number of the (last) speaker, so we
        # know where to look for measurements later.
        .speakers += 1
        .speaker_tier = .tier
      endif
    endfor

    # Label the overlap intervals. Blank intervals are matched by no speakers in
    # any tier. Intervals labeled "0" are matched by more than one speaker, in
    # more than one tier. The rest contain the tier number of the single speaker
    # speaking at that time.
    selectObject: .id
    if .speakers = 1
      Set interval text: 1, .interval, string$(.speaker_tier)
    elif .speakers > 1
      Set interval text: 1, .interval, "0"
    else
      Set interval text: 1, .interval, ""
    endif
  endfor

endproc