pypar
Phoneme alignment representation compatible with multiple forced aligners
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (5.8%) to scientific vocabulary
Keywords
Repository
Phoneme alignment representation compatible with multiple forced aligners
Basic Info
Statistics
- Stars: 21
- Watchers: 4
- Forks: 1
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
Python phoneme alignment representation
Word and phoneme alignment representation for speech tasks. This repo does
not perform forced word or phoneme alignment, but provides an interface
for working with the resulting alignment of a forced aligner, such as
pyfoal, or a manual alignment.
Table of contents
- Usage
- Application programming interface (API)
pypar.Alignmentpypar.Alignment.__init__pypar.Alignment.__add__pypar.Alignment.__eq__pypar.Alignment.__getitem__pypar.Alignment.__len__pypar.Alignment.__str__pypar.Alignment.durationpypar.Alignment.endpypar.Alignment.findpypar.Alignment.framewise_phoneme_indicespypar.Alignment.phonemespypar.Alignment.phoneme_at_timepypar.Alignment.phoneme_boundspypar.Alignment.savepypar.Alignment.startpypar.Alignment.updatepypar.Alignment.wordspypar.Alignment.word_bounds
pypar.Phonemepypar.Word
- Tests
Usage
Creating alignments
If you already have the alignment saved to a json, mlf, or TextGrid
file, pass the name of the file. Valid examples of each format can be found in
test/assets/.
python
alignment = pypar.Alignment(file)
Alignments can be created manually from Word and Phoneme objects. Start and
end times are given in seconds.
```python
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.
```python
Slice
firsttwowords = alignment[:2]
Concatenate
alignmentwithrepeat = firsttwowords + 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.
```python
Iterate over words
for word in alignment:
# Access start and end times
assert word.duration() == word.end() - word.start()
# Iterate over phonemes in word
for phoneme in word:
# Access string representation
assert isinstance(str(phoneme), str)
```
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 alignments
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.
Application programming interface (API)
pypar.Alignment
pypar.Alignment.__init__
```python def init( self, alignment: Union[str, bytes, os.PathLike, List[pypar.Word], dict] ) -> None: """Create alignment
Arguments
alignment
The filename, list of words, or json dict of the alignment
"""
```
pypar.Alignment.__add__
```python def add(self, other): """Add alignments by concatenation
Arguments
other
The alignment to compare to
Returns
The concatenated alignment
"""
```
pypar.Alignment.__eq__
```python def eq(self, other) -> bool: """Equality comparison for alignments
Arguments
other
The alignment to compare to
Returns
Whether the alignments are equal
"""
```
pypar.Alignment.__getitem__
```python def getitem(self, idx: Union[int, slice]) -> pypar.Word: """Retrieve the idxth word
Arguments
idx
The index of the word to retrieve
Returns
The word at index idx
"""
```
pypar.Alignment.__len__
```python def len(self) -> int: """Retrieve the number of words
Returns
The number of words in the alignment
"""
```
pypar.Alignment.__str__
```python def str(self) -> str: """Retrieve the text
Returns
The words in the alignment separated by spaces
"""
```
pypar.Alignment.duration
```python def duration(self) -> float: """Retrieve the duration of the alignment in seconds
Returns
The duration in seconds
"""
```
pypar.Alignment.end
```python def end(self) -> float: """Retrieve the end time of the alignment in seconds
Returns
The end time in seconds
"""
```
pypar.Alignment.framewise_phoneme_indices
```python def framewisephonemeindices( self, phoneme_map: Dict[str, int], hopsize: float, times: Optional[List[float]] = None ) -> List[int]: """Convert alignment to phoneme indices at regular temporal interval
Arguments
phoneme_map
Mapping from phonemes to indices
hopsize
Temporal interval between frames in seconds
times
Specified times in seconds to sample phonemes
"""
```
pypar.Alignment.find
```python def find(self, words: str) -> int: """Find the words in the alignment
Arguments
words
The words to find
Returns
The index of the start of the words or -1 if not found
"""
```
pypar.Alignment.phonemes
```python def phonemes(self) -> List[pypar.Phoneme]: """Retrieve the phonemes in the alignment
Returns
The phonemes in the alignment
"""
```
pypar.Alignment.phoneme_at_time
```python def phonemeattime(self, time: float) -> Optional[pypar.Phoneme]: """Retrieve the phoneme spoken at specified time
Arguments
time
Time in seconds
Returns
The phoneme at the given time (or None if time is out of bounds)
"""
```
pypar.Alignment.phoneme_bounds
```python def phonemebounds( self, samplerate: int, hopsize: int = 1 ) -> List[Tuple[int, int]]: """Retrieve the start and end frame index of each phoneme
Arguments
sample_rate
The audio sampling rate
hopsize
The number of samples between successive frames
Returns
The start and end indices of the phonemes
"""
```
pypar.Alignment.save
```python def save(self, filename: Union[str, bytes, os.PathLike]) -> None: """Save alignment to json
Arguments
filename
The location on disk to save the phoneme alignment json
"""
```
pypar.Alignment.start
```python def start(self) -> float: """Retrieve the start time of the alignment in seconds
Returns
The start time in seconds
"""
```
pypar.Alignment.update
```python def update( self, idx: int = 0, durations: Optional[List[float]] = None, start: Optional[float] = None ) -> None: """Update alignment starting from phoneme index idx
Arguments
idx
The index of the first phoneme whose duration is being updated
durations
The new phoneme durations, starting from idx
start
The start time of the alignment
"""
```
pypar.Alignment.words
```python def words(self) -> List[pypar.Word]: """Retrieve the words in the alignment
Returns
The words in the alignment
"""
```
pypar.Alignment.word_bounds
```python def wordattime(self, time: float) -> Optional[pypar.Word]: """Retrieve the word spoken at specified time
Arguments
time
Time in seconds
Returns
The word spoken at the specified time
"""
```
pypar.Phoneme
pypar.Phoneme.__init__
```python def init(self, phoneme: str, start: float, end: float) -> None: """Create phoneme
Arguments
phoneme
The phoneme
start
The start time in seconds
end
The end time in seconds
"""
```
pypar.Phoneme.__eq__
```python def eq(self, other) -> bool: """Equality comparison for phonemes
Arguments
other
The phoneme to compare to
Returns
Whether the phonemes are equal
"""
```
pypar.Phoneme.__str__
```python def str(self) -> str: """Retrieve the phoneme text
Returns
The phoneme
"""
```
pypar.Phoneme.duration
```python def duration(self) -> float: """Retrieve the phoneme duration
Returns
The duration in seconds
"""
```
pypar.Phoneme.end
```python def end(self) -> float: """Retrieve the end time of the phoneme in seconds
Returns
The end time in seconds
"""
```
pypar.Phoneme.start
```python def start(self) -> float: """Retrieve the start time of the phoneme in seconds
Returns
The start time in seconds
"""
```
pypar.Word
pypar.Word.__init__
```python def init(self, word: str, phonemes: List[pypar.Phoneme]) -> None: """Create word
Arguments
word
The word
phonemes
The phonemes in the word
"""
```
pypar.Word.__eq__
```python def eq(self, other) -> bool: """Equality comparison for words
Arguments
other
The word to compare to
Returns
Whether the words are the same
"""
```
pypar.Word.__getitem__
```python def getitem(self, idx: int) -> pypar.Phoneme: """Retrieve the idxth phoneme
Arguments
idx
The index of the phoneme to retrieve
Returns
The phoneme at index idx
"""
```
pypar.Word.__len__
```python def len(self) -> int: """Retrieve the number of phonemes
Returns
The number of phonemes
"""
```
pypar.Word.__str__
```python def str(self) -> str: """Retrieve the word text
Returns
The word text
"""
```
pypar.Word.duration
```python def duration(self) -> float: """Retrieve the word duration in seconds
Returns
The duration in seconds
"""
```
pypar.Word.end
```python def end(self) -> float: """Retrieve the end time of the word in seconds
Returns
The end time in seconds
"""
```
pypar.Word.phoneme_at_time
```python def phonemeattime(self, time: float) -> Optional[pypar.Phoneme]: """Retrieve the phoneme at the specified time
Arguments
time
Time in seconds
Returns
The phoneme at the given time (or None if time is out of bounds)
"""
```
pypar.Word.start
```python def start(self) -> float: """Retrieve the start time of the word in seconds
Returns
The start time in seconds
"""
```
Tests
Tests can be run as follows.
pip install pytest
pytest
Owner
- Name: Max Morrison
- Login: maxrmorrison
- Kind: user
- Website: https://www.maxrmorrison.com
- Twitter: maxrmorrison
- Repositories: 7
- Profile: https://github.com/maxrmorrison
Computer Science PhD student at Northwestern University researching machine learning and audio technology
Citation (CITATION.cff)
cff-version: 1.2.0 message: "If you use this software, please cite it using the following metadata." authors: - family-names: "Morrison" given-names: "Max" title: "pypar" version: 0.0.2 date-released: 2021-04-03 url: "https://github.com/maxrmorrison/pypar"
GitHub Events
Total
- Watch event: 5
Last Year
- Watch event: 5
Committers
Last synced: 7 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Max Morrison | m****n@g****m | 31 |
| CameronChurchwell | s****s@i****m | 2 |
| Max Morrison | m****x@d****m | 2 |
| Nathan Pruyne | n****e@g****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 4
- Total pull requests: 5
- Average time to close issues: 22 days
- Average time to close pull requests: about 15 hours
- Total issue authors: 1
- Total pull request authors: 3
- Average comments per issue: 0.75
- Average comments per pull request: 0.2
- Merged pull requests: 4
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- maxrmorrison (4)
Pull Request Authors
- CameronChurchwell (2)
- maxrmorrison (2)
- NathanPruyne (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 2,872 last-month
- Total dependent packages: 3
- Total dependent repositories: 3
- Total versions: 6
- Total maintainers: 1
pypi.org: pypar
Python phoneme alignment representation
- Homepage: https://github.com/maxrmorrison/pypar
- Documentation: https://pypar.readthedocs.io/
- License: MIT
-
Latest release: 0.0.6
published almost 2 years ago
Rankings
Maintainers (1)
Dependencies
- numpy *
- textgrid *