API Reference¶
Functional Helpers¶
gridio
¶
High-level helpers for converting Praat TextGrid files.
These wrappers expose the Rust-backed parsing and serialization
implemented in :mod:gridio.gridio and provide convenient
Pythonic utilities for turning TextGrid content into tabular or nested
data structures and writing them back to disk.
Functions:
| Name | Description |
|---|---|
textgrid_to_df |
Parse TextGrid files into a DataFrame-like structure. |
textgrid_to_data |
Parse TextGrid files into nested data resembling the Rust output. |
df_to_textgrid |
Serialize a tabular representation back into a TextGrid file. |
data_to_textgrid |
Write nested tier data to a TextGrid file using the Rust backend. |
textgrid_to_df(file, strict=False, file_type='auto', file_name_column=None, file_name_func=None, backend='pandas')
¶
Parse TextGrid files into a DataFrame-like structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
Union[str, list[str], Path, list[Path]]
|
Path to a single TextGrid file or an iterable of paths. |
required |
strict
|
bool
|
When |
False
|
file_type
|
str
|
|
'auto'
|
file_name_column
|
Optional[bool]
|
Force inclusion ( |
None
|
file_name_func
|
Optional[Any]
|
Optional callable used to transform each filename before it is written to the DataFrame. The callable receives the original path object and must return a string. |
None
|
backend
|
Literal['pandas', 'polars']
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame or DataFrame
|
Tabular representation containing |
Examples:
>>> df = textgrid_to_df("data/short_format.TextGrid")
>>> df.head().to_dict(orient="records")
[{'tmin': 0.0, 'tmax': 0.25, 'label': 'sil', 'tier': 'phones',
'is_interval': True},
{'tmin': 0.25, 'tmax': 0.53, 'label': 's', 'tier': 'phones',
'is_interval': True}]
The primary columns are tmin, tmax, label, tier,
is_interval, and (for multi-file inputs) filename.
See Also
df_to_textgrid : Persist the DataFrame back to a TextGrid file.
Source code in gridio/__init__.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
textgrid_to_data(file, strict=False, file_name_func=None, file_type='auto')
¶
Parse TextGrid files into nested data resembling the Rust output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
Union[str, list[str], Path, list[Path]]
|
Path to a single TextGrid file or an iterable of paths. |
required |
strict
|
bool
|
When |
False
|
file_name_func
|
Optional[Any]
|
Optional callable used to transform each filename key in the returned dictionary for multi-file inputs. |
None
|
file_type
|
str
|
|
'auto'
|
Returns:
| Type | Description |
|---|---|
tuple or dict[str, tuple]
|
The raw structured data from the Rust bindings. For multiple files a dictionary keyed by filename is returned. |
Examples:
>>> data = textgrid_to_data("data/short_format.TextGrid")
>>> round(data[0], 2), round(data[1], 2)
(0.0, 2.43)
>>> data[2][0]
('phones', True, [(0.0, 0.25, 'sil'), (0.25, 0.53, 's')])
The tuple layout is (tmin, tmax, tiers). Each tier entry is
(name, is_interval, items) where items is an ordered list of
(start, end, label) tuples. Point tiers repeat their timestamp for
start and end so the shape remains consistent with interval tiers.
With multiple input files the function returns a dictionary mapping the
normalised filename (after applying file_name_func when provided) to the
same tuple structure.
See Also
data_to_textgrid : Convert the tuple structure back into a TextGrid file.
Source code in gridio/__init__.py
df_to_textgrid(df, out_file, tmin=None, tmax=None, file_type='long')
¶
Serialize a tabular representation back into a TextGrid file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
Any
|
DataFrame-like object exposing |
required |
out_file
|
str
|
Destination path for the emitted TextGrid file. |
required |
tmin
|
Optional[float]
|
Optional overrides for the global bounds written to the file. |
None
|
tmax
|
Optional[float]
|
Optional overrides for the global bounds written to the file. |
None
|
file_type
|
str
|
Dialect to emit ( |
'long'
|
Examples:
>>> df = textgrid_to_df("data/short_format.TextGrid")
>>> df_to_textgrid(df, "out.TextGrid", file_type="short")
The converter expects the same column layout described in
:func:textgrid_to_df.
See Also
textgrid_to_df : Parse TextGrid files into the expected DataFrame format.
Source code in gridio/__init__.py
data_to_textgrid(data, out_file, file_type='long')
¶
Write nested tier data to a TextGrid file using the Rust backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
Tuple of |
required |
out_file
|
str
|
Destination path for the serialized TextGrid. |
required |
file_type
|
str
|
Dialect to emit ( |
'long'
|
Examples:
>>> data = textgrid_to_data("data/short_format.TextGrid")
>>> data_to_textgrid(data, "out.TextGrid", file_type="long")
Refer to :func:textgrid_to_data for details on the expected tuple layout.
See Also
textgrid_to_data : Produce the tuple structure consumed by this helper.
Source code in gridio/__init__.py
Object-Oriented API¶
gridio.textgrid
¶
Classes:
| Name | Description |
|---|---|
IntervalItem |
Lightweight container for a single interval tier entry. |
IntervalTier |
Tier containing interval items spanning start and end times. |
PointItem |
Container for a point tier entry stored at a single timestamp. |
PointTier |
Tier containing point items at discrete timestamps. |
TextGrid |
In-memory representation of a Praat TextGrid document. |
Tier |
Mutable collection of TextGrid items with a shared tier name. |
IntervalItem
¶
Lightweight container for a single interval tier entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tmin
|
float
|
Start and end boundaries in seconds. |
required |
tmax
|
float
|
Start and end boundaries in seconds. |
required |
label
|
str
|
Text label associated with the interval. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
data |
Return the tuple representation consumed by the Rust backend. |
Source code in gridio/textgrid.py
data
property
¶
Return the tuple representation consumed by the Rust backend.
IntervalTier
¶
Bases: Tier
Tier containing interval items spanning start and end times.
Methods:
| Name | Description |
|---|---|
get_item |
Return the :class: |
Source code in gridio/textgrid.py
get_item(index)
¶
PointItem
¶
Container for a point tier entry stored at a single timestamp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
float
|
Absolute time position in seconds. |
required |
label
|
str
|
Text label associated with the point. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
data |
Represent the point as |
Source code in gridio/textgrid.py
data
property
¶
Represent the point as (time, time, label) for uniform storage.
PointTier
¶
Bases: Tier
Tier containing point items at discrete timestamps.
Methods:
| Name | Description |
|---|---|
get_item |
Return the :class: |
Source code in gridio/textgrid.py
TextGrid
¶
In-memory representation of a Praat TextGrid document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tmin
|
float
|
Global bounds for all tiers. They are preserved when saving if not overridden. |
None
|
tmax
|
float
|
Global bounds for all tiers. They are preserved when saving if not overridden. |
None
|
Methods:
| Name | Description |
|---|---|
add_tier |
Insert |
from_file |
Read TextGrid files and wrap them in :class: |
get_tier |
Return a tier by numeric index or name, preserving subclass type. |
remove_tier |
Remove a tier, looking it up by name or numeric index. |
save |
Write the TextGrid to |
Attributes:
| Name | Type | Description |
|---|---|---|
data |
Return the backend-compatible tuple |
|
ntiers |
int
|
Total number of tiers in the TextGrid. |
Source code in gridio/textgrid.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
data
property
¶
Return the backend-compatible tuple (tmin, tmax, tiers).
ntiers
property
¶
Total number of tiers in the TextGrid.
add_tier(tier, where=-1)
¶
from_file(file, strict=False, file_type='auto', file_name_func=None)
staticmethod
¶
Read TextGrid files and wrap them in :class:TextGrid objects.
Source code in gridio/textgrid.py
get_tier(indexer=None, tier_name=None, tier_id=None)
¶
Return a tier by numeric index or name, preserving subclass type.
Source code in gridio/textgrid.py
remove_tier(tier_name=None, tier_id=None)
¶
Remove a tier, looking it up by name or numeric index.
save(out_file, file_type='long')
¶
Write the TextGrid to out_file using the Rust serializer.
Tier
¶
Mutable collection of TextGrid items with a shared tier name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Tier identifier as stored in the TextGrid. |
required |
is_interval
|
bool
|
|
required |
Methods:
| Name | Description |
|---|---|
insert_item |
Insert a new item at |
remove_item |
Remove the item at |
Attributes:
| Name | Type | Description |
|---|---|---|
data |
Return the tuple |
|
nitems |
int
|
Number of stored items. |