Skip to main content

Etalon: where every word and every letter of a known text begins and ends in its sound

How it works | Live demo | PyPI

PyPI version Python 3.9 or newer Code licence: Apache 2.0 Bank licence: CC BY-SA 4.0 Languages: Serbian, Croatian Needs numpy only Demo on Hugging Face

Etalon finds where every word and every letter of a known text begins and ends in a recording of it (forced alignment). It uses no neural model and needs no training and no graphics card: the whole method is a few hundred lines of numpy and a small bank of sounds that ships with the package.

  • Serbian and Croatian, measured. Bosnian and Montenegrin work the same way and are not measured yet.
  • Between half a minute and two minutes of work on a desktop processor for an hour of sound.
  • A recording and its plain text are enough; no times, no subtitles and no cutting are needed.
  • Works on one recording, or on a whole dataset read as a stream from Hugging Face.
  • From the command line, from Python, or on a page in the browser.

The method is described in Etalon.

Install

pip install cawn-etalon              # one recording at a time
pip install "cawn-etalon[hf]"        # also whole datasets (adds huggingface_hub and pyarrow)

The command and the Python module are both called etalon.

Python 3.9 or newer. A plain 16 kHz mono .wav is read directly; any other sound needs ffmpeg on the path.

Use

In the browser

etalon ui

A page opens on this computer (nothing is sent anywhere). Drop a recording, paste its text, and hear the result with the word that sounds lit. The same page lays whole datasets and makes banks for other languages, and shows the log of everything it works on.

Command line

etalon recording.wav text.txt                       # -> recording.srt, recording.json
etalon recording.mp3 text.txt --format srt,vtt,json,tsv,textgrid,html --out folder/name
etalon recording.wav subtitles.srt                  # only the text of the subtitles is used

--format html writes a page to hear the result. On it, red words are the tenth of the words that fit their sound worst and yellow the next 15 %. These marks are relative: a tenth of the words is always red, in the best result too. They say where to listen first, not that a word is wrong.

Python

import etalon

result = etalon.align("recording.wav", "text.txt", lang="sr")
for word in result["words"]:
    print(word["word"], word["start"], word["end"])     # seconds
etalon.save(result, "name", ("srt", "json"))

Every word also has its letters (letter, start, end), a mark (higher fits better) and a doubt (0, 1 or 2). result["fit"] and result["match"] say whether the text belongs to the sound.

A whole dataset

Every row a sound and its text. A Hugging Face repository is read as a stream, so nothing is downloaded whole; a folder of parquet files on disk works too.

etalon dataset OWNER/NAME                                # shows the columns it has
etalon dataset OWNER/NAME --audio_column audio --text_column text --limit 100 --html 20
etalon dataset OWNER/NAME --audio_column audio --text_column text --speaker_column speaker --push OWNER/NEW

The rows are written out as parquet with new columns: words, letters, etalon_slide, etalon_mark, etalon_ok. --html 20 adds a page to hear the first 20 rows. --push sends the result to a new repository, which is made private; its licence is yours to set.

Languages

--lang language bank of sounds measured
sr Serbian its own (Serbian parliament) yes
hr Croatian the Serbian one yes
bs, me Bosnian, Montenegrin the Serbian one not yet
any other code a language said the way it is written made by you, once (below) no

A bank for another language is made once, from a dataset that already has the times of its letters (a list of {letter, start, end} per row, from another aligner). After that Etalon lays that language by itself:

etalon bank OWNER/NAME --lang sl --audio_column audio --letters_column letters --speaker_column speaker
etalon recording.wav text.txt --lang sl

The bank is kept in ~/.etalon/bank_sl.pkl. With --speaker_column it is made in two rounds, every speaker moved to a standard voice first, as the Serbian one was; without it in one round, and it is blunter.

Numbers written in digits are read out: by Etalon's own tables for the four languages above, by the package num2words for the others it knows. Where neither can, write the numbers as words.

Languages written one way and said another (English, French) are beyond this method: they would need a dictionary of pronunciations.

Accuracy

The share of word starts that lie within 50 ms of the times of another aligner. Those times are not the truth, only the ruler that exists.

speech against within 50 ms
Serbian parliament, short pieces times published with ParlaSpeech-RS 93.8 % (MFA on the same: 93.9 %)
Serbian videos, short pieces, one speaker (14 videos) Montreal Forced Aligner 88.5 %
Serbian video of 90 minutes, several speakers Montreal Forced Aligner 87.3 %
Serbian, a whole hour from its plain text Montreal Forced Aligner 85.4 %
Croatian parliament, one hour, Serbian bank times published with ParlaSpeech-HR 81.2 % (97.1 % within 100 ms)

Settings

Every setting is an argument of the command; three of them can also be set as a variable of the terminal.

argument variable what it does
--lang CODE ETALON_LANG the language (default sr)
--slide MODE ETALON_SLIDE one voice or several. auto (default): Etalon decides. video: one voice, the fastest. piece: always several
--fit 65 ETALON_FIT the text must explain at least so many percent of the start of the sound, or a warning is given and the command exits with 2
--bank NAME which bank of sounds (default auto)
--minutes N only the first N minutes of the recording
ETALON_DATA a folder with other banks

How it works

  1. Rows. The sound becomes one row of 26 frequency bands every 10 ms. A slide moves the bands of a speaker towards a standard voice; there are 9 slides.
  2. Bank. From speech whose letter times are known, the bank keeps the usual row of every half of a letter together with its neighbour.
  3. Path. The text becomes a chain of letter halves and silences, and the chain is stretched over the rows of the sound so that the sum of the fits is the largest.
  4. Voices. Pieces spread over the recording each pick the slide that fits them. If they agree it is one voice; if they do not, several people talk and every piece gets its own slide.

Limits

  • The text must be what is said. Abbreviations must be written the way they are spoken; numbers in digits are read in their basic form.
  • The check "does the text belong to the sound" looks only at the first minute and a half, and works only where the recording is mostly speech. With street noise or music and little speech a wrong text can pass.
  • Bosnian, Montenegrin and banks made for other languages are not measured.
  • The times of word ends agree with other aligners less than the times of word starts.

Development

pip install -e ".[dev]"
pytest            # needs no sound
black .           # line length 110
module what
config.py constants and file locations
features.py the rows of the sound, the 9 slides
bank.py the bank of sounds, and making one
path.py a text stretched over the rows of its sound
slide.py the slide; one voice or several
align.py align and align_all: what is called from outside
text.py, numbers.py, languages.py reading the text, numbers, languages
audio.py reading the sound
output.py srt, vtt, json, tsv, TextGrid, html
dataset.py whole datasets, and banks for other languages
cli.py, ui.py, ui.html the command line and the page in the browser

Licence

The code is under the Apache License 2.0 (see LICENSE).

The bank of sounds, etalon/data/bank_parliament.pkl, is derived from ParlaSpeech-RS 4.0 (CLARIN.SI) and is shared under the same licence, CC BY-SA 4.0.

Metadata

Release files for cawn-etalon 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cawn-etalon 0.1.1
File Size Uploaded Provenance Actions
cawn_etalon-0.1.1.tar.gz 472.6 kB Without provenance Details for cawn_etalon-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cawn-etalon 0.1.1
File Interpreter ABI Platform Actions
cawn_etalon-0.1.1-py3-none-any.whl Python 3 none any Details for cawn_etalon-0.1.1-py3-none-any.whl

Total release size: 949.2 kB

Release files / cawn_etalon-0.1.1.tar.gz

Download URL cawn_etalon-0.1.1.tar.gz
Size 472.6 kB
Tags Source
SHA-256 checksum
How to use checksums
848b5c57209655e7c44b1fff64ae65a1447b1d5a693cc4bb41384bd1af742a7d
BLAKE2b-256 checksum
How to use checksums
6d43c97f0bed44faa4d1ca7693f2d4ca20aabb380aa6e2e1e22df8644fc80ead
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Release files / cawn_etalon-0.1.1-py3-none-any.whl

Download URL cawn_etalon-0.1.1-py3-none-any.whl
Size 476.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
70c43536ad58c15d52e7b0c5bc04b517322fcb7cbbed4e612841652fb506efb5
BLAKE2b-256 checksum
How to use checksums
c9d33a6e7441910bd0c42f11182914ee11672a64e418320ec23a0f8f94d112e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Security for cawn-etalon 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page