Inspiration

We love NBA basketball, but not every game has energetic commentary—especially for international fans. Most broadcasts are in English only and stay neutral, without the “homer” bias that makes watching your favorite team so much fun. We wanted an AI announcer that feels like your local radio broadcaster: hyping your team, shading the opponent, and speaking your native language fluently.

What it does

  • GrokCast NBA turns any NBA game into a personalized broadcast. Select a game (past or live) and your favorite team, and our AI commentator delivers real-time play-by-play synced to the video. It gets extra excited when your team scores, adds light shade for the opponent, and instantly switches languages—fully demonstrated in English, Spanish, and French.
  • During quiet moments between plays, GrokCast uses X Search to look up real player statistics and delivers live trivia about players on the court—keeping the broadcast engaging even when nothing’s happening. ## How we built it ### Core Files
  • grok_script.py - The engine powering all AI commentary:
    • NBACommentaryAgent class generates context-aware, biased commentary via LangChain
    • stream_tokens_to_speaker() enables true token-by-token streaming—audio starts playing while the LLM is still generating
    • search_player_stats() uses Grok’s X Search to fetch real-time player statistics for filler commentary
    • WebSocket-based TTS streams audio chunks directly to speakers with zero file storage
  • streamlit.py - Clean web interface for game selection:
    • run_streaming_commentary() implements real-time event simulation with a continuous clock
    • Interrupt support: new events immediately override current speech
    • Filler commentary: during gaps between plays, randomly selects players and speaks their stats
    • Dual voice rotation (Leo and Eve) for natural broadcast feel ### Tech Stack
  • Grok 4.1 (fast non-reasoning mode) generates exciting, context-aware commentary
  • Grok X API/Search fetches live player statistics during commentary downtime
  • Grok Voice (xAI WebSocket TTS) handles ultra-natural text-to-speech with automatic multilingual support
  • nba_api provides official real-time play-by-play events
  • Python + Streamlit creates a clean web interface
  • Custom timing logic syncs commentary precisely with video events using asyncio The system is built end-to-end for real-time live games (demo uses past games for copyright safety). ## Challenges we ran into
  • Achieving sub-second latency with token-by-token LLM→TTS streaming
  • Building an interrupt system so breaking plays override current commentary
  • Precisely syncing spoken lines with on-screen action using async event scheduling
  • Fine-tuning prompts to sound naturally hyped rather than robotic ## Accomplishments that we’re proud of
  • True real-time streaming: Audio plays while the LLM is still generating tokens
  • Smart interrupts: Higher-priority plays immediately override current speech
  • X Search filler: During quiet moments, the AI researches and shares live player stats
  • Truly personalized “homer” commentary that dynamically changes tone based on the user’s favorite team
  • Seamless multilingual support with accurate basketball terminology in English, Spanish, and French ## What we learned Sports commentary prompt engineering is an art—small phrasing tweaks create massive differences in excitement and personality. Building a real-time interrupt system with WebSockets taught us a lot about async Python. Grok 4.1's speed and Grok Voice’s quality far exceeded our expectations and made a hackathon timeline possible. ## What’s next for GrokCast NBA
  • Detect game excitement levels for even more dynamic emotion (louder for clutch moments)
  • Add player-specific catchphrases and voice styles
  • Priority-based interrupts (dunks override rebounds, etc.)
  • Build a mobile app and live overlay mode for watching games with friends GrokCast NBA is powered start-to-finish by xAI—bringing the future of personalized sports broadcasting to every fan around the world. :basketball::studio_microphone:

Built With

Share this project:

Updates