Quickstart

The goal of this package is to make the hierarchical and precedence relationships in TextGrids produced by forced alignment accessable and leverageable for analysis or recoding. You can find a quickstart for reading in a TextGrid on this page.

Reading in a single speaker TextGrid

To quickly read in 2 tiered textgrid, like those produced by the Montreal Forced Aligner, import the AlignedTextGrid class and the Word and Phone interval classes.

from aligned_textgrid import AlignedTextGrid
from aligned_textgrid import Word, Phone

AlignedTextGrid can take either a textgrid_path argument, or a textgrid argument for Textgrid objects that have already been created with praatio.

reading_passage = AlignedTextGrid(
    textgrid_path = "resources/josef-fruehwald_speaker.TextGrid",
    entry_classes=[Word, Phone]
)
reading_passage
AlignedTextGrid with 1 groups, each with [2] tiers. [['Word', 'Phone']]

A list of each tier is available at index 0.

reading_passage[0]
TierGroup with 2 tiers. ['Word', 'Phone']

You can access the specific tiers within a TierGroup with the name of the entry class.

reading_passage[0].Word
Sequence tier of Word; .superset_class: Top_wp; .subset_class: Phone

Multi-talker TextGrids

To read in a multi-talker textgrid, with the same Word,Phone organization for each speaker, the same approach works.

two_speaker = AlignedTextGrid(
    textgrid_path = "resources/KY25A_1.TextGrid",
    entry_classes=[Word, Phone]
)
two_speaker
AlignedTextGrid with 2 groups, each with [2, 2] tiers. [['Word', 'Phone'], ['Word', 'Phone']]

The first speakers’ tiers are available at index 0, and the second speakers tiers are available at index 1.

two_speaker[0]
TierGroup with 2 tiers. ['Word', 'Phone']
two_speaker[1]
TierGroup with 2 tiers. ['Word', 'Phone']

Accessing intervals

You can access intervals within a tier via ordinary indexing, looping, list comprehensions, etc.

for word in two_speaker[0].Word:
    print(word.label)

yeah

well
now

you

might

start
that

i
was
born
in

eighteen
sixty
seven

nintey
three

Reuse

GPLv3