Build a Python voice agent that makes scripted videos with OpenRouter

Tim builds a Python AI agent from scratch: you speak what you want, and a 6-step pipeline combining text, voice, image and video generation via OpenRouter produces a fully scripted video.

Tech With Tim · YouTube · published Oct 18, 2026 · Content & Creative

Build a Python voice agent that makes scripted videos with OpenRouter — video by Tech With Tim▶ Watch on YouTube
Prompt
Build a Python agent that takes my spoken request, then in 6 steps writes a script, generates voiceover, images and video clips through OpenRouter, and assembles them into a finished video.

Visual breakdown

Tim builds a Python pipeline you talk to: it records your voice, transcribes it, writes a script, generates a cover image, a voiceover and an 8-second video from that image, and prints what each step cost. Every model call goes through OpenRouter with a single API key.

The problem: Generating text, images, speech and video usually means juggling different SDKs, modules and something like seven API keys.

The voice-to-video pipeline

  1. Record voicePress enter, speak your idea into the mic, press enter again; saved as a WAV file
  2. TranscribeOpenAI Whisper large v3 turbo turns speech into text for a fraction of a cent
  3. Write scriptStructured JSON: 40–60 word voiceover, 16:9 image prompt, 8-second video prompt, with fallback models
  4. Cover imageA Gemini image model makes the 16:9 cover from the image prompt
  5. VoiceoverGemini text-to-speech reads the script (a bonus step)
  6. VideoVeo 3.1 animates from the cover as the first frame, 720p; polled every 15 seconds
    Dropped: Prompts with copyrighted characters were refused
  7. Clip and cost receiptclip.mp4, cover, voiceover and script in an output folder, plus a cost per step
InputsPlain PythonModel via OpenRouterResult

Why OpenRouter fits this project

  1. One API key and one endpoint for text, image, speech and video models
  2. List several models in one request to get automatic fallbacks
  3. Every response reports its cost, so you can track spend per step
  4. Per-key credit limits and a dashboard of all spend

By the numbers

$3.28one full pipeline run
$3.20of that for the video
8 svideo length at 720p
~$15his total spend making the video

Build it step by step

Start a blank Python project with uv; the code is free from the link in his description.

  1. uv init, then uv add numpy python-dotenv requests sounddevice soundfile
  2. Create an OpenRouter API key (optionally with a credit limit) and put it in .env as OPENROUTER_API_KEY
  3. Write helper.py: one post function, a cost tracker, and a cost lookup for calls that don't report cost
  4. Step 1 records and transcribes; step 2 writes the script with a strict JSON schema
  5. Step 3 makes the image; step 4 the voiceover; step 5 the video, polling until it's ready
  6. Import all steps into main.py, chain them, and print the cost receipt

Each model's API tab on OpenRouter shows the exact path and parameters to call it.

Gotchas from the build

  • Video is the expensive and slow part; swap in cheaper models to cut costs.
  • Starting the video from a generated image gives better, more consistent results.
  • Set the provider to require parameters so only providers that support your JSON schema are used.
  • A Recraft image broke the video step, which expected JPEG or PNG; regenerating with Gemini fixed it.
  • Prompts that produced a copyrighted character were rejected; adding 'don't use any copyright content' worked.

Distilled from the video’s captions

How to try it

  1. Open OpenRouter.
  2. Copy the prompt and fill in the [placeholders].
  3. Watch Tech With Tim's video for the full walkthrough and setup.

Related use cases

Share