Two hours of waiting, down to fifteen minutes.

A self-hosted speech studio that runs on a tiny shared server, and borrows a laptop's speed whenever the laptop is around.

Rendered on the Mac   Picked up by the serverIllustration of a lesson changing hands

Why this project exists.

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 key objectives

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.

Small box, firm rules.

The idea was simple. The constraints made it an interesting systems problem.

1 vCPU, 2 GB RAMNo GPU, and no room for a heavy model server.
A live neighbourAnother production app shares the host and always wins.
No new billsNo paid speech API or extra infrastructure.
Long jobsA crash at minute 37 can't mean starting over.
A laptop that wandersIt sleeps, unplugs and changes networks.
Zero inbound portsThe laptop is never reachable from the internet.

One queue, two engines.

The server owns all state. Workers only borrow a job, one at a time, and can lose it safely at any moment.

Phone or desktopInstallable web app with a persistent player and resume
Mac workerNative ONNX inference in a killable child process. Outbound HTTPS only.
nginxTLS, rate limits and strict upload caps

Isolated Docker Compose project

StudioNext.js 16 UI and API, job queue, built-in fallback worker
SQLiteJobs, leases and every chunk
FFmpegStreaming MP3 assembly
Speech enginekokoro-onnx on a private network, with no internet access
  1. NormaliseMarkdown becomes speakable text
  2. ChunkSentences of 300 characters or fewer
  3. LeaseOne worker owns the job
  4. SynthesizeEach finished chunk is stored
  5. AssembleAudio and pauses become one MP3

From a tap to a track.

Follow one lesson through every layer, from the phone, through the server and the speech model, and back to the car stereo.

Pull the plug. Keep the audio.

This simulation uses the real rules at compressed timing. Interrupt the Mac and watch a lesson change hands without losing a chunk.

Ready0 of 96 chunks

Start a lesson, then try to break it.

The decisions that mattered.

Each one came from a specific way this system could fail.

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.

Fenced leases stop zombie workers.

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.

Heartbeats decide what's dead, not job age.

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.

The database makes overlap impossible.

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');

The chunk is the unit of durability.

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.

The new app is built to lose.

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.

Boring where it counts.

Every tool earned its place against the memory budget.

NeedChosenWhyPassed over
Speech modelKokoro v1.0 int8Natural voices, small enough for CPUPaid speech APIs
Inferencekokoro-onnx, ONNX RuntimeFits under a 700 MB limitPyTorch server, expected to need 1 to 1.5 GB
Allocatorjemalloc, one arenaWith one inference thread, cut peak from 698 to 632 MBDefault glibc allocator
AppNext.js 16, React 19UI and API in one standalone serverSeparate frontend and backend
Interfaceshadcn/ui, Tailwind v4Owned components, mobile-firstHeavy component libraries
DatabaseSQLite, node:sqliteReal transactions with no extra servicePostgres and Redis
AudioFFmpegStreaming, sample-accurate assemblyIn-memory concatenation
Mac installuv, hash-locked depsReproducible, matches server versionsUnpinned pip install
Mac lifecyclelaunchdLogin start and crash restart, no rootA custom daemon
Mac secretsmacOS KeychainToken never sits in a config filePlain-text env files

9.4×faster on an M1 laptop than on the server

58unit and API tests, including a 10,000-step queue simulation
101local fault-injection checks with real engines and shortened timers
24production checks across generation, fallback and handback

Locked down by default.

  • Read-only, non-root containers with all capabilities dropped
  • Speech engine has no public port or internet access
  • Hashed passwords, sessions and revocable worker tokens
  • Strict schemas and validated audio uploads

Honest limits.

  • One lesson generates at a time, by design
  • Single-user app
  • Slow when the Mac is away
  • iOS may suspend web audio in the background