from aligned_textgrid import AlignedTextGrid, custom_classes
Modifying a Textgrid
You can modify a textgrid by adding an additional entry class with the .interleave_class()
method.
= AlignedTextGrid(
two_speaker = "../resources/KY25A_1.TextGrid",
textgrid_path = custom_classes(["Word", "Phone"])
entry_classes
)
two_speaker
AlignedTextGrid with 2 groups named ['KY25A', 'IVR'] each with [2, 2] tiers. [['Word', 'Phone'], ['Word', 'Phone']]
If we wanted to add a syllable layer in between the Word
and Phone
tier, we could do so like this.
two_speaker.interleave_class(= "Syllable",
name = "Phone",
above #below = "Word",
= "below",
timing_from = True
copy_labels )
two_speaker
AlignedTextGrid with 2 groups named ['KY25A', 'IVR'] each with [3, 3] tiers. [['Word', 'Syllable', 'Phone'], ['Word', 'Syllable', 'Phone']]
Now, you can begin building syllables on the Syllable tier using fuse methods. Here’s the first step.
import re
for speaker in two_speaker:
for interval in speaker.Syllable:
if re.match(r"[AEIOU]", interval.label):
if not (re.match(r"[AEIOU]", interval.prev.label) or
== "NG" or
interval.prev.label == "#"):
interval.prev.label
interval.fuse_leftwards()
0].Word[10].contains two_speaker[
[Class Syllable, label: S, .superset_class: Word, .super_instance: start, .subset_class: Phone, .subset_list: ['S'],
Class Syllable, label: T AA1, .superset_class: Word, .super_instance: start, .subset_class: Phone, .subset_list: ['T', 'AA1'],
Class Syllable, label: R, .superset_class: Word, .super_instance: start, .subset_class: Phone, .subset_list: ['R'],
Class Syllable, label: T, .superset_class: Word, .super_instance: start, .subset_class: Phone, .subset_list: ['T']]
Reuse
GPLv3