Metadata-Version: 2.4
Name: nyra-forced-aligner
Version: 0.3.0
Summary: Verbatim-aware, noise-robust forced alignment: precise word and phone timestamps for conversational speech, including fillers and vocal sounds
Author: nyra health GmbH
License: MIT
Project-URL: Homepage, https://nyra-labs.com/research/nyra-forced-aligner
Project-URL: Repository, https://github.com/nyrahealth/nyra-forced-aligner
Project-URL: Models, https://huggingface.co/nyralabs
Keywords: forced alignment,speech,word timestamps,phonetics,disfluency,multilingual,xls-r,wavlm
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24
Requires-Dist: torch>=2.0
Requires-Dist: soundfile>=0.12
Requires-Dist: soxr>=0.3
Requires-Dist: transformers>=4.40
Requires-Dist: huggingface_hub>=0.20
Requires-Dist: phonemizer>=3.2
Requires-Dist: numba>=0.58
Requires-Dist: tqdm
Requires-Dist: espeakng-loader>=0.2.4
Requires-Dist: anyascii
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Provides-Extra: ja
Requires-Dist: fugashi>=1.3; extra == "ja"
Requires-Dist: unidic-lite>=1.0.8; extra == "ja"
Requires-Dist: pykakasi>=2.2; extra == "ja"
Provides-Extra: denoise
Requires-Dist: inworld-voice-isolation>=1.0.0; extra == "denoise"
Requires-Dist: mamba-ssm>=2.2; extra == "denoise"
Requires-Dist: causal-conv1d>=1.4; extra == "denoise"
Requires-Dist: einops; extra == "denoise"
Requires-Dist: torchaudio; extra == "denoise"
Requires-Dist: cupy-cuda12x; extra == "denoise"
Dynamic: license-file

# nyra forced aligner (multilingual)

