Skip to content

spabolu/xai-hack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

16 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ€ GrokCast NBA

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.

Python xAI Streamlit


โœจ Features

  • ๐ŸŽ™๏ธ 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

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  NBA Play Data  โ”‚ โ”€โ”€โ–ถ โ”‚   Grok 4.1 LLM  โ”‚ โ”€โ”€โ–ถ โ”‚  Grok Voice TTS โ”‚ โ”€โ”€โ–ถ โ”‚   Speaker   โ”‚
โ”‚     (JSON)      โ”‚     โ”‚    (tokens)     โ”‚     โ”‚   (WebSocket)   โ”‚     โ”‚   (audio)   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
                               โ–ผ
                        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                        โ”‚    X Search     โ”‚
                        โ”‚  (filler stats) โ”‚
                        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

How It Works

  1. Event Arrives โ†’ NBA play-by-play data triggers at the correct timestamp
  2. Grok Generates โ†’ Grok 4.1 creates excited, biased commentary (token by token)
  3. Voice Speaks โ†’ Grok Voice converts to natural speech via WebSocket streaming
  4. Interrupt Ready โ†’ New events can override current speech instantly
  5. Filler Mode โ†’ During quiet moments, X Search finds player stats to share

๐Ÿ› ๏ธ Tech Stack

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

๐Ÿ“ Project Structure

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

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.9+
  • xAI API Key (Get one here)
  • PortAudio (for PyAudio)

Installation

# 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 portaudio

Configuration

Create a .env file in the tts/python directory:

XAI_API_KEY=your_xai_api_key_here
GROK_MODEL=grok-4-1-fast-non-reasoning

Run the App

cd tts/python
streamlit run streamlit.py

Open http://localhost:8501 in your browser.


๐ŸŽฎ Usage

  1. Upload Game Data โ€” Select a JSON file with NBA play-by-play events
  2. Pick Your Team โ€” Choose which team to root for (or stay neutral)
  3. Select Language โ€” English, Spanish, or French
  4. Start Broadcast โ€” Click play and enjoy personalized commentary!

Sample Output

๐Ÿš€ 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

๐Ÿ”ง Key Components

NBACommentaryAgent

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="")

Token-by-Token Streaming

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
)

X Search Filler

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!"

๐ŸŽฏ API Reference

Voices Available

Voice Style
leo Energetic male
eve Enthusiastic female
ara Professional
rex Deep, dramatic
sal Casual
una Warm

Languages Supported

  • en โ€” English
  • sp โ€” Spanish (Espaรฑol)
  • fr โ€” French (Franรงais)

๐Ÿ† What Makes This Special

  1. True Real-Time โ€” Not batch processing; tokens stream directly to voice
  2. Smart Interrupts โ€” Breaking plays override current speech seamlessly
  3. Homer Bias โ€” AI genuinely roots for your team with emotional reactions
  4. X Search Integration โ€” Real statistics during downtime, not made-up filler
  5. 100% xAI Powered โ€” Grok LLM + Grok Voice + X Search end-to-end

๐Ÿ“œ License

MIT License โ€” feel free to use, modify, and distribute.


๐Ÿ™ Acknowledgments

  • 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. ๐Ÿ€๐ŸŽ™๏ธ

About

increasing grok user usage

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages