aligned_textgrid.AlignedTextGrid(self, textgrid=None, entry_classes=[SequenceInterval], *, textgrid_path=None)
An aligned Textgrid
Parameters
textgrid
str | Path | praatio
.textgrid
.Textgrid
| Sequence [TierGroup | PointsGroup ]
An object to create a new AlignedTextGrid which can be one of: i) A path-like value (str|pathlib.Path) to a TextGrid file. ii) A praatio.textgrid.TextGrid object. iii) A list of TierGroup
s
None
entry_classes
Sequence [Sequence [Type [SequenceInterval ]]] | Sequence [Type [SequenceInterval ]]
If a single list of SequenceInterval
subclasses is given, they will be repeated as many times as necessary to assign a class to every tier. So if there are three speakers, each with a word and phone tier, [Word, Phone]
will process them each into a tier group. If your TextGrids are more complex, provide a nested list with the class for each tier within each tier group. Say, if only the first speaker had both a word and phone tier, and the remaining two had only a word tier, [[Word, Phone], [Word], [Word]]
[SequenceInterval]
Attributes
entry_classes
list[Sequence[Type[SequenceInterval]]] | list[]
The entry classes for each tier within a tier group.
tier_groups
list[TierGroup] | list[]
A list of TierGroup
or an empty list.
tier_names
list [str ]
A list of names for tiers in tier_groups.
xmax
float
Maximum time
xmin
float
Minimum time
[]
indexable
Methods
append
aligned_textgrid.AlignedTextGrid.append(tier_group)
Append a new TierGroup to an existing AlignedTextGrid.
Examples
from aligned_textgrid import Word, Phone, SequenceTier, TierGroup, AlignedTextGrid
speaker1 = TierGroup([
SequenceTier([
Word((0 ,10 , "Hi" ))
]),
SequenceTier([
Phone((0 ,5 , "HH" )),
Phone((5 ,10 , "AY" ))
])
])
speaker2 = TierGroup([
SequenceTier([
Word((10 ,20 , "Hi" ))
]),
SequenceTier([
Phone((10 ,15 , "HH" )),
Phone((15 ,20 , "AY" ))
])
])
atg = AlignedTextGrid()
atg.append(speaker1)
atg.append(speaker2)
print (atg)
AlignedTextGrid with 2 groups named ['group_0', 'group_1'] each with [2, 2] tiers. [['Word', 'Phone'], ['Word', 'Phone']]
Parameters
tier_group
TierGroup
The TierGroup to append to the AlignedTextGrid
required
cleanup
aligned_textgrid.AlignedTextGrid.cleanup()
Cleanup gaps in AlignedTextGrid
If any tiers have time gaps between intervals, missing subset or superset intervals or TierGroups with different start and ent times, this will clean them up by adding intervals with a blank label.
get_class_by_name
aligned_textgrid.AlignedTextGrid.get_class_by_name(class_name)
Get an entry class by name
Parameters
class_name
str
The requested entry class
required
get_intervals_at_time
aligned_textgrid.AlignedTextGrid.get_intervals_at_time(time)
Get interval indices at time
Returns a nested list of intervals at time
for each tier.
interleave_class
aligned_textgrid.AlignedTextGrid.interleave_class(name, above=None, below=None, timing_from='below', copy_labels=True)
Interleave a new entry class.
You can set either above
or below
, but not both.
Parameters
name
str
Name of the new class
required
above
Type [SequenceInterval ] | str
Which entry class to interleave above.
None
below
Type [SequenceInterval ] | str
Which entry class to interleave below.
None
timing_from
Literal [‘above’, ‘below’]
Which tier to draw timing from. Defaults to “below”.
'below'
copy_labels
bool
Whether or not to copy labels from the tier providing timing information. Defaults to True.
True
Examples
from aligned_textgrid import AlignedTextGrid, Word, Phone
atg = AlignedTextGrid(
textgrid_path = "../usage/resources/josef-fruehwald_speaker.TextGrid" ,
entry_classes = [Word, Phone]
)
print (atg)
AlignedTextGrid with 1 groups named ['group_0'] each with [2] tiers. [['Word', 'Phone']]
atg.interleave_class(
name = "Syllable" ,
above = "Phone" ,
timing_from = "below" ,
copy_labels = True
)
print (atg)
AlignedTextGrid with 1 groups named ['group_0'] each with [3] tiers. [['Word', 'Syllable', 'Phone']]
pop_class
aligned_textgrid.AlignedTextGrid.pop_class(name)
Pop a class from an AlignedTextGrid
Remove a class of tiers from an AlignedTextGrid
Examples
from aligned_textgrid import AlignedTextGrid, custom_classes
atg = AlignedTextGrid(
textgrid_path = "../usage/resources/spritely.TextGrid" ,
entry_classes = custom_classes([
"PrWord" ,
"Foot" ,
"Syl" ,
"OnsetRime" ,
"SylPart" ,
"Phone"
])
)
print (atg)
AlignedTextGrid with 1 groups named ['group_0'] each with [6] tiers. [['PrWord', 'Foot', 'Syl', 'OnsetRime', 'SylPart', 'Phone']]
atg.pop_class("SylPart" )
print (atg)
AlignedTextGrid with 1 groups named ['group_0'] each with [5] tiers. [['PrWord', 'Foot', 'Syl', 'OnsetRime', 'Phone']]
return_textgrid
aligned_textgrid.AlignedTextGrid.return_textgrid()
Convert this AlignedTextGrid
to a praatio
Textgrid
Returns the current object as a praatio.data_classes.textgrid.Textgrid
. Useful for saving.
Returns
praatio
.data_classes
.textgrid
.Textgrid
A praatio
Textgrid
save_textgrid
aligned_textgrid.AlignedTextGrid.save_textgrid(save_path, format='long_textgrid')
Saves the current AlignedTextGrid
Uses the praatio.data_classes.textgrid.Textgrid.save()
method.
Parameters
save_path
str
path for saving the textgrid
required
format
Literal [‘short_textgrid’, ‘long_textgrid’, ‘json’, ‘textgrid_json’]
Save format.
'long_textgrid'
shift
aligned_textgrid.AlignedTextGrid.shift(increment)
Shift all times (interval starts & ends and point times) by the given increment.
Parameters
increment
float
The increment by which to shift all times. Could be positive or negative.
required