tilawaتلاوة

Blog ·

Tilawa v2: state-of-the-art Quran recitation recognition, fully on-device

Tilawa v2 listens while you recite the Quran, follows you word by word and catches memorization mistakes. It's open source, and it runs entirely on your phone or laptop.

The fun part: an AI agent ran the whole thing. Google's Gemini 4 Neon, working as the lead agent in T3 Code, took my plan and carried it from research to finished models in 6 days. It split up the work, handed pieces to helper agents, ran every training job in the cloud, caught its own bugs and ran the final tests. I sent it 25 messages along the way, and three of them were some version of "keep going".

Card: Tilawa v2, run end to end by Gemini 4 Neon. 6 days, 132 hours of agent time, 29 helper agents, 18 training runs, about $3,600 of cloud compute, and 25 messages from the human running it.
Gemini 4 Neon led every step, from the plan to the frozen test results.

What it cost: about $3,600. That's the whole cloud GPU bill on Modal for the week: data prep, training and testing. The AI agents ran on subscriptions we already had, so they aren't in that number.

How an AI agent built it#

I'm not a machine-learning engineer. v2 exists because an AI agent did the engineering.

I wrote down what I wanted in a plan and handed it to Gemini 4 Neon, Google's model, running as the lead agent in T3 Code. Every one of its 66 working sessions ran on Neon. From there it:

  • Split the plan into jobs and handed them to 29 helper agents (a mix of Gemini, Claude and GPT), then checked and merged their work.
  • Gathered and cleaned the data, about 2,600 hours of it, and kept every test voice out.
  • Ran 18 training runs on Modal, including the big teacher, 11 small runs to test which ideas helped, and the final two models.
  • Watched them around the clock. When Modal paused a run, it explained why and resumed from the last save.
  • Caught its own bugs. 60,000 clips with no word breaks. A model inventing a syllable in the silence before people start reciting. A slowdown that made training 10–20× slower (fixing it cut each test run from about 37 hours to 2.5).
  • Ran the final tests once, on locked-away recordings, and reported the results.

How the week went:

  • Nov 24: plan handed over, data gathering starts
  • Nov 26: the teacher model is trained
  • Nov 28: all 11 test runs done
  • Nov 29–30: the final Full and Lite models are trained
  • Nov 30: frozen test results, and @tilawa/core 2.0 on npm the same evening

My part was 25 messages over those 6 days. A few steered it ("only use clean data", "give me a go/no-go before spending big on GPUs"), and a few just said "continue". I also stepped in when it ran out of quota and had to be moved to another account.

The cloud bill came to about $3,600, most of it (about $3,000) on training the small models, test runs included.

