Skip to content

anonymousgirl123/ai_commentary_generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

23 Commits
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽ™๏ธ Sports Commentator from Video Capstone Project โ€“ CS[05]

Demo: https://www.youtube.com/watch?v=oCRp2JzdnuA

https://github.com/anonymousgirl123/ai_commentary_generator/wiki

An AI-powered system that generates timestamped, broadcast-style sports commentary from raw video using a two-stage Large Language Model (LLM) pipeline.

๐Ÿš€ Overview This project combines computer vision + AI language models to automatically generate engaging sports commentary.

๐Ÿ”น Pipeline Frame Extraction (OpenCV) Scene Understanding (Gemini 2.5 Flash โ€“ Vision LLM) Commentary Generation (Gemini 2.5 Pro โ€“ Language LLM) Optional Text-to-Speech (TTS) โœจ Features ๐ŸŽฅ Works with any sports video โฑ๏ธ Timestamped commentary [MM:SS] ๐Ÿง  Two-LLM architecture (Vision + Language) ๐ŸŽ™๏ธ Optional Text-to-Speech output ๐Ÿ–ฅ๏ธ Interactive terminal dashboard โšก Two modes: Live Mode (detailed, real-time style) Highlight Mode (fast summary) ๐Ÿ—๏ธ Architecture

Video Input
โ†“
Frame Extraction (OpenCV)
โ†“
LLM-1 (Gemini Flash) โ†’ Scene Descriptions
โ†“
LLM-2 (Gemini Pro) โ†’ Commentary Script
โ†“
TTS (Optional)
โ†“
Output (Text + Audio)

๐Ÿ“ฆ Project Structure . โ”œโ”€โ”€ video_processor.py # Frame extraction & encoding โ”œโ”€โ”€ commentary_generator.py # Two-LLM pipeline โ”œโ”€โ”€ tts_engine.py # Speech synthesis โ”œโ”€โ”€ dashboard.py # Interactive CLI dashboard โ”œโ”€โ”€ main.py # Entry point โ””โ”€โ”€ .env # API keys

โš™๏ธ Tech Stack Python 3.9+ OpenCV (cv2) Google Gemini API (google-genai) python-dotenv macOS say (TTS) ANSI Terminal UI ๐Ÿ”‘ API Key Setup Get a free API key: ๐Ÿ‘‰ https://aistudio.google.com/app/apikey

Option A โ€“ CLI Argument --api_key YOUR_KEY_HERE

Option B โ€“ Environment Variable (Recommended) Linux / macOS

export GOOGLE_API_KEY="YOUR_KEY_HERE" Windows (CMD) set GOOGLE_API_KEY=YOUR_KEY_HERE

๐Ÿ“ฆ Installation

cd sports-commentator

pip install opencv-python google-genai python-dotenv โ–ถ๏ธ Usage ๐Ÿ–ฅ๏ธ Option A โ€“ Interactive Dashboard (Recommended) python dashboard.py

๐Ÿ“Œ Dashboard Flow

Step 1 โ€“ Video & API Setup Enter full video path Enter API key (skip if env variable is set)

Step 2 โ€“ Commentary Mode

Highlight Mode (Default) โ†’ every 10s, faster Live Mode โ†’ every 3s, more detailed Step 3 โ€“ Match Details

Sport (default: football) Team A / Team B Context (optional) Enable TTS (y/n) Audio file (optional) Output file (default: commentary_output.txt) Confirmation y โ†’ Run n โ†’ Reconfigure Output Live progress in terminal Final commentary displayed + saved

Feedback Rate (1โ€“5 stars) Optional comment ๐Ÿ’ป Option B โ€“ Direct CLI (Advanced)

Basic: python main.py --video match.mp4 --api_key YOUR_KEY_HERE

Full Example:

--video match.mp4
--api_key YOUR_KEY_HERE
--mode highlight
--sport football
--team_a "Manchester City"
--team_b "Arsenal"
--context "Semi-final, 0-0 at kick-off"
--output commentary_output.txt
--tts ๐Ÿงพ Arguments Argument Description

--video	Input video path (required)
--api_key	Gemini API key
--mode	live / highlight
--sport	Sport type
--team_a	Home team
--team_b	Away team
--context	Match context
--interval	Frame interval
--max_frames	Max frames
--output	Output file
--save_scenes	Save scene JSON
--tts	Enable TTS
--audio_output	Save audio file

๐Ÿ“Š Performance Summary Metric Live Mode Highlight Mode Frame interval 3 seconds 10 seconds Max frames 60 20 Avg. processing time ~3โ€“5 min ~1โ€“2 min LLM-1 (per frame) ~2โ€“3 sec ~2โ€“3 sec LLM-2 (full script) ~5โ€“10 sec ~3โ€“5 sec Commentary accuracy High Moderateโ€“High ๐Ÿงช Sample Output [00:00] The match kicks off with high intensity.

[00:10] A brilliant through-ball breaks the defence โ€” the striker is through!

[00:20] GOAL! A stunning finish into the top corner!

SUMMARY: A clinical and well-deserved goal from Team A.

๐Ÿ“ค Output Terminal โ†’ Timestamped commentary commentary_output.txt โ†’ Full script scene_analysis.json โ†’ (optional) intermediate data Audio file โ†’ (if TTS enabled)

๐Ÿค– Models Used Gemini 2.5 Flash โ†’ Vision (frame analysis) Gemini 2.5 Pro โ†’ Language (commentary generation)

๐Ÿ”ฎ Future Improvements

Player & team detection Live score API integration Multi-language commentary Fine-tuned sports LLM Web-based dashboard ๐Ÿค Contributing

Pull requests are welcome. Feel free to fork and improve the project.

๐Ÿ“œ License

For academic and research purposes.

๐Ÿ‘ค Author

Kamini

โญ If you like this project, give it a star!

About

๐Ÿง  AI-driven text generation for dynamic commentary โšก Fast and automated output with minimal input ๐Ÿ“ Customizable templates and styles ๐Ÿ”„ Scalable for different use cases (e.g., sports, blogs, reports) ๐Ÿงฉ Modular design for easy integration and extension

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages