All guides

ElevenLabs forced alignment: text and audio timestamps

Align existing audio and text, inspect character and word timings, and separate alignment from subtitle acceptance.

AINavWritten / Updated Sources checked
On this page

At a glance

Forced alignment places an existing transcript on an audio timeline. Both the audio and its text must already exist, making it useful for subtitles or word timings for a known reading. This task uses a short teaching sentence and produces an alignment response for review. No audio was submitted and no real timestamps are presented.

Task flow

  1. Matching materials

    Prepare sample.wav and the words actually spoken in it, not a rewritten transcript.

  2. Alignment request

    Send the file and a plain text string to forced_alignment.create.

  3. Review

    Inspect characters, words and loss, then compare word timings with the original recording.

The arrows show data and checks for this task; branches are explained in the text.

Prepare matching text and audio

Record the teaching sentence “A paper cup sits on the table.” as sample.wav. This specifies an input; it does not provide a fabricated recording. The transcript must match what the recording actually contains. The API reference requires a file smaller than 1GB, so this task uses a short file far below that limit rather than promoting the larger limit on the overview page. You need an existing API credential and available allowance.

Client and input format

Install the ElevenLabs SDK in your Python environment following the quickstart. Pass the key through ELEVENLABS_API_KEY, keeping it out of shared scripts. text is a plain string. Do not wrap its content in JSON or add speaker names and timing labels. The API reference says diarization is unsupported; speaker annotations do not enable a documented multi-speaker alignment feature.

Send the file with its corresponding text

Example: align an original teaching recording
python
import os
from elevenlabs.client import ElevenLabs

client = ElevenLabs(api_key=os.environ["ELEVENLABS_API_KEY"])
transcript = "A paper cup sits on the table."

with open("sample.wav", "rb") as audio:
    alignment = client.forced_alignment.create(file=audio, text=transcript)

print(alignment)

Save the script as align_audio.py beside sample.wav, supply the credential and run python align_audio.py. The file remains open during the request and closes when the with block exits. Inspect the actual printed object rather than filling in expected timestamps. Keep authentication or network errors; sending the request alone does not complete the task.

Read the returned fields

Response fields in the API reference
FieldPurpose
charactersEach character’s text, start and end, with times in seconds
wordsEach word’s text, start, end and per-word loss
lossTranscript-wide average alignment loss/confidence score calculated from characters

Check that start and end are numeric and ordered sensibly, then listen near the beginning, end and pauses. Field presence shows structural completeness, not accepted subtitle segmentation or timing accuracy. The page gives no universal acceptable loss threshold; do not invent a number and claim quality acceptance.

Hand the result to subtitle editing

Deliver the raw response and a review record covering text consistency, word timings and listening findings. Grouping words into subtitle lines, choosing display durations and line breaks are subsequent editing rules. A words array is not a finished subtitle file. When no transcript exists, start with speech-to-text; this alignment task does not infer a missing verbatim transcript.

Completion and unexecuted work

  • Audio and text represent the same reading, without speaker labels or JSON wrappers, and the file satisfies the current API reference.
  • The response contains characters, words and loss; inspect actual timings without fabricated test values.
  • Listen to selected passages and record questionable words or boundaries rather than dismissing them because the request succeeded.
  • Keep the raw response apart from an edited subtitle artifact and mark unperformed grouping as pending.

The overview, quickstart and API reference were read; the final cited sources are the quickstart and API reference listed here. No SDK was installed, login performed, audio uploaded or paid API called. The code illustrates the documented interface and supplies no observed alignment result.

Article sources

Original editorial content; official descriptions and checking suggestions are distinguished.

  1. ElevenLabs · Official sources
    View details
  2. ElevenLabs · Official sources
    View details