Skip to main content

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)

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snippet_cast-0.1.18.tar.gz (583.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snippet_cast-0.1.18-py3-none-any.whl (26.3 kB view details)

Uploaded Python 3

File details

Details for the file snippet_cast-0.1.18.tar.gz.

File metadata

  • Download URL: snippet_cast-0.1.18.tar.gz
  • Upload date:
  • Size: 583.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for snippet_cast-0.1.18.tar.gz
Algorithm Hash digest
SHA256 15a64e6ea96e772870707bde1b035e802f34fe64c34aabdece3558bc6ad081fe
MD5 9e4a5a5d0e34077cedfe83da9fbb9c95
BLAKE2b-256 1fa00fb3e8d84a26af94b5563e364ac449186d960a118ecf71baaa36c78f2c85

See more details on using hashes here.

File details

Details for the file snippet_cast-0.1.18-py3-none-any.whl.

File metadata

  • Download URL: snippet_cast-0.1.18-py3-none-any.whl
  • Upload date:
  • Size: 26.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for snippet_cast-0.1.18-py3-none-any.whl
Algorithm Hash digest
SHA256 2246e944c58b936888168fd4fc3c9721b78765eb9fda43f79db77d65f60bb35f
MD5 98ccc595f4f317caeb14f0da6a4a610f
BLAKE2b-256 d51e0c6f2f11d3ce2bcb5d12786bb54ea593b46909786da1006d7238464a8e31

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page