Points

Praat points are represented using the SequencePoint class, which is much less constrained than the SequenceInterval class. They don’t have hierarchical relationships defined, and the same SequencePoint subclass can exist within a single SequencePointTier.

from aligned_textgrid import SequencePoint, SequenceInterval, \
    SequenceTier, SequencePointTier, \
        AlignedTextGrid
from aligned_textgrid import custom_classes

To read in a TextGrid with a mixture of intervals and points (download link), you’ll need to provide both SequenceInterval and SequencePoint entry classes. Both can be created with the custom_classes() function. By default, a list of strings will create SequenceInterval subclasses, but you can add indicies of which classes should be SequencePoint subclasses.

Word, Phone = custom_classes(["Word", "Phone"])
Ranges = custom_classes("Ranges")

ToBI, PrStr, TurningPoints, Levels = custom_classes(
    ["ToBI", "PrStr", "TurningPoints", "Levels"], 
    points=[0, 1, 2, 3]
)

Now you can read in the TextGrid using these custom classes. entry_classes should be a list of list indicating how the tiers are nested (or not.)

tg = AlignedTextGrid(
    textgrid_path = "../resources/amelia_knew2-basic.TextGrid",
    entry_classes = [
        [Word, Phone],
        [ToBI, PrStr, TurningPoints, Levels],
        [Ranges]
    ]
)
tg
AlignedTextGrid with 3 groups, each with [2, 4, 1] tiers. [['Word', 'Phone'], ['ToBI', 'PrStr', 'TurningPoints', 'Levels'], ['Ranges']]

Useful SequencePoint attributes

The most useful attributes of a SequencePoint will be its .label and its .time

example_point = levels_tier[1]

example_point.label
'1'
example_point.time
0.20235139465888988

The labels and times of all points in a SequencePointTier can be accessed with .labels and .times.

# accessing the parent tier
example_point.intier.labels
['2', '1', '5', '1', '1', '3']
example_point.intier.times
array([0.08467382, 0.20235139, 0.36102389, 0.51020478, 0.73123339,
       0.83802   ])

There are also attributes giving the distance between the current point and its .fol and .prev point.

example_point.fol_distance
0.15867249135026215
example_point.prev_distance
-0.11767757671157641

Useful SequencePointMethods

With the .get_interval_at_time() method, you can get the interval a point falls within if passed a SequenceTier.

phone_tier = tg[0][1]
phone_tier.labels
['', '\\sw', 'm', 'i', 'l', 'j', '\\sw', 'n', 'u', '\\sw', 'm', '']
example_point.get_interval_at_point(phone_tier)
Class Phone, label: i, .superset_class: Word, .super_instance: Amelia, .subset_class: Bottom_1

If passed any given SequenceInterval or SequencePoint, the .distance_from() method will give the distance from the current point.

example_interval = example_point.get_interval_at_point(phone_tier)

example_point.distance_from(example_interval)
array([ 0.01603854, -0.11062785])
example_point.distance_from(example_interval.fol)
array([-0.11062785, -0.18968809])

Reuse

GPLv3