Skip to content

DoReCo: read any DoReCo language - #20

Merged
SanderGi merged 23 commits into
KoelLabs:mainfrom
RaunakGengiti2725:doreco-multilingual
Nov 20, 2026
Merged

SanderGi merged 23 commits into
KoelLabs:mainfrom
RaunakGengiti2725:doreco-multilingual

Conversation

@RaunakGengiti2725

@RaunakGengiti2725 RaunakGengiti2725 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

PR Description

Summary

  • The DoReCo loader can now read any DoReCo language, not only Southern British English. The default is still English.
  • For English, the IPA, audio and text match main on all 577 items. Two things change. Timestamps now count from the start of each clip, and speaker info has 5 new keys.
  • Tested on every English, Nǁng and Sümi item with real audio, and on the annotations of all 53 DoReCo languages.
  • Dataset notes are in docs/datasets/DoReCo.md.

Worth a look

  • core/codes.py turns three X-SAMPA marks into spaces, so the loader fixes them itself for now. This could move into core/codes.py instead.
  • 21 of the 53 languages have an NC, ND or SA license, and language="all" includes them right now.
  • The commits are small and can be read one at a time. I'm happy to split the PR if that is easier.

Q/A checklist

  • If you added new dependencies, did you update the requirements.txt file? pip freeze > requirements.txt
  • Run formatting and security checks gitleaks detect && zizmor . && black .

Legal Boilerplate

Look, I get it. The entity doing business as "Koel Labs" needs some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Koel Labs can use, modify, copy, and redistribute my contributions, under its choice of terms.

RaunakGengiti2725 and others added 23 commits November 6, 2026 03:29
Building an item filtered the whole phone table and decoded the whole
recording again, so one pass over the 577 English items took minutes,
at under 2 items per second. The table is now split into one list of
rows per utterance in a single pass, and decoded recordings are kept in
a 4-recording LRU cache. Clips are returned as copies, so a caller that
changes a clip cannot change the cache.

The CSVs inside the annotation zip are now found by the end of their
name, because DoReCo 2.0 bundles name them differently from the 1.3
bundle that English uses.

__del__ and __len__ no longer raise after a failed constructor. Before,
a missing audio zip also raised an AttributeError during cleanup.

No output changes: the golden snapshot of all four call patterns and a
fingerprint of all 577 English items are identical to main.
The loader now takes language=: a glottocode, a list of them, or "all"
for every language whose annotations and audio are on disk. Each
language lives in .data/DoReCo/<glottocode>/ and is found by glob, with
its audio as loose WAV files or a zip of them. The flat English files
the loader used before are still found first, so existing copies keep
working.

doreco_language_table.json is a trimmed copy of DoReCo's own table of
languages (fetched Nov 4, 2026), with names, licenses and download
links. A missing bundle or WAV now raises an error that names it and
says where to download it, and an unknown glottocode lists the valid
codes.

The metadata name prefix now comes from the glottocode. The
extended-audio zip is opened only when an item needs it, so the empty
placeholder file is no longer required. Speaker splits stay English
only for now.

No change for the default call: the golden snapshot of all four call
patterns and a fingerprint of all 577 English items are identical to
main.
core/codes.py turns ~, _v and _t into a space, and DoReCo uses them:
nasalized and voiced clicks and vowels in Nǁng, breathy l and n in
Sümi. Without a fix, 786 of 1,007 Nǁng utterances and 44 of 1,207 Sümi
utterances would have a space in their IPA. Until shared code is
fixed, the loader maps these three marks to the IPA in the X-SAMPA
table and counts each use in self.mark_uses.

Each distinct phone unit is now converted once, at construction. An
utterance with a unit that still cannot be used (a KeyError, a space
or angle bracket in the IPA, or a bare _ read as a tie bar) is
skipped and counted by reason in self.skipped, so no KeyError reaches
an item. So are utterances with no real phone, which used to crash,
and, for safety, ones with a missing word id. One summary line per
language reports the counts, and self.vocab now holds the IPA phones.

