Skip to main content

A python library to read and write a subset of TextGrid file format

Project description

TonkineseGrid for TextGrid file format

This is a python library that can read and write a subset of TextGrid file format, with full type hint, and some extra methods to manipulate intervals.

Notice that this library only support the full text format of TextGrid, and in which only contains IntervalTier class. Also this a side project has no full test of the codebase, therefore it is not production ready. Please use it at your own risk

Basic Usage

Get started with installing the package.

pip install tonkinese_grid

Then you can use it like the following.

from tonkinese_grid import TextGrid

textgrid = TextGrid.read("file.TextGrid")
for items in textgrid:
    for interval in items:
        print(interval)

new = TextGrid(0, 2.5)
new.append_new(0, 2.5, "words")
new[0].append_new(0, 1, "hello")
new[0].append_new(1, 2.5, "world")
new.save("HelloWorld.TextGrid")

Classes And Methods

This section list basic information about the classes and their methods. For more details, please read the source code

class Interval:
    min: float
    max: float
    text: str
    @staticmethod
    def is_continuous(prev: "Interval", curr: "Interval") -> bool:

class IntervalList:
    """a wrapper of list of intervals, which makes sure intervals inside of it
    is continuous and provide some other useful methods."""
    def __getitem__(self, idx: int) -> Interval: ...
    def __iter__(self) -> Iterator[Interval]: ...
    def __len__(self) -> int: ...
    def size(self) -> int: ...
    def slice(
        self,
        start: Optional[int] = None,
        stop: Optional[int] = None,
        step: Optional[int] = None,
    ) -> list[Interval]: ...
    def clear(self) -> None: ...
    def copy(self) -> IntervalList: ...
    def append(self, interval: Interval) -> None: ...
    def append_new(self, min: float, max: float, text: str) -> None: ...
    def replace(self, idx: int, text: str) -> None: ...
    def move_offset(self, idx: int, offset: float) -> None: ...
    def move_offset_by_dur(self, idx: int, dur: float) -> None: ...
    def split_insert(self, idx: int, text: str, dur: float) -> None: ...
    def split_append(self, idx: int, text: str, dur: float) -> None: ...
    def merge(self, start: int, end: int, text: str) -> None: ...

class IntervalTier:
    """Has the same methods with IntervalList"""
    min: float
    max: float
    name: str
    intervals: IntervalList

class TextGrid:
    min: float
    max: float
    items: list[IntervalTier]
    def __iter__(self) -> Iterator[IntervalTier]: ...
    def __str__(self) -> str: ...
    def __getitem__(self, idx: int) -> IntervalTier: ...
    def __setitem__(self, idx: int, tier: IntervalTier) -> None: ...
    @classmethod
    def read(cls, file: str) -> "TextGrid": ...
    def size(self) -> int: ...
    def copy(self) -> "TextGrid": ...
    def save(self, path: str) -> None: ...
    def append_new(self, min: float, max: float, name: str) -> None: ...
    def append(self, intervals: IntervalTier) -> None: ...

Credit

textgrid

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tonkinese_grid-2024.0.0a2.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tonkinese_grid-2024.0.0a2-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file tonkinese_grid-2024.0.0a2.tar.gz.

File metadata

  • Download URL: tonkinese_grid-2024.0.0a2.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.2

File hashes

Hashes for tonkinese_grid-2024.0.0a2.tar.gz
Algorithm Hash digest
SHA256 fbae0c87d316a29395ecfe7c50c2f4b8820164b20d533f003b0737c42606a378
MD5 e25c958a1b263951c05e9af651bd4e25
BLAKE2b-256 0cf1ed4206ad677ec9711f8f60f66b1a57cb3a1377c13465aabd4626ec3b777c

See more details on using hashes here.

File details

Details for the file tonkinese_grid-2024.0.0a2-py3-none-any.whl.

File metadata

File hashes

Hashes for tonkinese_grid-2024.0.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 32fb414f268023f811d82af77af9d3acc352a954a80df7cf5c5f3e8c1a17dd6e
MD5 888a85e77921b65c6c881a7c2eb8a06f
BLAKE2b-256 3f69392b6ba7ce88b688203ebd85bb4d3817b8b18552de54a1b14b1644181bd7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page