๐๏ธ 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
๐ 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!