Building a Voice-Driven AI Multimodal Generation Pipeline with Python

Build a five-step AI pipeline from voice to video with Python and the OpenRouter unified gateway, at a total cost of about $3.28.
The article introduces a multimodal AI pipeline built in Python by a YouTube creator: after the user records audio, the system sequentially performs speech transcription, structured script generation, cover image generation, voiceover generation, and video synthesis, ultimately outputting an MP4 file. The project's biggest engineering highlight is using OpenRouter as a unified model gateway, calling text, image, speech, and video models with a single API key and supporting automatic switching between primary and fallback models. The script generation stage uses JSON Schema to force the model to output fixed fields, while video generation uses a polling mechanism to handle asynchronous tasks and uses the cover image as the first frame to improve consistency. A complete run costs about $3.28, of which video generation accounts for $3.20. The article also points out practical implementation issues such as image format compatibility and content moderation blocks.
In AI application development, turning voice input into a complete video output sounds like a complex engineering effort requiring multiple teams. But a YouTube creator demonstrated how to build a complete pipeline from recording to video generation using Python and a unified API endpoint. This project not only demonstrates how to chain together multimodal AI but also provides clear cost accounting, offering a reusable template for developers who want to try similar projects.

Project Architecture: A Five-Step Pipeline Design
The core idea of the entire system is to break a complex task into independent steps that execute in sequence. The user presses Enter to start speaking, and after the system records the audio, it automatically completes all subsequent operations: speech-to-text, script generation, cover image generation, voiceover generation, and video synthesis. The final output is an MP4 file containing both visuals and an audio track, along with a complete cost breakdown.
The advantage of this design is that each step can be independently debugged and replaced. In the video, the creator demonstrates running each step's file separately, making it easy for developers to understand the input and output of each stage.
Managing Multiple Models with a Single API Key
The most practical design decision in the project is using OpenRouter as a unified model gateway. In the traditional approach, generating text requires the OpenAI SDK, generating images requires Stability AI or Google's interfaces, and video generation involves yet another authentication system. Managing seven or eight API keys is both cumbersome and error-prone.
With OpenRouter, all requests go through the same endpoint, and you only need to specify the model name in the request body. The video demonstrates configuring a primary model and a fallback model in the text generation step, automatically switching when the primary model is rate-limited or unavailable—a mechanism that is especially important in production environments. The creator also shows how to query the list of parameters supported by a specific image model through the /images/models endpoint, avoiding blind trial and error.

OpenRouter is an API gateway that aggregates multiple model providers. It exposes an interface format compatible with OpenAI, so developers only need to maintain a single API key and can call text, image, and even multimodal models from different vendors via model identifiers in the request body. The core value of such a gateway lies in its abstraction layer: it unifies authentication, request structure, and billing entry points, and performs routing and failover among multiple upstream providers. The fallback mechanism mentioned in the article is a typical capability of the gateway layer—when the primary model returns a rate-limit or service-unavailable error, the gateway automatically forwards the request to a preconfigured fallback model, and the caller does not need to modify any code. It is worth noting that while gateways bring convenience, they also introduce an extra layer of latency and a single point of dependency, and different upstream models do not fully support the same parameters. Therefore, querying model capability endpoints (such as /images/models) is a necessary adaptation step.
Breaking Down the Key Technical Stages
Voice Recording and Transcription
The recording part uses the sounddevice library to capture microphone input, writes the audio stream into a numpy array through a callback function, and then saves it as a WAV file. The transcription stage calls the Whisper Large V3 Turbo model, sending Base64-encoded audio data to the /audio/transcriptions endpoint. The creator specifically notes that this model "costs a fraction of a few cents," transcribes quickly, and is suitable as the first stage of the pipeline.
Structured Script Generation
The script generation step uses JSON Schema to force the model to output a fixed structure. The request defines three required fields: a 40-to-60-word voiceover script with emotion tags, a detailed 16:9 cover image prompt, and a motion description for an 8-second video clip. This structured output ensures that subsequent steps can reliably parse the required content instead of guessing and extracting it from free-form text.
JSON Schema is a specification for describing and validating the structure of JSON data. It defines constraints such as which fields an object should contain, the types of those fields, their value ranges, and whether they are required. When calling a large language model, passing JSON Schema as part of the request parameters can force the model to output content according to a predefined structure rather than returning free-form text. This technique is commonly called "structured output" or "constrained decoding," and its underlying implementation varies by model provider: some restrict token generation through grammar-guided decoding strategies, while others implement it indirectly through function calling. Compared with asking in the prompt to "please output in JSON format," JSON Schema imposes stronger constraints and can significantly reduce the probability of parsing failures. It is a key means of ensuring a stable data contract when building multi-step AI pipelines.
Image and Video Generation
The image generation stage demonstrates the flexibility of switching models. The creator first tried the Gemini model, then tested the Recraft model and found that the latter was "noticeably faster and much cheaper." However, after switching to Recraft, an unexpected problem appeared: the generated image format was not standard JPEG or PNG, causing the subsequent video generation API to return an error. The problem was resolved after regenerating the cover image with Gemini. This detail shows that when multiple models collaborate, output format compatibility requires additional validation.

