Skip to main content

Python phoneme alignment representation

Project description

Python phoneme alignment representation

PyPI License Downloads

Phoneme alignment representation for speech tasks. This repo does not perform forced phoneme alignment, but provides an interface for working with the resulting alignment of a forced aligner such as pyfoal.

Installation

pip install pypar

Usage

Creating an alignment

If you already have the alignment saved to a json, mlf, or TextGrid file, pass the name of the file.

alignment = pypar.Alignment(file)

Alignments can be created manually from Word and Phoneme objects. Start and end times are given in seconds.

# Create a word from phonemes
word = pypar.Word(
    'THE',
    [pypar.Phoneme('DH', 0., .03), pypar.Phoneme('AH0', .03, .06)])

# Create a silence
silence = pypar.Word(pypar.SILENCE, pypar.Phoneme(pypar.SILENCE, .06, .16))

# Make an alignment
alignment = pypar.Alignment([word, silence])

You can create a new alignment from existing alignments via slicing and concatenation.

# Slice
first_two_words = alignment[:2]

# Concatenate
alignment_with_repeat = first_two_words + alignment

Accessing words and phonemes

To retrieve a list of words in the alignment, use alignment.words(). To retrieve a list of phonemes, use alignment.phonemes(). The Alignment, Word, and Phoneme objects all define .start(), .end(), and .duration() methods, which return the start time, end time, and duration, respectively. All times are given in units of seconds. These objects also define equality checks via ==, casting to string with str(), and iteration as follows.

# Iterate over words
for word in alignment:

    # Iterate over phonemes in word
    for phoneme in word:

        # Do something with phoneme
        pass

To access a word or phoneme at a specific time, pass the time in seconds to alignment.word_at_time or alignment.phoneme_at_time.

To retrieve the frame indices of the start and end of a word or phoneme, pass the audio sampling rate and hopsize (in samples) to alignment.word_bounds or alignment.phoneme_bounds.

Saving an alignment

To save an alignment to disk, use alignment.save(file), where file is the desired filename. pypar currently supports saving as a json or TextGrid file.

Tests

Tests can be run as follows.

pip install pytest
pytest

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

pypar-0.0.4.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

pypar-0.0.4-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file pypar-0.0.4.tar.gz.

File metadata

  • Download URL: pypar-0.0.4.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.5

File hashes

Hashes for pypar-0.0.4.tar.gz
Algorithm Hash digest
SHA256 851bbe21f623ffba71000d1b14c1ec4d9cc7ecaf78e52b9ba754165ee450021a
MD5 92bc335ab6d10cdcbdd61ec12e6ad21e
BLAKE2b-256 3a88d870de7560ce1acb599f356e375e7724c37a92eeedfac694a8457d6cac0a

See more details on using hashes here.

File details

Details for the file pypar-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: pypar-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.5

File hashes

Hashes for pypar-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 df87c724f7f1189e3ddab3e1d5cc18c7b13b6319902681b7dd0b676ddb41620a
MD5 48fa9686b92b4e54f903a205cbfcdd49
BLAKE2b-256 800af93c0a14d87a29c82489110e8fdcb2013f9555e4df7bcfd0153cdf8c097d

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