Python package: mytextgrid
This is a python package to work with Praat annotation files. You can create, read, write and query TextGrids.
The following tutorial will walk you through the basics. For more information, visit the documentation website
Getting started
1. Installation
You can get the lastest release of this package using the pip installer:
pip install -U mytextgrid
After that, you can import the package as in the following line.
import mytextgrid
2. The basics
Reading a TextGrid from a file
To read an existing TextGrid file use the read_textgrid() function. TextGrid files come in three formats: long, short and binary. At this moment, only the long format is supported.
import mytextgrid
# Read TextGrid
>>> path = r'C:\Users\rolan\Documents\projects\Mary_John_bell.TextGrid'
>>> tg = mytextgrid.read_textgrid(path)
Describe a TextGrid
>>> tg.describe()
TextGrid:
Startig time (sec): 0
Ending time (sec): 1
Number of tiers: 3
Tiers summary:
0 IntervalTier Mary (size = 1)
1 IntervalTier John (size = 1)
2 PointTier bell (size = 0)
Manipulating a TextGrid
# Insert tier
>>> tone_tier = tg.insert_tier("tone", False)
>>> segment_tier = tg.insert_tier("segment")
>>> word_tier = tg.insert_tier("word")
>>> phrase_tier = tg.insert_tier("phrase")
# Point tier: Inserting points
>>> tone_tier.insert_point(0.66, "H")
>>> tone_tier.insert_point(0.9, "L")
# Interval tier: Inserting boundaries
>>> segment_tier.insert_boundaries(0.23, 0.30, 0.42, 0.62, 0.70, 0.82, 0.98)
>>> word_tier.insert_boundaries(0.23, 0.42, 0.98)
>>> phrase_tier.insert_boundaries(0.23, 0.98)
# Interval tier: Populate intervals with text
>>> segment_tier.set_text_at_index(1, 'e', 'l', 'p', 'e', 'rr', 'o')
>>> word_tier.set_text_at_index(1, 'el')
>>> word_tier.set_text_at_index(2, 'perro')
>>> phrase_tier.set_text_at_index(1, 'el perro')
# Remove a tier
>>> tg.remove_tier(0)
>>> tg.describe()
traversing through a TextGrid
A TextGrid object is a container that stores one or more Tier objects. Each tier, at the same time, is a container itself and stores two types of objects: Intervals or Points. Depending on that, a tier can be a IntervalTier or PointTier. To iterate through these containers use the for loop as in the following example.
# Iterate through a TextGrid
for tier in tg:
print(tier.name)
# Iterate through tiers
if tier.is_interval():
for interval in tier:
# For interval tiers
# Print Interval attributes
print(interval.xmin)
print(interval.xmax)
print(interval.text)
else:
# For point tiers
for point in tier:
# Print Point attributes
print(point.time)
print(point.text)
Writing TextGrid to a file
You can write a TextGrid to different types of files.
tg.write('example1-long.TextGrid')
tg.write('example1-short.TextGrid', True) # Write the TextGrid a short format TextGrid
# Write to a JSON file
tg.write_as_json('example1.json')
Creating a TextGrid from scratch
Creating a TextGrid from the scratch is easy, just take a look to the following lines of code.
# Create an empty TextGrid
>>> new_tg = mytextgrid.create_textgrid(xmin = 0, xmax = 1)
Becareful, the resulting object does not contain any tier.
Metadata
Release files for mytextgrid 0.10.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mytextgrid-0.10.0.tar.gz | 27.7 kB | Without provenance | Details for mytextgrid-0.10.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mytextgrid-0.10.0-py3-none-any.whl | Python 3 | none | any | Details for mytextgrid-0.10.0-py3-none-any.whl |
Total release size: 58.9 kB
Release files / mytextgrid-0.10.0.tar.gz
| Download URL | mytextgrid-0.10.0.tar.gz |
|---|---|
| Size | 27.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a6a992b1dfacad034d199559cf2ad48d7dc8d1d99556bdb1e460d50d973bc887
|
|
BLAKE2b-256 checksum How to use checksums |
ad4cf0689cee12e9b7641f45373548808410739237abb6a8274408ae6bfcb7cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.28.1
|
Release files / mytextgrid-0.10.0-py3-none-any.whl
| Download URL | mytextgrid-0.10.0-py3-none-any.whl |
|---|---|
| Size | 31.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4d719d3c5fad25e2a17663458cd9c2a04588c01d4bfa3e15dd5ad25d2afdb222
|
|
BLAKE2b-256 checksum How to use checksums |
3c23a16368396f8a35e35d221e18c3698d6db372506203a33b7ca2d37ce49180
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.28.1
|
Security for mytextgrid 0.10.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.