[![PyPI](https://img.shields.io/pypi/v/nyra-forced-aligner)](https://pypi.org/project/nyra-forced-aligner/)
[![Models](https://img.shields.io/badge/%F0%9F%A4%97%20models-nyralabs-yellow)](https://huggingface.co/nyralabs)

**Precise word timing for real speech in 16 languages, and the only forced
aligner that puts exact timestamps on vocal sound events: fillers, laughter,
breaths, coughs and cut-off words.**

[Blog post](https://nyra-labs.com/research/nyra-forced-aligner) ·
[Paper](https://arxiv.org/abs/2610.22583) ·
[Code](https://github.com/nyrahealth/nyra-forced-aligner) ·
[PyPI](https://pypi.org/project/nyra-forced-aligner/) ·
[CrisperWhisper](https://github.com/nyrahealth/CrisperWhisper)

A forced aligner answers one question: given a recording and its transcript,
*when* was each word said? Most aligners were built for read speech and clean
audio, and they quietly fall apart on the material people actually need to
align: conversations full of `um`s, laughter, restarts and half-finished words,
recorded in rooms that are not studios.

This model was built for exactly that material.

- **Vocal sound events are aligned, not smeared.** Other aligners have no way
  to represent a laugh, a breath or an `um`: the sound is either dropped or
  absorbed into the neighbouring words, which pushes their boundaries off.
  Here fillers (`[UH]`, `[UM]`), laughter, breaths, sighs, coughs, sniffs,
  lip smacks, throat clearing, yawns and word cut-offs (`th-`) are units of
  the acoustic model like any phone, in every language. Each one gets a start
  and an end time of its own.
- **Made for CrisperWhisper transcripts.** Trained on the verbatim
  transcription convention of
  [CrisperWhisper 2.0](https://github.com/nyrahealth/CrisperWhisper): feed
  its output straight in and every filler, repetition and event token is
  aligned.
- **16 languages, one backbone.** One shared XLS-R encoder and a 5-12 MB
  model folder per language. The encoder is downloaded and loaded once,
  however many languages you use.
- **Accurate on conversational speech.** 18.4 ms mean word-boundary error on
  Buckeye, the lowest of any forced aligner we have measured.
- **Robust to noise.** With the built-in voice isolator (`denoise=True`) the
  same model stays accurate on noisy and reverberant recordings.
- **Fast and longform.** About 600x real time on one GPU: a 20 s clip aligns
  in about 30 ms. Any audio length works in one call.

## Install

```bash
pip install nyra-forced-aligner
pip install "nyra-forced-aligner[ja]"        # Japanese (MeCab)
pip install "nyra-forced-aligner[denoise]"   # voice isolator for noisy audio (CUDA)
```

Runs on CPU, but a CUDA GPU is strongly recommended. The shared backbone
(about 0.5 GB) and the folder of the language you ask for are downloaded from
the [model repository](https://huggingface.co/nyralabs/nyra_forced_aligner_multilingual) on first use.

## Quickstart

```python
from nyra_align import Aligner

aligner = Aligner()                         # English
# aligner = Aligner(language="de")          # any of the 16 languages
# aligner = Aligner(denoise=True)           # noisy audio

result = aligner.align("interview.wav",
                       "so i [UM] i went there on on thursday [laughter]")

for w in result.words:
    print(f"{w.start:7.3f} {w.end:7.3f}  {w.word:<12s} {w.type}")   # w / f(iller) / s(ound) / c(ut-off)

result.to_textgrid("interview.TextGrid")     # Praat
result.to_json("interview.json")
```

Output (illustrative):

```text
  0.410   0.580  so           w
  0.580   0.660  i            w
  0.660   1.120  [UM]         f
  1.240   1.330  i            w
  1.330   1.560  went         w
  ...
  2.870   3.640  [laughter]   s
```

Every word also carries its phones and a `confidence` between 0 and 1.
`result.events` returns just the fillers, sounds and cut-offs,
`result.silences` the pauses between words.

Command line, single file or a whole corpus of paired `.wav` + `.txt`/`.lab`
files (MFA-style layout):

```bash
nyra-align interview.wav --text-file interview.txt --out interview.TextGrid
nyra-align corpus_dir/ --language de --denoise --out-dir aligned/ --format textgrid
```

## Noisy audio

For noisy, reverberant or phone recordings, switch on the built-in voice
isolator. It cleans the audio before alignment; the timestamps refer to the
original recording.

```python
from nyra_align import Aligner

aligner = Aligner(language="en", denoise=True)      # needs a CUDA GPU

result = aligner.align("street_interview.wav",
                       "yeah so [UM] we we moved here in two thousand nine [laughter]")
for w in result.words:
    print(f"{w.start:7.3f} {w.end:7.3f}  {w.word:<12s} {w.type}  {w.confidence:.2f}")
```

```bash
pip install "nyra-forced-aligner[denoise]"
nyra-align street_interview.wav --text-file street_interview.txt --denoise --out street_interview.TextGrid
```

The isolator is loaded once per process and shared by every `Aligner`, so
several languages can run with `denoise=True` side by side. On clean audio it
changes the result very little (see [Under noise](#under-noise)), so leave it
off there and save the time: alignment alone runs at about 600x real time,
with the isolator at about 60x.

## Vocal sound events

The transcript tells the aligner what to place, so it should be **verbatim:
write what you hear.**

| In the audio | Write | Type in the result |
|--------------|-------|--------------------|
| Filled pauses | `[UH]`, `[UM]` | `f` |
| Laughter, breath, sigh, cough, sniff, lip smack, throat clearing, yawn, sneeze | `[laughter]`, `[breath]`, `[sigh]`, `[cough]`, `[sniff]`, `[lipsmack]`, `[throatclearing]`, `[yawn]`, `[sneeze]` | `s` |
| Interrupted words and fragments | trailing hyphen: `th-`, `w-`, `resched-` | `c` |
| Everything else | word for word, repetitions and false starts included | `w` |

```text
so we we need to, to reschedule the th- Thursday meeting to [UH] March third at nine thirty [laughter]
```

Normal casing and punctuation are fine; the aligner ignores both. Numbers,
dates and times are written out as spoken. A word that was spoken but is
missing from the transcript gets absorbed into its neighbours, and a word that
was never spoken is squeezed into a few frames, so both shift the surrounding
boundaries. A tag the model does not know (`[music]`) is left out and listed
in `result.skipped`. English additionally knows `[noise]`, `[crying]` and
`[scream]`.

## With CrisperWhisper 2.0

[CrisperWhisper 2.0](https://github.com/nyrahealth/CrisperWhisper) produces
transcripts in exactly this convention: it writes down fillers, repetitions,
cut-offs and vocal events as they were said. Its verbatim output can be
aligned as is, which gives every word *and* every sound event a precise start
and end:

```python
from crisperwhisper import CrisperWhisperModel
from nyra_align import Aligner

audio = "interview.wav"
transcript = CrisperWhisperModel("large").transcribe(audio, language="en").text
# "so i [UM] i went there on on thursday [laughter]"

result = Aligner(language="en").align(audio, transcript)

for w in result.events:                       # fillers, laughter, cut-offs
    print(f"{w.start:7.3f} {w.end:7.3f}  {w.word}")
result.to_textgrid("interview.TextGrid")
```

```bash
pip install "crisperwhisper[transformers]" nyra-forced-aligner
```

For another language, pass the same `language` to both.

## Languages

| Language | Code | Pronunciations | Size |
|----------|------|----------------|-----:|
| English | `en` | lexicon + eSpeak | 6 MB |
| German | `de` | dictionary + eSpeak | 12 MB |
| French | `fr` | eSpeak + unit map | 5 MB |
| Spanish | `es` | eSpeak + unit map | 5 MB |
| Italian | `it` | eSpeak + unit map | 5 MB |
| Dutch | `nl` | eSpeak + unit map | 5 MB |
| Polish | `pl` | eSpeak + unit map | 6 MB |
| Portuguese | `pt` | eSpeak + unit map | 5 MB |
| Russian | `ru` | eSpeak + unit map | 8 MB |
| Swedish | `sv` | NST lexicon + eSpeak | 10 MB |
| Danish | `da` | NST lexicon + eSpeak | 7 MB |
| Turkish | `tr` | eSpeak + unit map | 6 MB |
| Ukrainian | `uk` | spelling rules + eSpeak | 7 MB |
| Greek | `el` | eSpeak + unit map | 5 MB |
| Japanese | `ja` | MeCab + kana rules | 5 MB |
| Korean | `ko` | hangul rules + eSpeak | 7 MB |

All 16 share `xlsr/` (458 MB). `Aligner(language=...)` downloads that folder
once plus the folder of the language; several `Aligner` objects in one process
share one backbone in memory. Words outside a language's lexicon are
pronounced by the language's own grapheme-to-phoneme rules, the same ones used
in training.

## Performance (English)

Measured with the
[nyra speech timing benchmark](https://github.com/nyrahealth/nyra_speech_timing_benchmark)
on three test sets with hand-labelled word boundaries: **Buckeye**
(conversational, 2,008 recordings, 80k words), **TIMIT** (read sentences,
1,626 recordings, 14k words) and **FluencyBank** (stuttered speech, 300
recordings, 5.5k words). Every system gets the reference transcript and is
scored with the same protocol. MAE is the mean absolute word-boundary error;
≤ t ms is the share of words whose boundaries are within t of the reference
(F1 at that collar).

**Buckeye** (conversational speech)

| System | MAE (ms) | ≤25 ms | ≤50 ms | ≤100 ms |
|--------|---------:|-------:|-------:|--------:|
| **nyra forced aligner** (this package) | **18.4** | **65.7%** | **90.7%** | **97.9%** |
| **nyra forced aligner + voice isolator** (`denoise=True`) | 18.9 | **65.7%** | 90.6% | **97.9%** |
| Montreal Forced Aligner `english_us_arpa`, wide beam | 25.3 | 61.3% | 86.7% | 95.6% |
| Qwen3-ForcedAligner-0.6B | 39.4 | 28.7% | 74.9% | 94.3% |
| MMS-FA (torchaudio) | 52.7 | 15.2% | 49.9% | 86.5% |
| WhisperX (wav2vec2 alignment) | 89.8 | 0.9% | 7.9% | 48.6% |

**TIMIT** (read speech)

| System | MAE (ms) | ≤25 ms | ≤50 ms | ≤100 ms |
|--------|---------:|-------:|-------:|--------:|
| **nyra forced aligner** (this package) | **18.5** | **60.5%** | 86.5% | **97.9%** |
| **nyra forced aligner + voice isolator** (`denoise=True`) | **18.5** | **60.5%** | **86.6%** | **97.9%** |
| Montreal Forced Aligner `english_us_arpa`, wide beam | 18.6 | 58.3% | 84.5% | 96.9% |
| Qwen3-ForcedAligner-0.6B | 30.1 | 26.6% | 70.8% | 95.0% |
| MMS-FA (torchaudio) | 37.3 | 17.4% | 51.3% | 93.2% |
| WhisperX (wav2vec2 alignment) | 64.8 | 2.8% | 13.3% | 59.5% |

**FluencyBank** (stuttered speech)

| System | MAE (ms) | ≤25 ms | ≤50 ms | ≤100 ms |
|--------|---------:|-------:|-------:|--------:|
| **nyra forced aligner** (this package) | **73.7** | **34.4%** | **70.4%** | **87.2%** |
| **nyra forced aligner + voice isolator** (`denoise=True`) | 75.0 | 32.0% | 69.3% | 86.3% |
| Montreal Forced Aligner `english_us_arpa`, wide beam | 121.5 | 28.7% | 58.2% | 76.3% |
| Qwen3-ForcedAligner-0.6B | 109.4 | 14.3% | 44.6% | 73.7% |
| MMS-FA (torchaudio) | 154.8 | 12.1% | 37.5% | 65.0% |
| WhisperX (wav2vec2 alignment) | 171.8 | 2.3% | 7.5% | 39.6% |


### Under noise

The same three sets with white Gaussian noise added, from 30 dB down to 0 dB
signal-to-noise ratio, without and with the voice isolator. Each cell is
MAE in ms / share of words within 50 ms.

| Set | Voice isolator | clean | 30 dB | 20 dB | 10 dB | 5 dB | 0 dB |
|-----|----------------|---:|---:|---:|---:|---:|---:|
| Buckeye | off | 18.4 / 91% | 18.4 / 91% | 18.7 / 90% | 22.9 / 88% | 32.0 / 81% | 73.4 / 65% |
| Buckeye | **on** | 18.9 / 91% | 18.8 / 91% | 18.9 / 90% | 20.6 / 89% | 24.3 / 86% | 34.0 / 80% |
| TIMIT | off | 18.5 / 87% | 18.4 / 86% | 18.4 / 87% | 19.9 / 84% | 23.8 / 79% | 38.4 / 63% |
| TIMIT | **on** | 18.5 / 87% | 18.5 / 86% | 18.5 / 86% | 19.2 / 86% | 20.9 / 83% | 26.4 / 75% |
| FluencyBank | off | 73.7 / 70% | 72.7 / 70% | 76.3 / 69% | 90.5 / 62% | 109.5 / 53% | 166.3 / 37% |
| FluencyBank | **on** | 75.0 / 69% | 77.1 / 68% | 76.6 / 67% | 79.9 / 66% | 90.9 / 62% | 113.4 / 54% |

`Aligner(denoise=True)` runs the
[Inworld Voice Isolator](https://github.com/inworld-ai/voice-isolator)
(Apache-2.0) on the audio before the features are extracted, through a faster
inference path with the same weights (about 60x real time on one GPU). The
weights are part of the [model repository](https://huggingface.co/nyralabs/nyra_forced_aligner_multilingual) (`isolator/`, 256 MB) and are downloaded
the first time denoising is used. It needs a CUDA GPU and
`pip install "nyra-forced-aligner[denoise]"`.

TIMIT under the same noise next to other forced aligners:

| Mean absolute error (ms) | 30 dB | 20 dB | 10 dB | 5 dB | 0 dB |
|--------|---:|---:|---:|---:|---:|
| **nyra forced aligner + voice isolator** | 18.5 | 18.5 | 19.2 | 20.9 | 26.4 |
| **nyra forced aligner** | 18.4 | 18.4 | 19.9 | 23.8 | 38.4 |
| Montreal Forced Aligner `english_us_arpa`, wide beam | 17.9 | 20.7 | 39.5 | 71.6 | 152.4 |
| Qwen3-ForcedAligner-0.6B | 29.5 | 30.4 | 44.6 | 74.5 | 124.0 |
| MMS-FA (torchaudio) | 37.4 | 37.6 | 38.3 | 39.4 | 43.5 |
| WhisperX (wav2vec2 alignment) | 68.2 | 70.8 | 76.4 | 95.9 | 316.2 |

| Words within 50 ms / within 100 ms | 30 dB | 20 dB | 10 dB | 5 dB | 0 dB |
|--------|---:|---:|---:|---:|---:|
| **nyra forced aligner + voice isolator** | 86.5% / 97.8% | 86.4% / 97.8% | 85.5% / 97.3% | 83.0% / 96.1% | 75.4% / 91.9% |
| **nyra forced aligner** | 86.5% / 97.9% | 86.7% / 97.8% | 84.5% / 96.6% | 79.0% / 93.5% | 62.6% / 83.2% |
| Montreal Forced Aligner `english_us_arpa`, wide beam | 85.7% / 96.7% | 81.5% / 93.7% | 59.1% / 80.8% | 40.2% / 63.7% | 19.9% / 37.9% |
| Qwen3-ForcedAligner-0.6B | 72.3% / 95.3% | 70.8% / 94.2% | 51.5% / 82.5% | 29.7% / 60.7% | 13.2% / 34.6% |
| MMS-FA (torchaudio) | 51.1% / 93.1% | 50.8% / 93.0% | 50.3% / 92.1% | 49.5% / 90.8% | 46.9% / 86.6% |
| WhisperX (wav2vec2 alignment) | 12.2% / 56.7% | 11.1% / 54.3% | 8.9% / 49.2% | 6.1% / 40.0% | 1.6% / 14.1% |

## Options

| Option | What it does |
|--------|--------------|
| `Aligner(language="de")` | One of the 16 languages; the backbone is shared between them |
| `Aligner(denoise=True)` | Voice isolator on the audio before alignment |
| `Aligner(device="cuda" / "cpu")` | Device selection (auto by default) |
| `Aligner(precision="fp32")` | Backbone in fp32 instead of fp16 |
| `Aligner(wavlm_batch=16)` | Batch size for the 30 s backbone windows on long audio (tune to VRAM) |
| `aligner.align_features(feats, text)` | Re-align a transcript against cached features |
| `w.confidence` | 0-1 per word: how well the audio under the word fits it. Low values point at transcript errors and at words displaced by untranscribed speech next to them |
| `result.events` | Just the filler / sound / cut-off tokens |
| `result.silences` | Silence segments between words |
| `nyra_align.available_languages()` | The languages in the repository |
| `NYRA_ALIGN_MODELS=/path/to/repo` | Use a local copy of the [model repository](https://huggingface.co/nyralabs/nyra_forced_aligner_multilingual) instead of the Hub |

**Word confidence.** Per 10 ms frame the aligner compares the likelihood of
the sound it placed there with that of the best-fitting sound of the whole
model, and maps the mean gap over the word's frames to a value between 0 and
1. A word that really is where it was placed scores close to 1; a
transcription error, or a correct word pushed onto the wrong audio, scores
close to 0. Look at runs rather than single words: one low word in a fluent
stretch is usually a fast or reduced word, several in a row point at speech
the transcript leaves out or gets wrong. It is a fit score to rank and filter
by, not a probability, and it does not change the timestamps.

**Long recordings.** Any length works in one call. The audio is processed in
30 s windows that are stitched on the exact frame grid, so timestamps do not
drift: an hour aligned in one call is as accurate as the same hour aligned in
15 s pieces.

## How it works

Hidden states of a frozen XLS-R encoder (layers 18, 8 and 14) are projected
by a supervised LDA onto 40 dimensions and modelled by a triphone GMM-HMM
whose inventory holds the vocal-event units next to the language's phones.
For a transcript the package builds the alignment graph (optional silence
between words, full context across word boundaries) and runs a compiled beam
Viterbi over the model's likelihoods, with a beam ladder so that no utterance
is ever silently dropped. There is no Kaldi or other external toolkit at
inference.

Repository layout:

```
languages.json     the languages available
xlsr/              shared backbone: XLS-R 300M, layers 1-18 of 24, fp16
isolator/          voice isolator weights, downloaded only for denoise=True
<language>/        meta.json, model.npz, lexicon.txt, pronunciation data
```

## Limitations

- The transcript has to match the audio. Missing or extra words shift the
  boundaries around them; `confidence` flags such places.
- Accuracy is reported for English only.
- The voice isolator needs a CUDA GPU.

## License

The model files in the [model repository](https://huggingface.co/nyralabs/nyra_forced_aligner_multilingual) are released under the
[nyra health Non-Commercial Research License](https://huggingface.co/nyralabs/nyra_forced_aligner_multilingual/blob/main/LICENSE.md): free for research
and other non-commercial use. The license covers the model **and the
alignments it produces**: any commercial use of the timestamps, and any use of
them to train, fine-tune or otherwise improve models intended for commercial
use, requires a commercial license.
[Contact nyra health](mailto:licensing@nyra-labs.com).

The inference code (`nyra-forced-aligner`) is MIT-licensed. `xlsr/` is a
shortened copy of `facebook/wav2vec2-xls-r-300m` (Apache-2.0); `isolator/`
holds the unchanged Inworld Voice Isolator v1 weights (Apache-2.0, © Inworld
AI, with their LICENSE and NOTICE); the Swedish and Danish pronunciation
lexica derive from the NST lexica (CC0).
