📚 Encyclopedia

Tools & Workflow · updated 2026-11-09

Generating narrated screencast tutorials from a script (PIL + Piper TTS + ffmpeg)

videotutorialsttspiperffmpegpillowpythonscreencastautomation

Programming tutorials can be produced without recording a screen or a voice: write each episode as a small script of narration lines and editor/terminal actions, then render it to a video. Frames are drawn with Pillow, narration comes from a local text-to-speech engine, and ffmpeg encodes the result. In 2026-11 eight 1 to 1.5 minute H language tutorials were made this way and published on videos.jhampton.io; all eight render in parallel in about 40 seconds.

The episode script

A small line-based DSL. A beat is one narration line (spoken and shown as a caption) plus the screen actions that play while it is spoken:

# title: Hello, H
> Programs live in files ending in dot underscore.
@file hello._
@type echo "hello";
> Compile and run it.
@run hc hello._ && ./hello

Useful directives: @file (new editor buffer), @type (typed at a fixed characters-per-second rate, multi-line up to @end), @set (show code instantly), @erase N / @eraseline, @write name ... @end (a data file the program reads, not shown), @run cmd (type a command in the terminal pane and show its output), @clear, @mark A-B (highlight lines), @pause S. A caption can carry a separate spoken form: > Caption || what the voice says.

Run the real code at render time

Every @run really executes in a temp dir, and the video shows the actual output, including compiler errors. Write every command and its output to a log next to the video. After any language change, re-render and read the log: if the narration claims something the compiler no longer does, the log shows it. This is the main advantage over hand-made screencasts, which silently go stale. - Clear test-only environment (here H_SEED, which fixes the random seed) so the demo behaves like a user's run, and put the tool's install dir on PATH.

Narration with Piper

Piper is a fast, offline neural TTS. Install it in its own venv (pip install piper-tts) and download a voice model (en_US-ryan-high.onnx from the rhasspy/piper-voices collection on Hugging Face). Each beat is synthesized to its own WAV; the beat lasts as long as the longer of its audio and its screen actions. - Rewrite text for the ear before synthesis: code reads badly aloud. Strip backticks, and map tokens to words: hc → "H C", ._ → "dot underscore", ++ → "plus plus", == → "equals equals", fn → "F N", and the single letter H → "aitch" (otherwise TTS may say "huh"). Listen to at least one episode; a rule list never catches everything.

Rendering

Publishing

Upload newest-first if the site lists new items at the top, so a series reads 1, 2, 3 in order. Keep a README with the re-render + republish recipe, because a language change means replacing videos, not editing them.

See also

Linked from

Sources: h memory (video-tutorials), h repo tutorials/, post #1887