from aligned_textgrid import SequencePoint, SequenceInterval, \
\
SequenceTier, SequencePointTier,
AlignedTextGridfrom aligned_textgrid import custom_classes
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
.
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.
= custom_classes(["Word", "Phone"])
Word, Phone = custom_classes("Ranges")
Ranges
= custom_classes(
ToBI, PrStr, TurningPoints, Levels "ToBI", "PrStr", "TurningPoints", "Levels"],
[=[0, 1, 2, 3]
points )
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.)
= AlignedTextGrid(
tg = "../resources/amelia_knew2-basic.TextGrid",
textgrid_path = [
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
= levels_tier[1]
example_point
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
.
= tg[0][1] phone_tier
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_point.get_interval_at_point(phone_tier)
example_interval
example_point.distance_from(example_interval)
array([ 0.01603854, -0.11062785])
example_point.distance_from(example_interval.fol)
array([-0.11062785, -0.18968809])