English has none of these units: the golden snapshot and a fingerprint
of all 577 items are identical to main. Nothing is skipped in English,
Nǁng or Sümi.
core/audio.py reads a WAV by assuming 16-bit samples right after a
44-byte header. DoReCo serves WAV files from many projects, and a
file with another header or sample format would come out as noise
without any error. The loader now decodes WAVs with soundfile, which
is already pinned in requirements.txt, then averages the channels and
resamples exactly as core/audio.py does.

An item whose last phone ends after the end of its recording now
raises an error that names the WAV file. Before, a cut or wrong file
gave a short or empty clip without a word.

The English WAV files are 16-bit PCM with a 44-byte header, so their
audio is unchanged: the golden snapshot and a fingerprint of all 577
English items are identical to main.
The loader returns a clip cut from the recording, but its phone
timestamps were counted from the start of the whole recording, so for
all 577 English items they pointed 0.09 to 983.5 s past the clip.
Code that uses them as indices into the audio, such as
split_utterance_into_multiple in common.py, got the wrong samples.
Every start and end is now counted from the start of the clip, so the
first phone starts at 0. This fix was approved at Gate A as its own
commit.

Only timestamps change. For all 577 English items, every timestamp is
the old one minus its item's crop start, and IPA, audio, text and
metadata are identical. The golden snapshot differs only in the
timestamps of the one call pattern that asks for them.
With more than one language in a dataset, each item has to say which
language it is from and under which licenses its annotations and audio
are, since these differ by language. The speaker info dict gains
language (the glottocode), language_name, annotation_license and
audio_license, from doreco_language_table.json.

A metadata row describes a whole recording, and in a conversation it
lists several speakers, such as spk_code "AA1/RZ1" in Sümi. So the
dict also gains utt_spk_code, the one speaker of the utterance, taken
from the phone table.

Only new keys are added: for all 577 English items every existing key
keeps its value, and IPA, audio, timestamps and text are unchanged.
For English, utt_spk_code always equals spk_code.
A zip handle kept open for later items was shared by every worker
process forked from the dataset, as a DataLoader forks it, and the
workers moved each other's file position. In a test with 2 workers
after the parent had read one item, 7 of 116 reads failed. The open
handle also kept the dataset from being pickled for workers that are
started fresh. Each recording is now read with its zip open only for
that read, which adds one small zip directory read per decoded
recording. With no handle left to close, __del__ goes away.

The decoded recording is returned from a local variable, so a cache
size of 0 no longer raises a KeyError. While several languages are
read, only the last one's tables are kept, instead of every table
until the constructor returns.

Output is unchanged: the golden snapshot and the fingerprint of all
577 English items are identical to the previous commit.
A file that is not a zip, such as a download that was cut short or an
error page saved under a .zip name, raised BadZipFile with no file
name, and one such file in any language folder also stopped
language="all". A WAV that soundfile could not decode raised an error
that named only an in-memory buffer. Both errors now name the file and
say what to do: every zip is opened through one open_zip helper, and a
decoding error is raised again as a ValueError with the WAV's path.

Output is unchanged for files that can be read.
The check added in 7a511d7 raises when an utterance's last phone ends
after the end of its decoded recording, to catch cut or wrong WAV
files. A phone that ends right at the end of a file could still trip
it by a few samples, through rounding of the annotation times or of
the resampled length, which core/audio.py rounds down. 10 ms are now
allowed. A truncated WAV still fails, and so does a file 50 ms short.

The English recordings end 8,240 to 158,032 samples after their last
phone, so English output is unchanged.
Items are found by utterance id. If two languages read together had an
id in common, the second language's rows silently replaced the
first's, and the dataset lost utterances that its summary line still
counted. Reading such languages together now raises a ValueError that
names the id and both languages. In all 53 DoReCo core bundles on
disk, no kept id appears in two languages, so no real output changes.
* language=None raised a TypeError. It now raises the same ValueError
  as an empty list.
* A set of glottocodes was read in set order, which changes with
  PYTHONHASHSEED, and so did the item order. A set is now read in
  sorted order.
* Loose WAV files were found only with a lower-case .wav, while WAVs
  in zips matched any case. Both now match any case.
* Data folder paths went to glob unescaped, so a path with [ or ] in
  it found nothing. They are now escaped.

Output is unchanged for the default call and for lists of languages.
Comments, docstrings and string literals only, after the independent
review of the branch:
* The header gives the English license and says exactly what was
  tested on real data, including that no item of another language has
  been read with its real audio yet.
