$ show cbh123/narrator
This repository is a small Python demo application that turns a webcam feed into a real-time David Attenborough-style nature documentary narration. It consists of two independent processes: capture.py grabs frames from the webcam every 2 seconds, resizes them to a maximum dimension of 250 pixels, and writes them to frames/frame.jpg; narrator.py polls that file, base64-encodes it, sends it to OpenAI's GPT-4 Vision API with a snarky Attenborough system prompt, appends the response to a running conversation script, synthesizes speech via ElevenLabs, and plays the audio aloud. The two processes communicate through the filesystem, which is a simple but effective decoupling pattern for a demo. The code is functional and readable, with a few thoughtful touches: the image is downscaled before upload to reduce API cost and latency, and the narrator retries reading the frame file when it catches a transient EACCES error caused by the capture process writing concurrently. However, it is a proof-of-concept rather than a production application: there are no tests, no error handling for API failures, hardcoded paths, and the pinned dependencies are from late 2023. The OpenAI model 'gpt-4-vision-preview' and the ElevenLabs 'generate/play' API are both deprecated, so the code would need updates to run against current APIs. Despite a recent commit timestamp in the metadata, the codebase is effectively a frozen 2023 demo. The maintainer has not updated dependencies or addressed the deprecated APIs, and 41 open issues remain. It is best treated as a reference implementation or a starting point for a webcam-to-AI-narration pipeline, not as a maintained library.
The LLM identified 2 files worth highlighting for reuse:
The encode_image function reads a base64 image from disk with a retry loop that specifically handles EACCES errors, which occur when the capture process is mid-write. This is a clean, self-contained solution to a common cross-process file-sharing race condition and can be extracted into any project that reads files being written by another process.
The frame capture loop grabs webcam frames, downscales them to a maximum 250px dimension using LANCZOS resampling, and writes them to a shared file. The downscaling is a practical optimization for vision API cost and latency, and the loop is a simple template for a frame producer in a real-time AI pipeline.