from aligned_textgrid import AlignedTextGrid
from aligned_textgrid import Word, Phone
= AlignedTextGrid(
the_dog ="../resources/the_dog.TextGrid",
textgrid_path=[Word, Phone]
entry_classes )
Sequence Modification
Changing the label of a sequence is fairly straightforward. There are also .fuse_leftwards()
and .fuse_rightwards()
methods.
🚨 These sequence modification methods are destructive, and cannot be undone.
Changing a sequence label
We can change the label of a sequence with simple assignment.
= the_dog.tier_groups[0].tier_list[1].sequence_list[1] AH0
AH0.label
'AH0'
= "IY0"
AH0.label AH0
Class Phone, label: IY0, .superset_class: Word, .super_instance: the, .subset_class: Bottom_wp
Fusing Leftwards and Rightwards
You can also merge sequences together with .fuse_leftwards()
and .fuse_rightwards()
AH0.fuse_leftwards() AH0
Class Phone, label: DH IY0, .superset_class: Word, .super_instance: the, .subset_class: Bottom_wp
All of the relevant information and references are updated when this happens.
# precedence is updated
[AH0.prev.label, AH0.fol.label]
['#', '#']
# the superset instance is updated
len(AH0.inword)
1
AH0.inword.sub_labels
['DH IY0']
# the tier is updated
AH0.intier.labels
['DH IY0', 'D', 'AO1', 'G']
len(AH0.intier)
4
If you merge two sequences with subset lists, their subset lists get merged as well.
AH0.inword.fuse_rightwards()
AH0.inword.label
'the dog'
AH0.inword.sub_labels
['DH IY0', 'D', 'AO1', 'G']
1] AH0.inword[
Class Phone, label: D, .superset_class: Word, .super_instance: the dog, .subset_class: Bottom_wp
The fusion label
By default, .fuse_leftwards()
and .fuse_rightwards()
will append the two interval labels together separated by a space. You can adjust this behavior by passing label_fun
a fuction that takes two strings as input and returns a single string as output.
def my_dash_join(left, right):
return "-".join([left, right])
AH0.fol
Class Phone, label: D, .superset_class: Word, .super_instance: the dog, .subset_class: Bottom_wp
=my_dash_join) AH0.fuse_rightwards(label_fun
AH0
Class Phone, label: DH IY0-D, .superset_class: Word, .super_instance: the dog, .subset_class: Bottom_wp