AI-Powered Real-Time NBA Commentary โ Personalized, Multilingual, and Passionate
Turn any NBA game into your personal broadcast with an AI commentator that roots for YOUR team, speaks YOUR language, and never misses a beat.
- ๐๏ธ Real-Time Commentary โ Play-by-play audio synced precisely with game events
- โค๏ธ Homer Mode โ Pick your team and get biased, passionate commentary
- ๐ Multilingual โ English, Spanish, and French with native fluency
- โก True Streaming โ Audio starts playing while AI is still thinking
- ๐ Live Player Stats โ X Search fills quiet moments with real statistics
- ๐ Smart Interrupts โ Breaking plays override current commentary instantly
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ NBA Play Data โ โโโถ โ Grok 4.1 LLM โ โโโถ โ Grok Voice TTS โ โโโถ โ Speaker โ
โ (JSON) โ โ (tokens) โ โ (WebSocket) โ โ (audio) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโ
โ X Search โ
โ (filler stats) โ
โโโโโโโโโโโโโโโโโโโ
- Event Arrives โ NBA play-by-play data triggers at the correct timestamp
- Grok Generates โ Grok 4.1 creates excited, biased commentary (token by token)
- Voice Speaks โ Grok Voice converts to natural speech via WebSocket streaming
- Interrupt Ready โ New events can override current speech instantly
- Filler Mode โ During quiet moments, X Search finds player stats to share
| Component | Technology | Purpose |
|---|---|---|
| LLM | Grok 4.1 (fast non-reasoning) | Generate context-aware commentary |
| Search | Grok X Search | Fetch real-time player statistics |
| Voice | Grok Voice (WebSocket TTS) | Natural multilingual speech |
| Framework | LangChain + OpenAI SDK | LLM orchestration |
| UI | Streamlit | Web interface |
| Audio | PyAudio | Real-time audio playback |
| Data | nba_api | Official NBA play-by-play |
tts/python/
โโโ streamlit.py # ๐ฎ Main web interface
โโโ grok_script.py # ๐ง Core AI engine
โ โโโ NBACommentaryAgent # Commentary generation
โ โโโ search_player_stats() # X Search integration
โ โโโ stream_tokens_to_speaker() # Real-time TTS
โโโ requirements.txt # ๐ฆ Dependencies
โโโ magicvgrizzlies.json # ๐ Sample game data
โโโ ARCHITECTURE.md # ๐ System diagrams
- Python 3.9+
- xAI API Key (Get one here)
- PortAudio (for PyAudio)
# Clone the repository
git clone https://github.com/yourusername/grokcast-nba.git
cd grokcast-nba/tts/python
# Install dependencies
pip install -r requirements.txt
# Install additional packages
pip install streamlit langchain-xai openai pydantic
# macOS: Install PortAudio for audio playback
brew install portaudioCreate a .env file in the tts/python directory:
XAI_API_KEY=your_xai_api_key_here
GROK_MODEL=grok-4-1-fast-non-reasoningcd tts/python
streamlit run streamlit.pyOpen http://localhost:8501 in your browser.
- Upload Game Data โ Select a JSON file with NBA play-by-play events
- Pick Your Team โ Choose which team to root for (or stay neutral)
- Select Language โ English, Spanish, or French
- Start Broadcast โ Click play and enjoy personalized commentary!
๐ Real-time simulation started (608 events)
Teams: MEM, ORL | Players: 24
[13.8s] ๐ค [leo] D. Bane driving floating Jump Shot
๐ฌ Bane floats it in! Beautiful!
โ Done
๐ [Filler] [eve] Looking up J. Jackson Jr....
๐ฌ Jackson averaging 22 points this month!
๐ Filler interrupted by event
[37.3s] ๐ค [leo] MISS K. Caldwell-Pope 3PT
๐ฌ Caldwell-Pope... no good!
โ Done
Generates biased, exciting commentary based on team preference:
agent = NBACommentaryAgent(
language="en", # en, sp, fr
team_support="Grizzlies" # Your team (or "Neither")
)
# Stream tokens for real-time TTS
async for token in agent.process_event_streaming(event):
print(token, end="")Audio starts playing while the LLM is still generating:
await stream_tokens_to_speaker(
agent.process_event_streaming(event),
voice="leo" # leo, eve, ara, rex, sal, una
)During quiet moments, searches for real player stats:
async for token in search_player_stats("LeBron James", ["LAL", "BOS"]):
print(token, end="")
# Output: "LeBron averaging 25 points in his last 5 games!"| Voice | Style |
|---|---|
leo |
Energetic male |
eve |
Enthusiastic female |
ara |
Professional |
rex |
Deep, dramatic |
sal |
Casual |
una |
Warm |
enโ Englishspโ Spanish (Espaรฑol)frโ French (Franรงais)
- True Real-Time โ Not batch processing; tokens stream directly to voice
- Smart Interrupts โ Breaking plays override current speech seamlessly
- Homer Bias โ AI genuinely roots for your team with emotional reactions
- X Search Integration โ Real statistics during downtime, not made-up filler
- 100% xAI Powered โ Grok LLM + Grok Voice + X Search end-to-end
MIT License โ feel free to use, modify, and distribute.
- xAI โ For Grok 4.1, Grok Voice, and X Search APIs
- NBA โ For the incredible game data
- Streamlit โ For the simple, powerful UI framework
Built with โค๏ธ for basketball fans everywhere
GrokCast NBA โ Your team. Your language. Your broadcast. ๐๐๏ธ