将两层合并为一层的Praat
问题描述:
我在文本框中有两层,我想将它们合并到一个层中。每一层都是不同的说话者。每层内的间隔不重叠。这可能吗?我看到很多Praat脚本会合并或连接,但没有合并它们。我试图使用Python的tgt模块来做到这一点,但它是一个缓慢的去。我一直在挖掘一段时间,所以对如何解决这个问题的建议非常感谢!谢谢。将两层合并为一层的Praat
答
前一段时间,我写了a script,用于查找非重叠区间,也用于不同讲话人的层级。虽然任务不同,但脚本创建的TextGrid可以用于您想要的任何内容。
该脚本的逻辑是a procedure,可以将其包含到您正在使用的任何脚本中(或者如果您正在使用这种脚本,可以将其放入该脚本中)。
如果包含程序(无论是物理复制,或include
荷兰国际集团),你可以做
old = selected("TextGrid")
@toNonOverlappingTiers()
new = selected("TextGrid")
之后,new
TextGrid将有一个单层将全部来自其它层的间隔“扁平化“。具有非零标签的此新层中的每个间隔将代表最多一层中包含在带标签间隔中的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