Turn annotated Python snippets into narrated screencast videos.
Project description
snippet-cast
Turn an annotated Python snippet into a narrated screencast video.
Narration is written as trailing #: comments on the snippet's own lines, so
the input stays valid, runnable Python:
def fib(n): #: We define fib, taking one argument, n.
a, b = 0, 1 #: Start from the first two Fibonacci numbers.
for _ in range(n): #: Loop n times.
a, b = b, a + b #: Advance the pair; b becomes the running sum.
return a #: Return a — the nth Fibonacci number.
Each #: line becomes one "beat": the code is revealed up to that line, the
line is highlighted, and its narration is spoken. snippet-cast renders
syntax-highlighted code frames with a progressive reveal, a Python-Tutor-style
live variable panel, optional burned-in captions and a typing-in animation,
synthesises speech per line, and stitches everything into an MP4 with ffmpeg.
Installation
Requires Python 3.10+ and ffmpeg (with ffprobe) on PATH.
pip install snippet-cast
# or
pixi add snippet-cast
# or
conda install -c munch-group snippet-cast
Usage
snippet-cast snippet.py -o out.mp4 --tts silent --subtitles # fast, voiceless proof
snippet-cast snippet.py -o out.mp4 --typing --subtitles # type each new line in
snippet-cast loop.py -o out.mp4 --every --subtitles # animate each loop iteration
Or from Python:
from snippet_cast import build
build("snippet.py", "out.mp4", tts="silent", subtitles=True)
Or in a Jupyter notebook — write the snippet directly in a cell instead of a
separate .py file:
pip install snippet-cast[jupyter]
%load_ext snippet_cast.magic
%%snippet-cast -o out.mp4 --tts silent --subtitles
def fib(n): #: We define fib, taking one argument, n.
a, b = 0, 1 #: Start from the first two Fibonacci numbers.
for _ in range(n): #: Loop n times.
a, b = b, a + b #: Advance the pair; b becomes the running sum.
return a #: Return a — the nth Fibonacci number.
result = fib(7) #: Call fib with seven; result becomes {result}.
The cell magic takes the same flags as the CLI and displays the rendered MP4 inline.
See SETUP.md for configuring the Piper (local) and ElevenLabs
(cloud) text-to-speech backends, and snippet-cast --help for all options.
Development
This repository is built from the munch-group library template.
Initial set up
pixi run init
Get updates to upstream fork
Add upstream if not already added
git remote add upstream https://github.com/munch-group/snippet-cast.git
Fetch upstream changes
git fetch upstream
Either rebase your changes on top of upstream (cleaner history)
git rebase upstream/main
Or, merge upstream into your fork (preserves history)
git merge upstream/main
If you want to see what's changed upstream before applying:
git log HEAD..upstream/main
See the actual diff
git diff HEAD...upstream/main
Then push your updated fork:
git push origin main
If you rebased and need to force push
git push origin main --force-with-lease
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file snippet_cast-0.1.35.tar.gz.
File metadata
- Download URL: snippet_cast-0.1.35.tar.gz
- Upload date:
- Size: 604.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e147866f666057e1d7317b3ff19b4a5718bb8aedc33f43644b7c6d31751371eb
|
|
| MD5 |
d6cd0a67b75633a40ad3e0aa5d236097
|
|
| BLAKE2b-256 |
ede6cdbeb4367aff57854306d73a22423e36b0f20eea9070a6cd08135c05f89e
|
File details
Details for the file snippet_cast-0.1.35-py3-none-any.whl.
File metadata
- Download URL: snippet_cast-0.1.35-py3-none-any.whl
- Upload date:
- Size: 39.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
396ee7df3ebe64e0d5cffe617264ee96c25d126864c19d7a11d8d435a0a19432
|
|
| MD5 |
275cab8e906b8e192b0521a32913531a
|
|
| BLAKE2b-256 |
9ae5fe8b7671c1eb95bfdf73cba32b9efa74d71324e73cadb2f99f9dfe260280
|