Workers pull. Nothing connects to the laptop.
Why: the Mac needs no open port, VPN or stable address, and works from any network.
Passed over: SSH tunnels and webhooks, which add attack surface and break when the network changes.
A self-hosted speech studio that runs on a tiny shared server, and borrows a laptop's speed whenever the laptop is around.
I undertook this project as part of my ongoing professional development in enterprise software architecture, particularly my preparation for TOGAF.
Balancing work, family commitments and professional learning makes it difficult to dedicate uninterrupted time to reading lengthy study materials. I wanted to make better use of my daily commute by converting structured lessons into audio that I could listen to while driving.
Although commercial text-to-speech platforms are available, relying on them for lengthy and frequent lessons could introduce recurring subscription costs, usage limitations and dependency on third-party services.
This led me to develop Audio Lesson Studio, a private, self-hosted text-to-speech platform designed around my personal learning needs.
The resulting solution combines a lightweight cloud-hosted application with local processing on my Mac, achieving approximately nine times faster audio generation while retaining the VPS as an automatic fallback.
Beyond solving a personal productivity challenge, the project also provided an opportunity to explore practical AI integration, distributed workload processing, resource optimization and resilient system architecture.
Ultimately, the project was not about building another text-to-speech application. It was about using technology to make continuous learning more accessible, practical and sustainable within my everyday life.
The idea was simple. The constraints made it an interesting systems problem.
The server owns all state. Workers only borrow a job, one at a time, and can lose it safely at any moment.
Isolated Docker Compose project
Follow one lesson through every layer, from the phone, through the server and the speech model, and back to the car stereo.
This simulation uses the real rules at compressed timing. Interrupt the Mac and watch a lesson change hands without losing a chunk.
Start a lesson, then try to break it.
Each one came from a specific way this system could fail.
Why: the Mac needs no open port, VPN or stable address, and works from any network.
Passed over: SSH tunnels and webhooks, which add attack surface and break when the network changes.
Why: a laptop can wake up after losing its job and keep writing. Every write carries an epoch token, and stale ones are refused.
Passed over: a plain locked_by column, which can't stop a stale worker.
Why: a healthy three-hour job must never look stuck. Recovery starts after 15 minutes of silence.
Extra guard: a worker that heartbeats but delivers no audio loses the job too.
Why: synthesis plus FFmpeg at the same time is a memory risk on 2 GB. Testing caught exactly that overlap, so the rule moved into the schema.
CREATE UNIQUE INDEX one_active_job ON jobs((1))
WHERE status IN ('running', 'assembling');Why: failure costs one chunk at most. Crashes, restarts and handoffs all resume at the next unfinished chunk.
Bonus: uploads are idempotent, so a network retry can't corrupt a lesson.
Why: the existing production app comes first. The speech engine has a hard 700 MB limit, no swap and a low CPU weight, and it's first in line for the OOM killer.
Result: no out-of-memory kills across long runs, with at least 706 MB left free on the host.
Every tool earned its place against the memory budget.
| Need | Chosen | Why | Passed over |
|---|---|---|---|
| Speech model | Kokoro v1.0 int8 | Natural voices, small enough for CPU | Paid speech APIs |
| Inference | kokoro-onnx, ONNX Runtime | Fits under a 700 MB limit | PyTorch server, expected to need 1 to 1.5 GB |
| Allocator | jemalloc, one arena | With one inference thread, cut peak from 698 to 632 MB | Default glibc allocator |
| App | Next.js 16, React 19 | UI and API in one standalone server | Separate frontend and backend |
| Interface | shadcn/ui, Tailwind v4 | Owned components, mobile-first | Heavy component libraries |
| Database | SQLite, node:sqlite | Real transactions with no extra service | Postgres and Redis |
| Audio | FFmpeg | Streaming, sample-accurate assembly | In-memory concatenation |
| Mac install | uv, hash-locked deps | Reproducible, matches server versions | Unpinned pip install |
| Mac lifecycle | launchd | Login start and crash restart, no root | A custom daemon |
| Mac secrets | macOS Keychain | Token never sits in a config file | Plain-text env files |
9.4×faster on an M1 laptop than on the server