Video generation is the most expensive stage. The project uses the Google Veo 3.1 model, with the cover image as the first frame, to generate an 8-second, 720p clip. Because video generation takes a long time, the API uses a polling mechanism: it first returns a polling URL, and the client checks the status every 15 seconds. Once the status becomes complete, the video content is downloaded from a signed URL. The creator specifically mentions that using an image as the first frame makes the result "more consistent," which is a practical technique for improving generation quality.

Polling is a common pattern for handling asynchronous API tasks. When a requested task takes a long time, the server does not keep the HTTP connection hanging while waiting for the result. Instead, it immediately returns a task identifier or status query URL, and the client then repeatedly requests that URL at fixed intervals to obtain task progress. In video generation scenarios, rendering a clip of a few seconds often takes tens of seconds to several minutes, so polling is almost the most mainstream way to obtain status, in contrast to Webhook callbacks or streaming push. The choice of polling interval requires a trade-off between response timeliness and request overhead: too short an interval increases无效 requests and rate-limit risk, while too long an interval prolongs the overall waiting time. In engineering implementations, a maximum number of polling attempts and a backoff strategy are usually also set to avoid falling into an infinite loop when a task fails.
Cost Structure and Actual Performance
The video shows the full bill for one run: the total cost was $3.28, of which video generation accounted for $3.20, image generation about $0.67 cents, and text and transcription costs were negligible. The creator admits that video generation is "quite expensive" but also points out that costs can be reduced by choosing cheaper models.
In terms of actual generation results, the test cases included "a programmer struggling to drink coffee in front of a computer" and "a cowboy riding a unicorn on Mars." The visual quality was "not the best in the world," but it basically matched the text descriptions. Interestingly, when generating an image containing what appeared to be a well-known IP character, the video generation API returned a third-party content copyright blocking error. The creator said they had "never seen this error," which indirectly reflects the review mechanisms of video models regarding copyright compliance.
Takeaways for Developers
The value of this project is not in the generation quality itself, but in demonstrating a reusable architectural pattern: using a unified gateway to shield differences among multiple models, using structured output to ensure pipeline stability, using polling to handle asynchronous tasks, and using cost tracking to control budgets. For developers who want to build AI agents, these engineering practices are more instructive than the specific model choices. The code is available for free through joining the creator's community, lowering the barrier to trying it out.
One detail: the handoffs between stages in the pipeline are not entirely seamless. Unexpected situations such as image format compatibility issues and content moderation blocks show that multimodal systems need more format validation and error-handling logic before they are production-ready. This is also a step that must be crossed when moving from a demo project to a real application.
One-line Summary
Built a five-step AI pipeline from voice to video using Python and the OpenRouter unified gateway, with a total cost of about $3.28.
Paragraph Summary
The article introduces a multimodal AI pipeline built in Python by a YouTube creator: after the user records audio, the system sequentially performs speech transcription, structured script generation, cover image generation, voiceover generation, and video synthesis, ultimately outputting an MP4 file. The project's biggest engineering highlight is using OpenRouter as a unified model gateway, calling text, image, speech, and video models with a single API key and supporting automatic switching between primary and fallback models. The script generation stage uses JSON Schema to force the model to output fixed fields, while video generation uses a polling mechanism to handle asynchronous tasks and uses the cover image as the first frame to improve consistency. A complete run costs about $3.28, of which video generation accounts for $3.20. The article also points out practical implementation issues such as image format compatibility and content moderation blocks.
Related articles

Free Unlimited Claude Code Solution: Agnes AI + CC Switch Setup Guide
No paid subscription needed — pair the free AI platform Agnes AI with the open-source tool CC Switch to provide a backend for Claude Code, enabling unlimited free calls to text, image, and video models. This guide covers the full setup, test results, and usage boundaries.

A Complete Zero-Cost Guide to Getting Started with Claude Code for Beginners in China
A beginner's guide to Claude Code for users in China: two installation methods (command line and IDE plugin), full configuration steps for replacing the official API with the free domestic LongCat model, and a hands-on demo of building a small tool with natural language, plus tips.

When the NSA Gets Involved: The AI Supply Chain Crisis Behind Open-Source CVEs and API Key Hijacking
Multiple open-source projects disclosed severe CVEs in one day, PHP flaws alarmed the FBI, and Railway and OpenCode were breached with API keys stolen. This article breaks down the vulnerability window, AI-accelerated exploitation, and the AI supply chain crisis behind the API key black market, with a developer defense checklist.