API

class praattools.TextGrid(start, end, tiers=[])

A TextGrid object. Supports writing and reading from long and short TextGrid files.

A TextGrid is (currently) implemented as a list of Tiers. It will always support all list operations like append(), insert(), and pop().

Initialise a TextGrid.

Parameters:
  • start (float | timedelta) – The start time, in seconds or as a timedelta.

  • end (float | timedelta) – The end time, in seconds or as a timedelta.

  • tiers (Iterable[Tier]) – A list or other iterable of Tiers to initialise with.

classmethod from_file(filename, encoding='utf-8')

Create a TextGrid from a file. Currently supports short and long text formats, but not (yet) binary.

Parameters:
  • filename (str) – The TextGrid filename

  • encoding (str) – The character encoding of the TextGrid file

Returns:

The created TextGrid

Return type:

TextGrid

to_file(filename, format='long', encoding='utf-8')

Writes a TextGrid to a file. Currently supports short and long text formats, but not binary.

Parameters:
  • filename (str) – The new TextGrid filename

  • format (str) –

    The format to write the TextGrid in. Must be one of:

    • 'long' To write a longform TextGrid file.

    • 'short' To write a shortform TextGrid file.

    • 'binary' (Planned in a future release.)

  • encoding (str) – The character encoding to be used

Raises:
property end: timedelta

End time.

property end_ms: float

End time in milliseconds.

property end_s: float

End time in seconds.

property start: timedelta

Start time.

property start_ms: float

Start time in milliseconds.

property start_s: float

Start time in seconds.

__getitem__(index: SupportsIndex) Tier
__getitem__(index: str) Tier
__getitem__(index: slice) list[praattools.Tier]

A TextGrid can be indexed like a list or by name. Deleting is also implemented like this, but (re-)assignment can only be done by numeric index.

class praattools.Tier(name, start, end, elements=[])

Not to be constructed separately. Base class for IntervalTier and PointTier.

Initialises a Tier.

Parameters:
property end: timedelta

End time.

property end_ms: float

End time in milliseconds.

property end_s: float

End time in seconds.

property start: timedelta

Start time.

property start_ms: float

Start time in milliseconds.

property start_s: float

Start time in seconds.

class praattools.IntervalTier(name, start, end, elements=[])

An IntervalTier, consisting of IntervalElements.

IntervalTiers are (currently) implemented as a list of py:class:IntervalElements. They will always support all list operations like append(), insert(), and pop().

Initialises a Tier.

Parameters:
element_type

alias of IntervalElement

property end: timedelta

End time.

property end_ms: float

End time in milliseconds.

property end_s: float

End time in seconds.

property start: timedelta

Start time.

property start_ms: float

Start time in milliseconds.

property start_s: float

Start time in seconds.

class praattools.PointTier(name, start, end, elements=[])

A PointTier, or TextTier, of PointElements.

PointTiers are (currently) implemented as a list of py:class:PointElements. They will always support all list operations like append(), insert(), and pop().

Initialises a Tier.

Parameters:
element_type

alias of PointElement

property end: timedelta

End time.

property end_ms: float

End time in milliseconds.

property end_s: float

End time in seconds.

property start: timedelta

Start time.

property start_ms: float

Start time in milliseconds.

property start_s: float

Start time in seconds.

class praattools.IntervalElement(name, start, end)

An element in an IntervalTier.

Parameters:
property end: timedelta

End time.

property end_ms: float

End time in milliseconds.

property end_s: float

End time in seconds.

property start: timedelta

Start time.

property start_ms: float

Start time in milliseconds.

property start_s: float

Start time in seconds.

class praattools.PointElement(name, time)

An element in a PointTier.

Parameters: