Back to .md Directory

Pitch Narration Generator

Parses a structured video script, extracts narrator blocks, and synthesises them into a single MP3 using Azure OpenAI TTS.

May 2, 2026
0 downloads
0 views
ai openai
View source

What this file does

Parses a structured video script, extracts narrator blocks, and synthesises them into a single MP3 using Azure OpenAI TTS.

When to use it

  • You have a timed video script with narrator sections
  • You want to generate a voiceover from a text script automatically
  • You need per-section audio clips plus a final stitched narration
  • You use Azure OpenAI TTS and want a repeatable pipeline

Assumes this stack

PythonAzure OpenAI TTSffmpegpydubpython-dotenv

Pitch Narration Generator

Parses a structured video script, extracts all Narrator: blocks, and synthesises them into a single MP3 using Azure OpenAI TTS.

How it works

  1. Split the script on Time: ... section headings
  2. Extract each Narrator: block
  3. Synthesise each block via Azure OpenAI TTS → output/section_NN.mp3
  4. Concatenate with a short pause between sections → output/narration.mp3

Setup

1. Install dependencies

pip install openai python-dotenv pydub

pydub requires ffmpeg for MP3 export:

brew install ffmpeg   # macOS

2. Configure credentials

cp .env.example .env

Fill in your Azure OpenAI TTS resource key and endpoint.

Usage

python video_gen.py script.txt

Your script file should use this format:

Time: 0:00-0:30 | Section Title
(Visual: optional stage direction — ignored)
Narrator: The text that will be spoken aloud.

Time: 0:30-1:00 | Next Section
Narrator: More narration here.

Output

output/
├── section_00.mp3   ← per-section audio clips
├── section_01.mp3
│   …
└── narration.mp3    ← final stitched narration

Configuration

SettingWhere
TTS voicevoice= in synthesise() — options: alloy, echo, fable, nova, onyx, shimmer
TTS speedspeed= in synthesise()
Pause between sectionsPAUSE_MS constant

What's inside

1 setup section, 1 usage example, 1 output structure, 1 configuration table, 3 code blocks

Change this for your project

  • Replace voice= in synthesise() with your preferred TTS voice
  • Replace speed= in synthesise() with your desired speech rate
  • Replace PAUSE_MS constant with your preferred pause duration

Where it goes

Keep it in your repository where the agent or team that needs it will read it.

Related Documents