* The three converted X-SAMPA marks cite the X-SAMPA chart, and the
  splitting into symbols cites xsampa2ipa in core/codes.py.
* Comments that told the history of a line are gone, an unsourced
  size is dropped, and the decoding docstring no longer says that any
  WAV format works.
* f-strings with no placeholder become plain strings, and a comment
  that black had wrapped around a value now sits above it.

No behavior changes: the golden snapshot and the fingerprint of all
577 English items are identical to the previous commit.
The loader read an English item from the Multi-CAST zip of extended
recordings when its metadata row was marked extended. DoReCo's
extended recordings have no phone rows, so no item can come from
them: in all 53 DoReCo core bundles, every phone row is core. The
branch, the AUDIO_ZIP constant and the per-item read of the extended
column are removed, and every recording is found through the same
lookup.

Output is unchanged: the golden snapshot and the fingerprint of all
577 English items are identical to the previous commit.
A missing WAV file raises FileNotFoundError at the first item that
needs it, with the WAV name and where to download it, and not when
the dataset is built. So the annotations can be read without the
audio, as the annotation-only checks of other languages do. The
constructor docstring now says this in one line.

Docstring only. The golden snapshot and the fingerprint of all 577
English items are identical to the previous commit.
The resampler in core/audio.py makes 64-bit arrays as long as the
whole recording, so it is where reading a recording needs the most
memory. decode_wav now reads the WAV itself and frees the file's bytes
and the samples of every channel before the resampler runs. It also
averages the channels a block of rows at a time, in int16, so no
float64 copy of the whole recording is made for the average.

On Linux, peak memory for all 577 English items once goes from
1,934 MB to 1,692 MB. Main needs 1,811 MB for items 0 to 9.

Output is unchanged. The golden snapshot and the fingerprint of all
577 English items are identical to the previous commit, and the
channel average equals np.mean on synthetic files with 1 to 6
channels.
The header now says that English, Nǁng and Sümi were read and
checked with their real audio on Nov 7, 2026. Every Nǁng and Sümi
item was read, and each clip has the length its annotation times
give. No other language has been read with its real audio yet.

Comments only. The golden snapshot and the fingerprint of all 577
English items are identical to the previous commit.
For units like a:~, the loader wrote the tilde after the length mark.
In Unicode a combining mark belongs to the character before it, so the
tilde marked the length mark and not the vowel. Now each of the three
marks in XSAMPA_MARKS goes in front of the length marks right before
it, so a:~ gives ã and then ː.

This changes 9 units and 1,668 kept phones in 1,043 utterances, in
Anal, Hoocąk and Texistepec. No other label of the 53 languages
changes, and no time, count or list of utterances does. The
fingerprint of all 577 English items is identical to the previous
commit.
Alex asked for notes on each dataset, such as how much of the
annotation was done by people or by machine, how the annotators were
trained, and what cleaning was done or is still needed. These are
the notes for DoReCo. The repo had no docs folder, so this place is
only a proposal, and the file is easy to move.

They cover English, Nǁng and Sümi in detail, and the other 50
languages from their annotations only. Each section names its
sources, the DoReCo files, papers and web pages, and the repo's code
with line numbers.

No code changes. DoReCo.py and doreco_language_table.json are the
same as in the previous commit.
A review of the notes found claims that went further than the runs
show. On Linux, most of each memory peak is the shared resampler. On
the Mac, a process that reads several recordings holds far more, and
why is not known. The notes now say this. They also say what each
commit was tested on, which machine and commit each timing comes
from, and where the memory numbers come from. They name commit
b051100 where they mean it, and a local checksum file is no longer
listed as a source.

No code changes. DoReCo.py and doreco_language_table.json are the
same as in the previous commit.

@SanderGi SanderGi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@SanderGi
SanderGi marked this pull request as ready for review November 20, 2026 01:59
@SanderGi
SanderGi merged commit 52c51f4 into KoelLabs:main Nov 20, 2026
2 of 3 checks passed

This branch had an error being deployed

1 failed deployment
security — a4f3b7b3 Deployed Nov 20, 2026 by SanderGi via gitleaks #383
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants