torchfa
A Python package for performing forced alignment on audio files using Torchaudio's MMS model. This tool aligns audio with text transcripts to provide precise timing information for each word, making it useful for speech analysis, subtitling, and other applications requiring accurate speech-text synchronization.
Features
- High-accuracy forced alignment using Torchaudio's MMS model
- Support for both Chinese and English text
- Batch processing capabilities for multiple audio files
- Output aligned segments in various formats including TextGrid
Installation
pip install torchfa
Usage
Basic Usage
from torchfa import TorchaudioForcedAligner
aligner = TorchaudioForcedAligner()
audio = "assets/clean_speech.wav"
transcript = "关服务高端产品仍处于供不应求的局面"
cut = aligner.align_audios(audio, transcript)
# Save aligned audio segments
cut.trim_to_alignments("word").save_audios("./")
# Print alignment results
for alignment in cut.supervisions[0].alignment["word"]:
print(alignment)
Output:
AlignmentItem(symbol='关', start=0.02, duration=0.121, score=0.21)
AlignmentItem(symbol='服', start=0.241, duration=0.141, score=0.07)
AlignmentItem(symbol='务', start=0.502, duration=0.101, score=0.49)
AlignmentItem(symbol='高', start=0.724, duration=0.181, score=0.97)
AlignmentItem(symbol='端', start=0.945, duration=0.141, score=0.52)
AlignmentItem(symbol='产', start=1.126, duration=0.201, score=0.81)
AlignmentItem(symbol='品', start=1.367, duration=0.141, score=0.35)
AlignmentItem(symbol='仍', start=1.608, duration=0.201, score=0.89)
AlignmentItem(symbol='处', start=1.869, duration=0.121, score=0.72)
AlignmentItem(symbol='于', start=2.09, duration=0.06, score=0.96)
AlignmentItem(symbol='供', start=2.251, duration=0.161, score=0.95)
AlignmentItem(symbol='不', start=2.452, duration=0.06, score=0.69)
AlignmentItem(symbol='应', start=2.573, duration=0.161, score=0.63)
AlignmentItem(symbol='求', start=2.754, duration=0.141, score=0.95)
AlignmentItem(symbol='的', start=2.935, duration=0.08, score=0.99)
AlignmentItem(symbol='局', start=3.075, duration=0.101, score=0.98)
AlignmentItem(symbol='面', start=3.256, duration=0.221, score=0.94)
Saving to TextGrid Format
from torchfa import TorchaudioForcedAligner
from torchfa.utils import save_text_grid
aligner = TorchaudioForcedAligner()
audio = "assets/clean_speech.wav"
transcript = "关服务高端产品仍处于供不应求的局面"
cut = aligner.align_audios(audio, transcript)
# Save as TextGrid file
save_text_grid(cut.supervisions[0].alignment["word"], "output.TextGrid", "long")
Batch Processing
from torchfa import TorchaudioForcedAligner
aligner = TorchaudioForcedAligner(batch_size=4) # Process 4 files at once
audio_paths = [
"audio1.wav",
"audio2.wav",
"audio3.wav"
]
transcripts = [
"This is the first transcript.",
"This is the second transcript.",
"This is the third transcript."
]
cuts = aligner.align_audios(audio_paths, transcripts)
for cut in cuts:
for alignment in cut.supervisions[0].alignment["word"]:
print(alignment)
License
Metadata
Release files for torchfa 0.1.1
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 |
|---|---|---|---|---|
| torchfa-0.1.1.tar.gz | 9.2 kB | Without provenance | Details for torchfa-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| torchfa-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for torchfa-0.1.1-py3-none-any.whl |
Total release size: 19.3 kB
Release files / torchfa-0.1.1.tar.gz
| Download URL | torchfa-0.1.1.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
707d11854f481046086f1d78ce5beca08fe0ead4cac26eccbc062ef316dc2ec9
|
|
BLAKE2b-256 checksum How to use checksums |
6c3ec43dd359b7f4998b1da09a74ee1de2f8b15d75611268635ce422d4ba0b62
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / torchfa-0.1.1-py3-none-any.whl
| Download URL | torchfa-0.1.1-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6c6347640e250d9951db7ce29de6edd772bb1a5cf95890594900cb2f40790d3f
|
|
BLAKE2b-256 checksum How to use checksums |
1e33f3ddd6f89625ff8c1395e1471f9ce873c2c61493aaff97d73ab3445cbee4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for torchfa 0.1.1
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.