FastRTC-Compact
The lightweight real-time communication library for Python.
Turn any Python function into a real-time audio or video stream over WebRTC or WebSockets — without the heavyweight dependencies.
FastRTC-Compact is a fork of FastRTC (v0.0.34) built for production deployments that serve their own frontend. It removes Gradio (~312 MB) and the librosa/numba resampling stack (~400 MB, replaced with soxr), cutting the installed footprint from roughly 1.05 GB to ~345 MB while keeping the full WebRTC/WebSocket core, voice activity detection, turn-taking logic, and Twilio dial-in support.
It is a drop-in replacement: the import name is still fastrtc, so existing code works unchanged.
Installation
FastRTC-Compact is now available on PyPI:
To use built-in pause detection (see ReplyOnPause), speech-to-text (see Speech To Text), and text-to-speech (see Text To Speech), install the vad, stt, and tts extras:
One fastrtc per environment
Do not install fastrtc-compact and the upstream fastrtc package in the same
environment — both provide the fastrtc import and will clash.
Quickstart
Import the Stream class, pass in a handler, and mount it on a FastAPI app with .mount(app) — perfect for integrating with your existing production system and serving your own frontend.
from fastrtc import Stream, ReplyOnPause
import numpy as np
def echo(audio: tuple[int, np.ndarray]):
# The function will be passed the audio until the user pauses
# Implement any iterator that yields audio
# See "LLM Voice Chat" for a more complete example
yield audio
stream = Stream(
handler=ReplyOnPause(echo),
modality="audio",
mode="send-receive",
)
import os
from fastrtc import (ReplyOnPause, Stream, get_stt_model, get_tts_model)
from openai import OpenAI
sambanova_client = OpenAI(
api_key=os.getenv("SAMBANOVA_API_KEY"), base_url="https://api.sambanova.ai/v1"
)
stt_model = get_stt_model()
tts_model = get_tts_model()
def echo(audio):
prompt = stt_model.stt(audio)
response = sambanova_client.chat.completions.create(
model="Meta-Llama-3.2-3B-Instruct",
messages=[{"role": "user", "content": prompt}],
max_tokens=200,
)
prompt = response.choices[0].message.content
for audio_chunk in tts_model.stream_tts_sync(prompt):
yield audio_chunk
stream = Stream(ReplyOnPause(echo), modality="audio", mode="send-receive")
Run it by mounting the stream on a FastAPI app:
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
app = FastAPI()
stream.mount(app)
# Optional: serve your own frontend
@app.get("/")
async def _():
return HTMLResponse(content=open("index.html").read())
# uvicorn app:app --host 0.0.0.0 --port 8000
mount() registers /webrtc/offer (WebRTC signaling), /websocket/offer (WebSocket streaming), and the Twilio dial-in routes /telephone/incoming and /telephone/handler — point your own Twilio number at the stream for phone support.
Learn more about the Stream in the user guide.
Key Features
Lightweight — ~345 MB installed vs ~1.05 GB for upstream FastRTC. No Gradio, no librosa/numba; audio resampling handled by soxr.
Drop-in replacement — imports as fastrtc, so switching requires no code changes.
Automatic Voice Detection and Turn Taking built-in — only worry about the logic for responding to the user.
WebRTC Support — .mount(app) adds a WebRTC endpoint to a FastAPI app for your own frontend.
WebSocket Support — the same .mount(app) adds a WebSocket endpoint.
Telephone Support — Twilio dial-in routes are mounted automatically; connect your own Twilio number.
Completely customizable backend — a
Stream mounts on any FastAPI app, so you can extend it to fit your production application.
Roadmap
- Optional
huggingface_hubdependency with the Silero VAD model vendored as package data - Streaming STT, TTS, and LLM support
- Pipecat smart_turn integration for smarter pause detection
Examples
See the cookbook.
Credits
FastRTC-Compact is based on FastRTC by Freddy Boulton. MIT licensed; original copyright preserved.