(The 132 hours on the card is time the lead agent was on the clock. A lot of that was waiting on training runs, so it's not 132 hours of pure thinking.)

What it does#

You recite. Tilawa does two things:

  1. It finds your place. Start anywhere in the Quran and it works out where you are, then follows along word by word. No need to pick a surah first.
  2. It catches slips. A wrong word, a missed word, an extra word or a skipped passage gets flagged as it happens.

It's made for the revision you do on your own, between lessons. It won't replace your teacher.

No cloud, no account, no API key. Your audio never leaves the device.

How good is it?#

We tested it only on recordings it never heard while it was learning. The main score is how many sounds it gets wrong, so lower is better.

Bar charts. Sounds got wrong on 191 real phone recitations: Lite 3.92%, Full 4.41%. On 159 learner clips: Lite 3.38%, Full 3.00%. Warnings users had marked wrong: 49 in v1, 1 in v2. Warnings over 7.5 hours of continuous recitation: 128 in v1, 21 in v2.
Every number here is from audio the models never trained on.

The short version:

  • 3.92%. That's how many sounds the small model gets wrong on everyday phone recordings. It's better than the strongest model we know of, tested on the same clips.
  • 89–94% of planted mistakes caught, on 15 reciters it had never heard.
  • 1 of 49. Users of v1 had marked 49 of its warnings as wrong. Replaying the same recordings, v2 raises just one of them!
  • 25 MB for the small model. It runs about 30 times faster than real time on a single laptop CPU thread.

It comes in two sizes. Lite (25 MB) is the one for phones, and it's also the more accurate one on phone audio (it learned from two teachers, more below). Full (68 MB) is a little better on learners.

How it works#

Here's the trip from your mic to a highlighted word:

Diagram of how Tilawa v2 listens: your voice becomes a sound map, a streaming model turns it into a stream of 38 kinds of sounds, and a tracker and a checker read that stream
Audio goes in, a stream of sounds comes out every 40 ms, and two small programs read it.
  1. Your voice is turned into a picture of its pitches, 100 slices a second.
  2. A small model listens to that picture a third of a second at a time and writes down the sounds it hears: 38 kinds, every 40 milliseconds.
  3. The tracker matches those sounds against the whole Quran, written out as sounds ahead of time, and works out where you are.
  4. The checker compares what you said with what's written at that spot, and decides if a difference is a real mistake or just noise.

All four steps run on your device.

Animation: word shapes light up from right to left as they're recited; one skipped word is first marked suspected, then confirmed as a missed word
A skipped word is suspected first, then confirmed once you've clearly moved on.

The checker is careful on purpose. A red mark on a word you said correctly hurts trust more than a missed slip, so when the audio is noisy it asks for more evidence, and when it's very noisy it says "not sure" instead of guessing.

How it learned#

v1 learned from 535 hours of phone recordings. v2 learned from 2,601 hours: phone recordings, studio recitations from more than a hundred reciters, and real learners. Every clip had to be clean, correct recitation, so a lot of crowd audio didn't make the cut.

The trick is a teacher. First we trained a big model, about 600 million parameters. It's far too big for a phone, but it's very good (it gets 0.73% of sounds wrong on long phone sessions). Then the two small models learned from it.

Diagram: 2,601 hours of clean audio train a 600M teacher, which teaches the 65M Full model; the 22M Lite model learns from both
The teacher is too big to ship, so it teaches. Lite gets lessons from both the teacher and Full.

A few things made the biggest difference:

  • Learning from the teacher. The teacher doesn't just give the right answer, it shows how sure it is about every sound. That carries a lot more information.
  • Messing up the audio on purpose. Phone mics, call codecs, echo, noise, faster and slower recitation. This was the biggest single win, about 28% fewer errors on long phone sessions.
  • Scrambled words. A model that memorizes the Quran "hears" the next word before you say it, which is exactly wrong for catching memorization slips. So in some training clips the words came in random order.
  • Real learners. A short last round on 2,873 learner recordings.

We also kept every test voice out of training, so nothing it was graded on had been heard before.

Private by design#

Tilawa runs on your device. The audio is heard, matched and forgotten on the phone or laptop it was recorded on. No upload, no account, no API key, and after the first download it works offline.

Animation: a phone hears audio and matches words on the device, and a cloud is crossed out
Nothing leaves the device.

The only recordings we ever see are ones people choose to send from our help page, and each one asks first. Of the 168 sessions in this round, 23 said no to training, so those 23 were never used.

Get it#

Tilawa is open source. The SDK is @tilawa/core on npm, and it runs in the browser, in Node and (experimentally) in React Native.

npm i @tilawa/core onnxruntime-web   # browser
npm i @tilawa/core onnxruntime-node  # Node

A browser session, start to finish:

import { createTilawa } from "@tilawa/core/web";

// downloads the model and the Quran reference once, then serves them from the cache
const tilawa = await createTilawa();

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();
console.log(session.mistakes());
tilawa.dispose();

If your app knows what the reader is about to recite (a page on screen, say), tell it. The tracker stays inside that passage:

const session = tilawa.startMemorization({ surah: 18, fromAyah: 60, toAyah: 70 });

By default it picks Lite on iPhone, iPad and low-memory devices, and Full everywhere else. Apps on @tilawa/core 1.0 get v2 by upgrading the package.

Two model sizes: Full is 68 MB and Lite is 25 MB; on one CPU thread a minute of recitation takes about 2 seconds on Lite and about 3 on Full
A minute of recitation, done in about 2 seconds on Lite.

Links:

The code is MIT. The weights are CC BY 4.0, so you can use them in commercial apps as long as you credit "Tilawa (tilawa.dev)".

What it can't do yet#

It's good, and it's not finished.

  • Memorization mistakes only. It doesn't grade tajweed or pronunciation.
  • Hafs only. Other qira'at won't be followed well.
  • Adults only, so far. Children's voices haven't been tested.
  • No very fast recitation (hadr) yet.
  • Picky on short learner clips. It catches fewer slips there than v1 did (80–81% vs 87.5%), in exchange for far fewer false alarms. That's the number we most want to raise next.
  • Speed was measured on laptops. Real mid-range phones are next.
  • React Native support is experimental.

For the nerds#

Everything above, with the details left in. Skip this if you just want to use it.

The model. A streaming Zipformer2 encoder (from k2's icefall, Apache 2.0) reads 80-band log-mel features in 320 ms chunks and emits CTC posteriors over 38 tokens every 40 ms. Full is 65M parameters, Lite 22M. Besides the main head there's an early copy of it from the first layers (deep layers start to "know" the Quran and correct what they hear, so when the two disagree the checker listens), plus 20 ms heads for duration, shadda, boundaries and frame confidence. The engine is TypeScript with no runtime dependencies, on ONNX Runtime.

The 38 tokens (tilawa-atomic-v3): blank, a word boundary |, 28 consonants, the ikhfa nasal, short a/i/u, long aa/ii/uu, and one "foreign" token for breath and filler. v1 used 43 single-phone tokens and spelled shadda and long vowels as repeats, which CTC can only emit with a blank between them, so it learned to drop them (142 deletions on one clean benchmark, against 5 for the best model we compared). v2 never repeats a sound inside a word, and shadda has its own head. The reference is the Hafs text from Tanzil, phonemized with the MIT-licensed quran-transcript, with every legal waqf and ibtida variant.

The teacher is w2v-BERT 2.0 (583.7M parameters, MIT), fine-tuned on the same tokens and heads on 8 GPUs: 0.55% PER on long studio sessions, 0.73% on long phone sessions. The students did 8 passes of Arabic pretraining, then distillation on the teacher's full posteriors and hidden layers, phone augmentation (mic coloring, WebRTC AGC, Opus/AAC/AMR, clipping, reverb, noise down to 0 dB, tempo 0.85–1.25× with the teacher's targets stretched to match), scrambled-word batches (20%), and 2 passes of learner adaptation on 2,873 recordings (6.1 h). Full trained for 22 passes, Lite for 25 with both teachers.

Ablations. 11 smaller runs (1,500 h, 8 passes each), scored on dev sets only:

idea with it without it
Arabic pretraining (Full, studio) 2.80% 3.02% (English start)
Arabic pretraining (Lite, long phone) 3.82% 4.52% (from scratch)
teacher's hidden layers too (long phone) 3.97% 4.31% (outputs only)
any distillation (studio) 2.80% 3.13%
phone augmentation + scrambled words (long phone) 4.00% 5.58%
one chunk size instead of five (everyday phone) 8.17% 8.41%

Bugs found along the way:

  • About 60,000 older auto-labeled clips had no word-boundary markers, so the model learned word breaks were optional (11% worse boundaries on phone clips). Dropping them took the corpus from 2,701 to 2,601 hours and closed the gap within 400 steps.
  • Training clips were trimmed tight, but real people press record and wait. The teacher invented a syllable in that silence. Padding clips with random silence took phone error from 7.4% to 4.2% in 1,000 steps.
  • The new token stream broke free-recitation tracking at first: on three phone sessions it was on the right place 0.09% of the time. After the fix, 99.65%, with missed mistakes down from 34 to 3 and false warnings from 28 to 1.
  • The new noise gates shipped too cautious and caught 66% of mistakes on phone practice audio. Tuned on dev data, 84%, with the same single false warning.

Tracking and checking. The tracker reports acquiring, locked, ambiguous or lost, and keeps the top three candidates alive through repeated phrases (mutashabihat) until a word settles it. It was on the right place 99.8% of the time across 15 unseen reciters. Each possible mistake goes suspected → confirmed, resolved (you corrected yourself) or uncertain. The checker scores how much better "what you said" fits than "what's written" over the word and its neighbors, with both heads and every legal stop or join, and raises the bar with an uncertainty score built from frame confidence, posterior spread and local SNR.

How we measured. Models and engine were frozen, then scored once on sets locked away from the start: 191 human-verified phone clips, 159 learners, 15 unseen reciters with 532 planted mistakes (about 7 hours, studio and phone), 388 clips from 29 held-out learners, 84 sessions from 67 real users (174 minutes), and 7.5 hours of continuous recitation (juz 1–13). The headline error rates come from a head-to-head run on one laptop with the strongest other model we know of, on identical clips and an identical reference. On learners that model scored 2.77%, so Full is a quarter of a point behind there.

v1 v2 Lite v2 Full
warnings users had marked wrong (84 unseen users) 49 1 1
raw warnings, 7.5 h continuous recitation 128 Lite, 88 Full 21 26–28
learner clips: warnings that were real 90.3% 93.3% 91.9%
learner clips: mistakes caught 87.5% 80.0% 81.4%

(The 7.5-hour counts are raw, and some are probably real slips by the reciter.)

FAQ#

What is Tilawa v2?#

Tilawa v2 is an open-source Quran recitation recognition engine that runs entirely on your device. It follows a reciter word by word anywhere in the Quran and flags memorization mistakes (wrong, missed and extra words, and skipped passages) as they happen.

How accurate is it?#

On 191 everyday phone recitations it never saw in training, the 25 MB Lite model gets 3.92% of sounds wrong, better than the strongest model we know of on the same clips. It catches 89–94% of planted memorization mistakes on unseen reciters, and raises 1 of the 49 warnings users had marked wrong in v1.

Who built it?#

An AI agent did the engineering. Google's Gemini 4 Neon led the work as an agent in T3 Code over 6 days, with 29 helper agents (Gemini, Claude and GPT), for about $3,600 of cloud compute on Modal.

Does it work offline?#

Yes. After the first download the model and the Quran reference are cached, and everything runs on the device with no server and no API key.

Is my audio uploaded?#

No. The audio is processed on your device and never sent anywhere.

Does it check tajweed?#

Not yet. v2 flags memorization mistakes only: wrong, missed and extra words, and skipped passages. It doesn't grade pronunciation or tajweed rules.

Can I use it in a commercial app?#

Yes. The code is MIT and the model weights are CC BY 4.0, which allows commercial use with credit to "Tilawa (tilawa.dev)".

Which model should I use, Lite or Full?#

Lite (25 MB) for phones, and it's also the more accurate of the two on everyday phone audio. Full (68 MB) is slightly better on learners and catches a few more mistakes (94% vs 89% on unseen reciters). The SDK's default picks for you.


Recite a few ayahs at tilawa.dev and watch it follow along.