Metadata-Version: 2.4
Name: afrospeech-recipes
Version: 0.1.2
Summary: Load the speech data a recipe describes, from wherever it lives.
Author-email: AfriModal AI <kaykola.olaleye@gmail.com>
License-Expression: Apache-2.0
Project-URL: Homepage, https://afrimodal-ai.github.io/
Keywords: speech,asr,african-languages,datasets,streaming
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.28
Requires-Dist: numpy>=1.23
Requires-Dist: soundfile>=0.12
Requires-Dist: scipy>=1.10
Provides-Extra: huggingface
Requires-Dist: datasets>=2.18; extra == "huggingface"
Dynamic: license-file

# The recipe loader

One call that loads exactly the speech a recipe describes, wherever the data
lives. The recipe comes from the builder page; paste it into a notebook and
run it.

```python
from afrospeech_recipes import load_recipe

ds = load_recipe(recipe, split="train", sample_rate=16_000, stream=True)
for ex in ds.take(3):
    print(ex["source"], round(ex["duration"], 1), "s", ex["text"])
print(ds.report())
```

Install it:

```
pip install "afrospeech-recipes[huggingface]==0.1.1"
```

The extra brings `datasets`, which only a Hugging Face source needs; a
recipe that reads a tar archive runs without it. Every script the builder
page hands out pins the version it was written against, because a recipe is
a record of what was fetched and a loader that changed under it is a
different answer.

## The data keeps its own terms

This licence covers the loader, not one second of audio. Every dataset keeps
the terms its publisher set: attribution, share-alike, no redistribution, an
access request, a non-commercial clause. A recipe carries the permission
answers that were recorded for each source and this loader checks them again
before it fetches, but a check in code is not a licence review, and a
permission nobody has read is not permission. Read each publisher's terms
before you train on their audio, and before you publish anything you trained.

## What version 1 does

- Hugging Face repositories, streamed: parquet, webdataset and audio folders.
- Tar archives over HTTP, read as a stream and never written to disk.
- Filters whole datasets, which is what the catalogue records today.
- Shares an hour budget over the sources using each dataset's recorded
  hours, so a budget is met to within one clip and `report()` says what was
  actually delivered.
- Resamples to one rate and returns one record shape whatever the source:
  `audio, text, duration, language, split, source, clip_id, speaker_id`.

## Stopping early ends the process

A script that takes a few clips and stops leaves a read in flight on
pyarrow's I/O threads. It then fails on the file the loader has closed,
retries, and Python cannot finish shutting down: on a free tier the run sits
there until the host kills it. So when a stream is stopped with sources left
unread, this loader ends the process itself once every other exit handler
has run, flushing stdout and stderr first, and exits 1 if an exception went
uncaught. That skips any `atexit` handler registered after this one and any
destructor still waiting, so if you open something beside the loader that
needs its own cleanup, close it before you stop taking clips. A stream read
to its end is unaffected.

## What it refuses to do

- Mix splits. A training recipe reads train splits only, and asking it for a
  test split raises rather than returning the audio.
- Read a source whose recorded terms do not allow the recipe's purpose. The
  permission answers travel inside the recipe and are checked again here, at
  the point the data is fetched.
- Keep audio. Clips are decoded, handed over and dropped.

## What is not here yet

- Per clip selection: length, speaker, topic and an exact hour budget all
  need the clip index, which is the next step.
- Adapters for zip archives, GitHub releases, cloud buckets, Dataverse and
  Zenodo, and for local copies of datasets that need a signed agreement.
- Writing shards or a NeMo manifest instead of streaming.

A dataset this loader cannot yet fetch correctly is never written into a
script. The builder page counts its hours, names it under the script, and
says why it is not in the code.

## Which datasets it can fetch

The loader fetches whatever a recipe names, and a recipe is written by the
builder page, which only writes a source it has checked: it asks each
publisher's repository what configs and splits it really has and which
columns a row carries, and records the date it asked. Nothing there is
inferred from a naming convention, and a dataset whose train and test split
is recorded somewhere other than the data itself is left out with that as
the stated reason, rather than loaded on a guess.
