load_textgrid#

Defined in: voxatlas.units.alignment_loader

voxatlas.units.alignment_loader.load_textgrid(path)[source]#

Parse a Praat TextGrid file into per-tier interval tables.

Each returned DataFrame contains interval rows with id, start, end, and label columns. Tier names are used as dictionary keys.

Parameters:

path (str | Path) – Path to a TextGrid file on disk.

Returns:

Mapping from tier name to interval table.

Return type:

dict[str, pandas.DataFrame]

Notes

This parser targets interval tiers (intervals [n] blocks). Point tiers are not expanded into the output structure.

Examples

>>> import tempfile
>>> from pathlib import Path
>>> from voxatlas.units.alignment_loader import load_textgrid
>>> textgrid = "\n".join(
...     [
...         "item [1]:",
...         '    name = "words"',
...         "    intervals [1]:",
...         "        xmin = 0",
...         "        xmax = 0.5",
...         '        text = "hello"',
...         "item [2]:",
...         '    name = "phones"',
...         "    intervals [1]:",
...         "        xmin = 0",
...         "        xmax = 0.5",
...         '        text = "h"',
...     ]
... ) + "\n"
>>> with tempfile.TemporaryDirectory() as tmp:
...     path = Path(tmp) / "alignment.TextGrid"
...     _ = path.write_text(textgrid, encoding="utf-8")
...     tiers = load_textgrid(path)
...     (sorted(tiers.keys()), tiers["words"].columns.tolist())
(['phones', 'words'], ['id', 'start', 'end', 'label'])