Tilawa
[!IMPORTANT]
2.0 is out. It ships the Tilawa v2 engine and models (68 MBfull, 25 MBlite), which follow the reciter word by word and catch memorization mistakes as you recite: wrong, missed and extra words, and skipped passages. On 388 held-out learner clips, 91.9% offull's warnings were real mistakes and it caught 81.4% of them (lite: 93.3% / 80.0%). The API and event schema are unchanged from 1.0.
> It flags memorization mistakes only for now (no tajweed or pronunciation grading yet, and fast hadr or kids' voices aren't supported).
> Help us get to 1.0: recite 2–5 minutes the way you normally do at tilawa.dev/help, or try it live at tilawa.dev.
Offline, streaming Quran recitation engine. It follows a reciter word by word and flags memorization mistakes (wrong, omitted and added words, and skipped passages) as they happen, entirely on-device: in the browser, Node, and (soon) React Native. Audio never leaves the device.
@tilawa/core is TypeScript with no runtime dependencies. You install the ONNX Runtime for your platform as a peer dependency.
Upgrading from 1.0? Your code keeps working; the default models change. See Upgrading from 1.0 to 2.0. From 0.x, see the 0.x migration guide.
Install
npm i @tilawa/core onnxruntime-web # browser
npm i @tilawa/core onnxruntime-node # Node
onnxruntime-web ≥ 1.19, onnxruntime-node ≥ 1.20. Node ≥ 20.12.
In the browser, onnxruntime-web's .wasm files load from https://tilawa.dev/v2/runtime/ort/ by default. The versions hosted there are listed in /v2/manifest.json (1.30.0 at the time of writing). For any other version, pass wasmPaths or self-host.
Browser
import { createTilawa } from "@tilawa/core/web";
// Downloads the model and the Quran reference once, then serves them from the Cache API.
const tilawa = await createTilawa({ onProgress: (p) => (bar.value = p.fraction) });
const session = tilawa.startFreeRecitation();
session.subscribe((e) => {
if (e.type === "position" && e.observed[0]) highlight(e.observed[0].word); // { surah, ayah, word }
if (e.type === "checker" && e.state === "confirmed") mark(e.location, e.errorClass);
});
const mic = await tilawa.listen(session); // microphone → session
// …
await mic.stop(); // stops the tracks, then ends the session
console.log(session.mistakes());
tilawa.dispose(); // releases the ONNX session
listen() needs a secure context (https or localhost). If it can't open the microphone it rejects with a MicrophoneError whose reason is "denied", "unavailable" or "insecure-context".
A declared passage
When the app knows what the reciter is about to read, for example a page on screen, start a memorization session for it:
const session = tilawa.startMemorization(
{ surah: 18, fromAyah: 60, toAyah: 70 },
{ confirm: { after: "next-word" } }, // confirm a mistake once the next word starts (default: 2.5 s after it)
);
The tracker then stays inside the passage, and position events carry the word the reciter should be on (expected).
Node
import { createTilawa, readWav } from "@tilawa/core/node";
const tilawa = await createTilawa(); // model cached in ~/.cache/tilawa; the reference ships in the package
const session = tilawa.startMemorization({ surah: 1, fromAyah: 1, toAyah: 7 });
session.subscribe((e) => {
if (e.type === "checker" && e.state === "confirmed") console.log(e.errorClass, e.location);
});
const { samples, sampleRate } = await readWav("take.wav");
for (let i = 0; i < samples.length; i += 4800) session.pushAudio(samples.subarray(i, i + 4800), sampleRate);
await session.end();
console.log(session.mistakes());
await tilawa.dispose();
pushAudio takes audio at any sample rate. Calls run one at a time in call order, so a capture callback doesn't need to await them. Use modelDir to load a model directory you already have, or cacheDir to put downloads somewhere else.
Events
The event schema is versioned (v: 1). Every session sends three kinds of event:
capabilitiescomes first. It lists which error classes the model supports and which it doesn't, and carriesmodelVersion(the model id),modelRelease,referenceVersion,sdkVersion,modelSha256,tierandbackend. Both model sets support the four memorization classeswrong_word,omitted_word,added_wordandskipped_passage.position: where the reciter is.observedlists candidates, best first, each with aword({surah, ayah, word}, 1-based word index), aspanand aconfidence.stateisacquiring,locked,ambiguousorlost. Whileambiguous,hypothesescan list the competing places, best first. In memorization sessionsexpectedis the passage word the reciter should be on.checker: a possible mistake, with anidthat stays the same across its states. Each one goessuspected→confirmed, orresolved(a self-correction), oruncertain(the audio was too unclear to judge). It carrieserrorClass,location, and theexpected/observedphonemes. For a word recited more than once,occurrencecan say which recitation the decision belongs to.
timeMs on position and checker events is the session audio clock: ms of 16 kHz audio delivered since the first sample. session.now() reads the same clock. ayahsRecited(events) gives the ayahs recited, in order.
Sessions
- A session is one take.
end()drains the audio and decides every open mistake. It is idempotent, and after it startspushAudiorejects withSessionEndedError. To start again, start a new session. dispose()drops a session's subscribers and buffers.tilawa.dispose()disposes every session and releases the model.session.idis a uuid.session.startedAtis the wall-clock time of the first sample, andsession.policyis the policy with its defaults filled in.- Policy:
confirm({ after: "delay", ms }or{ after: "next-word" }),minConfidence(default 0.6), andcountSelfCorrections(default false: resolved mistakes aren't inmistakes()).
Models and hosting
| Tier | Model | Size | Picked when |
|---|---|---|---|
| full | tilawa-v2-full-c16-l128-int8@1 | 68 MB | default |
| lite | tilawa-v2-lite-c16-l128-int8@1 | 25 MB | tier: "auto" on a device reporting under 4 GB of memory, on iPhone and iPad, or on another phone or tablet |
By default the browser entry loads from https://tilawa.dev/v2/: models from models/, the reference from reference/ref-v3.json, and the onnxruntime-web WASM files from runtime/ort/. These files are immutable; a new model or reference gets a new path. Downloads are checked against the sha256 in the bundled registry.
- The 1.0 models: pass
models: "v1"to loadspliced-clean@1-int8andspliced-clean-lite@1-int8withref-v2fromhttps://tilawa.dev/v1/. - Self-hosting: mirror that layout and pass
assetBase. - Offline: pass
reference(import@tilawa/core/assets/ref-v3.json;ref-v2.jsonfor the 1.0 models) and amodelyou loaded withloadWebModel/loadNodeModel. If you serve the WASM files yourself, passwasmPathstoloadWebModel(with your ownmodel,createTilawadoesn't use it).
createTilawa with TilawaLoadError (stage: model or reference), ModelIntegrityError or ModelBudgetError. Pass signal to cancel a download.
Packages
| Import | What |
|---|---|
| @tilawa/core | Runtime-neutral engine: createEngine, event types, loadReferenceIndex, the model registry, ayahsRecited, errors |
| @tilawa/core/web | createTilawa, prepareMicrophone, loadWebModel, startMicrophone, cacheStorage, decodeWav |
| @tilawa/core/node | createTilawa, loadNodeModel, loadNodeTier, fsStorage, readWav |
| @tilawa/core/react-native | createTilawa, loadNativeModel. Experimental: not yet validated on devices. onnxruntime-react-native 1.24.3 needs four build fixes |
| @tilawa/core/report | Opt-in problem reports (no audio is kept or sent unless the app asks) |
| @tilawa/core/assets/*.json | ref-v3.json, ref-v2.json, phrases-v1.json |
Documentation
- Quickstart: web, Node, declared passages, cleanup, errors, iOS
- API reference: every export, events, lifecycle, version policy
- Support matrix: browsers, Node, React Native, model sizes
- Self-hosting and offline use
- Reporting: opt-in problem reports
- Upgrading from 1.0 to 2.0
- Migrating from 0.x
- Model card
- Contributors: recite at tilawa.dev/help, privacy
Licence and credits
The code is MIT. The v2 models are trained on tarteel-ai/tlog (Tarteel, CC-BY-4.0); Salama1429/tarteel-ai-everyayah-Quran, azizbekphd/ikhlas_recitations, obadx/muaalem-annotated-v3, obadx/qdat and sobolev210/quran-recitation-errors (MIT); fawazahmed0/quran-audio (CC0-1.0); rabah2026/Quran-Ayah-Corpus and zaibihassan/Quranic-Recitation-Data (Apache-2.0); and consented contributor recordings (help/v1, field-dev-v2). The list is in each model's manifest (trainingSources). The 1.0 listener model is trained and evaluated on tlog (Tarteel, CC-BY) and Quranic Universal Ayahs / the QUD alignment benchmark (QUD Technologies, CC-BY). It is distilled from obadx/muaalem-model-v3_2 (MIT) and uses the quran-transcript phoneme inventory (MIT). The architecture and export follow k2-fsa icefall (Apache-2.0). The Quran text derives from Tanzil. Full notices: NOTICE.md.
This repository
packages/tilawa-core/: the SDK.src/engine/andsrc/runtime/are copied from the research engine at a pinned commit byscripts/sync-engine.mjs. Don't edit them by hand.packages/core/,packages/sdk/: the research engine and runtime, with the lab (tools/lab.py,modal/) that measures every change. Lab history shows every experiment and the improvements over time.web/: the demo at tilawa.dev.