MCPcopy Index your code
hub / github.com/NickTikhonov/shuo

github.com/NickTikhonov/shuo @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
186 symbols 764 edges 21 files 135 documented · 73% updated 4mo ago★ 664
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

shuo 说

A voice agent framework in ~600 lines of Python.

python main.py +1234567890
🚀 Server starting on port 3040
✓  Ready https://mature-spaniel-physically.ngrok-free.app
📞 Calling +1234567890...
✓  Call initiated SID: CA094f2e...
🔌 WebSocket connected
▶  Stream started SID: MZ8a3b1f...
← Flux EndOfTurn "Hey, how's it going?"
◆ LISTENING → RESPONDING
→ Start Agent "Hey, how's it going?"
← Agent turn done
◆ RESPONDING → LISTENING

How it works

Two abstractions, one pure function:

  • Deepgram Flux — always-on STT + turn detection over a single WebSocket
  • Agent — self-contained LLM → TTS → Player pipeline, owns conversation history
  • process_event(state, event) → (state, actions) — the entire state machine in ~30 lines

Everything streams. LLM tokens feed TTS immediately, TTS audio feeds Twilio immediately. If you interrupt (barge-in), the agent cancels everything and clears the audio buffer instantly.

LISTENING ──EndOfTurn──→ RESPONDING ──Done──→ LISTENING
    ↑                        │
    └────StartOfTurn─────────┘  (barge-in)

Project structure

shuo/
  types.py              # Immutable state, events, actions
  state.py              # Pure state machine (~30 lines)
  conversation.py       # Main event loop
  agent.py              # LLM → TTS → Player pipeline
  log.py                # Colored logging
  server.py             # FastAPI endpoints
  services/
    flux.py             # Deepgram Flux (STT + turns)
    llm.py              # OpenAI GPT-4o-mini streaming
    tts.py              # ElevenLabs WebSocket streaming
    tts_pool.py         # TTS connection pool (warm spares)
    player.py           # Audio playback to Twilio
    twilio_client.py    # Outbound calls + message parsing

Setup

Requires Python 3.9+, ngrok, and API keys for Twilio, Deepgram, OpenAI, and ElevenLabs.

Configure your ngrok authentication token:

ngrok config add-authtoken <YOUR_NGROK_AUTH_TOKEN>
pip install -r requirements.txt
cp .env.example .env   # fill in your keys
ngrok http 3040        # in another terminal
python main.py +1234567890  # Replace with the phone number the code will call

Tests

Running these tests is not required for executing the application. It is recommended to run tests after making changes to the codebase.

python -m pytest tests/ -v   # runs in ~0.03s

License

MIT

Core symbols most depended-on inside this repo

_c
called by 50
shuo/log.py
info
called by 42
shuo/log.py
get
called by 35
shuo/services/tts_pool.py
process_event
called by 33
shuo/state.py
error
called by 20
shuo/log.py
cancel
called by 10
shuo/services/llm.py
_text_outline
called by 5
scripts/service_map.py
get_logger
called by 4
shuo/log.py

Shape

Method 107
Function 41
Class 33
Route 5

Languages

Python100%

Modules by API surface

tests/test_update.py34 symbols
shuo/log.py28 symbols
shuo/server.py13 symbols
shuo/agent.py13 symbols
shuo/services/tts_pool.py12 symbols
shuo/services/tts.py12 symbols
shuo/services/player.py12 symbols
shuo/types.py11 symbols
shuo/tracer.py11 symbols
shuo/services/flux.py9 symbols
shuo/services/llm.py8 symbols
scripts/visualize.py8 symbols

For agents

$ claude mcp add shuo \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page