I have two tiers within a textgrid and I'd like to combine them into one tier. Each tier is a different speaker. The intervals within each tier don't overlap. Is this possible? I've seen a lot of Praat scripts that will merge or concatenate but nothing to combine them. I've trying to use the Python tgt module to do this but it's been a slow go. I've been digging for a while so any suggestions on how to attack this problem are greatly appreciated! Thanks.
问问题
700 次
1 回答
1
前段时间,我编写了一个脚本,用于查找不重叠的间隔,也在不同扬声器的层级中。尽管任务不同,但脚本创建的 TextGrid 可用于您想要的。
该脚本的逻辑是在一个过程中,该过程可以包含在您正在使用的任何脚本中(或者如果您喜欢那种东西,可以将其包含在其中)。
如果您包含该过程(物理复制或复制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
于 2015-11-05T11:39:26.940 回答