Skip to navigation

Forced alignment

A recording and what is said in it, back as word and sound timestamps.

POST /v1/audio/alignments takes an audio file and its transcript and returns when every word was said, the timing of every sound inside it, and how well each word fits the audio. Fillers, laughter, breaths and cut-off words get timestamps of their own. English only. $0.25 per audio hour.

1

Get a key and top up

The same key and prepaid wallet as transcription. See Quickstart and Billing.

2

Align

Send the file and the transcript as multipart/form-data.

curl https://api.nyra-labs.com/v1/audio/alignments \
-H "Authorization: Bearer $NYRA_API_KEY" \
-F "file=@clip.wav" \
-F "model=nyra-forced-aligner-en" \
-F "language=en" \
-F "text=Just change our p- but that's [laughter] just change our priorities a little bit"

Parameters

FieldNotes
filerequiredOne audio file, up to 25 MB and 1 hour, in any accepted format.
textrequiredWhat is said in the recording, written as below. Up to 200 000 characters.
modelrequirednyra-forced-aligner-en. Anything else answers 400 model_not_found.
languageoptionalen, the default. Any other value answers 400 unsupported_language.

Transcript conventions

The aligner places exactly what the transcript contains, so write what you hear, not a cleaned-up version:

WriteForExample
Every word as spokenrepetitions, false starts, restartswe we need to, to reschedule
[UH], [UM]filled pausesso [UM] I think
[tag]vocal sound events, see belowthat's [laughter] just
A trailing hyphenwords broken off mid-waythe th- Thursday meeting
Words, not digitsnumbers, dates, times, emailsMarch third at nine thirty

Casing and punctuation are ignored, and tags match in any casing ([Laughter], [um]). CrisperWhisper’s verbatim.text already follows these conventions: send it as text unchanged. The Quickstart has the two calls, transcribe then align, in curl and Python.

Vocal sound events

Each tag is a unit of the model like a phone, so the event gets its own word in the response, with type: "sound":

TagPhone in the response
[laughter]LAU
[breath]BRE
[cough]COF
[sigh]SGH
[sniff]SNF
[lipsmack]LPS
[throatclearing]TCL
[yawn]YWN
[sneeze]SNZ
[crying]CRY
[scream]SCR
[fart]FRT
[noise]NSN

[UH] and [UM] come back with type: "filler" and the phones FUH and FUM. A tag the model does not know, such as [music], is left out of the alignment and listed in skipped.

When the transcript is wrong

The transcript is taken as true. A word that was said but is missing from it is absorbed by its neighbours; a word in it that was never said is squeezed into a few frames. Both shift the boundaries around them and both show up as low confidence. A transcript of a different recording fails with 400 alignment_failed or alignment_too_complex, and is not charged.

Response

{
"duration": 4.98,
"language": "en",
"words": [
{
"word": "our", "start": 0.54, "end": 0.93, "type": "word", "confidence": 0.796,
"phones": [
{ "phone": "AW", "start": 0.54, "end": 0.71 },
{ "phone": "AX", "start": 0.71, "end": 0.93 }
]
},
{
"word": "p-", "start": 0.93, "end": 1.09, "type": "cutoff", "confidence": 0.931,
"phones": [{ "phone": "P", "start": 0.93, "end": 1.09 }]
},
{
"word": "[laughter]", "start": 2.5, "end": 2.85, "type": "sound", "confidence": 0.873,
"phones": [{ "phone": "LAU", "start": 2.5, "end": 2.85 }]
}
],
"skipped": [],
"usage": { "type": "duration", "seconds": 5 }
}
FieldMeaning
wordsEvery transcript token in order, as you wrote it (punctuation kept), except those in skipped.
start, endSeconds from the start of the recording, 10 ms resolution. Words never overlap; gaps between them are silence.
typeword, filler ([UH], [UM]), sound (a vocal sound event) or cutoff (a fragment ending in -).
phonesThe word’s sounds in order, covering exactly its span: ARPAbet phones (TH, ER, AY, …) or the event units above.
confidence0 to 1: how well the audio under the word fits it. See below.
skippedTokens that could not be aligned: unknown tags and tokens without a pronunciation.
duration, usageDecoded audio duration in seconds, and the billed whole seconds.

Confidence

This is a different number from the confidence on transcription words: that one is the speech model’s certainty about what was said, this one is how well the audio fits the word where it was placed. A word can be high on one and low on the other, and checking both catches more than either alone.

Per 10 ms frame, the aligner compares the sound it placed there with the best-fitting sound of the whole model; confidence is that fit averaged over the word, from 1 (perfect) down to 0.

confidenceTypically
0.8 to 1The word is there and its timing can be trusted. Two thirds of correct words.
0.5 to 0.8Fast, reduced or mumbled speech. Almost always fine.
0.3 to 0.5Worth a look if exact timing matters.
below 0.3The transcript is likely wrong here: misheard, or next to speech it leaves out.
  • Look at runs. One low word is usually a short or reduced one. Several in a row mean the transcript and the audio disagree there, typically speech that was not transcribed.
  • Cut-offs and very short words score lower by nature. Judge them against their own kind, not against a fixed threshold.
  • It ranks, it does not correct. The timestamps are the same either way; use it to filter words or to send stretches to review.

Python

import os
import requests
with open("clip.wav", "rb") as audio:
response = requests.post(
"https://api.nyra-labs.com/v1/audio/alignments",
headers={"Authorization": f"Bearer {os.environ['NYRA_API_KEY']}"},
files={"file": ("clip.wav", audio, "audio/wav")},
data={
"model": "nyra-forced-aligner-en",
"language": "en",
"text": "so we [UH] we need to reschedule the th- Thursday meeting [laughter]",
},
timeout=600,
)
response.raise_for_status()
for word in response.json()["words"]:
flag = " <- check" if word["confidence"] < 0.5 else ""
print(f"{word['start']:6.2f} {word['end']:6.2f} {word['word']}{flag}")

Pricing and limits

$0.25 per audio hour, billed per second: $0.000069 per second, with the duration rounded up to a whole second per request. Funds are held before the audio is aligned and only what was used is charged; a request that fails is not charged. See Billing.

The limits are those of transcription: 25 MB per upload and one hour of audio per request, so send long recordings compressed (an hour of 48 kbps MP3 is about 22 MB). An hour aligns in one request with no drift: the last minute is as accurate as the first. Idempotency-Key works as for transcription, bound to the model, the language and the exact transcript.

Errors

The envelope and the general errors are those of transcription. Specific to alignment:

StatuscodeWhen
400missing_required_parametertext (or file, model) was not sent or is empty.
400unsupported_languagelanguage is not en.
400model_not_foundmodel is not nyra-forced-aligner-en.
400alignment_failedThe transcript cannot be placed in the audio: it belongs to another recording, or it is longer than the audio can hold. Not charged.
400alignment_too_complexThe same on a long recording, found out after a wider search. Not charged.
503capacity_exceededThe aligner is busy. Retry after retry-after. Not charged.