FastRTC-Compact
A lean, Gradio-free fork of FastRTC.
Turn any Python function into a real-time audio and video stream over WebRTC or WebSockets — without the Gradio, librosa and their dependencies baggage of upstream.
This is a fork. It tracks FastRTC
v0.0.34and strips everything not needed for a production, bring-your-own-frontend deployment. The publicStreamAPI and thefastrtcimport path are unchanged, so code that mounts a stream on FastAPI works as-is.
What's different from upstream
Removed / out of scope
- Gradio — the entire auto-UI (
.ui.launch()), the GradioWebRTCcomponent, and the bundled Svelte / compiled frontend assets. - librosa + numba + llvmlite — replaced by
soxrfor audio resampling. Same resampler quality (soxr_hq), roughly 400 MB lighter, and no one-time JIT compilation stall on the first call. fastphone()— the free temporary phone number (HF token + Gradio tunneling) has been removed.- HuggingFace Spaces tooling —
upload_space.pyand related helpers.
Kept
- WebRTC and WebSocket endpoints via
.mount(app). - Voice Activity Detection and turn-taking (
ReplyOnPause, optionalvadextra). - Optional TTS / STT / stop-word extras.
The result is a much smaller dependency tree and image footprint, suitable for packaging as a plain FastAPI / WebRTC library.
Installation
This fork is distributed from git (it is not published to PyPI under this name):
pip install "git+https://github.com/abdurrafay0610/FastRTC-Compact.git"
To use built-in pause detection (see ReplyOnPause) and text to speech (see Text To Speech), add the vad and tts extras:
pip install "fastrtc-compact[vad,tts] @ git+https://github.com/abdurrafay0610/FastRTC-Compact.git"
Other optional extras: stt, stopword.
Naming: the distribution is
fastrtc-compact, but the import path is unchanged —from fastrtc import Stream, ReplyOnPause. It is a drop-in replacement for code already written against FastRTC.
Key Features
- 🗣️ Automatic voice detection & turn-taking — only worry about the logic for responding to the user;
ReplyOnPausehandles detecting when they've finished speaking. - 🔌 WebRTC support —
.mount(app)adds a/webrtc/offerendpoint to a FastAPI app for your own frontend. - ⚡️ WebSocket support — the same
.mount(app)adds a/websocket/offerendpoint. - 🤖 Fully customizable backend — a
Streammounts onto any FastAPI app, so you can extend it to fit your production system.
Quickstart
Echo Audio
from fastrtc import Stream, ReplyOnPause
import numpy as np
def echo(audio: tuple[int, np.ndarray]):
# The function is passed the audio until the user pauses.
# Implement any iterator that yields audio.
yield audio
stream = Stream(
handler=ReplyOnPause(echo),
modality="audio",
mode="send-receive",
)
LLM Voice Chat
from fastrtc import (
ReplyOnPause, Stream,
audio_to_bytes, aggregate_bytes_to_16bit,
)
import numpy as np
from groq import Groq
import anthropic
from elevenlabs import ElevenLabs
groq_client = Groq()
claude_client = anthropic.Anthropic()
tts_client = ElevenLabs()
def response(audio: tuple[int, np.ndarray]):
prompt = groq_client.audio.transcriptions.create(
file=("audio-file.mp3", audio_to_bytes(audio)),
model="whisper-large-v3-turbo",
response_format="verbose_json",
).text
reply = claude_client.messages.create(
model="claude-3-5-haiku-20241022",
max_tokens=512,
messages=[{"role": "user", "content": prompt}],
)
response_text = " ".join(
block.text
for block in reply.content
if getattr(block, "type", None) == "text"
)
iterator = tts_client.text_to_speech.convert_as_stream(
text=response_text,
voice_id="JBFqnCBsd6RMkjVDRZzb",
model_id="eleven_multilingual_v2",
output_format="pcm_24000",
)
for chunk in aggregate_bytes_to_16bit(iterator):
audio_array = np.frombuffer(chunk, dtype=np.int16).reshape(1, -1)
yield (24000, audio_array)
stream = Stream(
modality="audio",
mode="send-receive",
handler=ReplyOnPause(response),
)
Webcam Stream
from fastrtc import Stream
import numpy as np
def flip_vertically(image):
return np.flip(image, axis=0)
stream = Stream(
handler=flip_vertically,
modality="video",
mode="send-receive",
)
Running the Stream
Mount the stream on a FastAPI app and serve your own frontend:
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from fastrtc import Stream, ReplyOnPause
app = FastAPI()
stream = Stream(handler=ReplyOnPause(...), modality="audio", mode="send-receive")
stream.mount(app)
# Optional: serve your frontend
@app.get("/")
async def index():
return HTMLResponse(content=open("index.html").read())
# uvicorn app:app --host 0.0.0.0 --port 8000
mount() registers the following routes (prefixed with the optional path argument):
| Endpoint | Protocol | Purpose |
|---|---|---|
/webrtc/offer |
HTTP POST | WebRTC SDP / ICE exchange |
/websocket/offer |
WebSocket | WebSocket streaming |
/telephone/incoming |
HTTP POST | Twilio inbound call webhook * |
/telephone/handler |
WebSocket | Twilio media-stream handler * |
* Telephone (Twilio): dial-in routes are still mounted, so you can point your own Twilio number at
/telephone/incoming. The zero-configfastphone()temporary number is gone. (Pending decision: keep these routes for phone dial-in, or strip them for a browser-only deployment.)
Examples
For end-to-end demos (Gemini / OpenAI / Claude voice chat, Whisper transcription, object
detection, and more), see the upstream FastRTC cookbook.
Those demos are built against the original library and its Gradio UI; adapt the handler
logic to a .mount(app) deployment when porting them to this fork.
Credits
Forked from FastRTC by the Gradio team. MIT licensed.
Metadata
Release files for fastrtc-compact 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastrtc_compact-0.0.1.tar.gz | 808.2 kB | Without provenance | Details for fastrtc_compact-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastrtc_compact-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for fastrtc_compact-0.0.1-py3-none-any.whl |
Total release size: 1.6 MB
Release files / fastrtc_compact-0.0.1.tar.gz
| Download URL | fastrtc_compact-0.0.1.tar.gz |
|---|---|
| Size | 808.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f885e961bde72645e7061ba735c5076937237da8ab48166c1d621fac6c65bf3
|
|
BLAKE2b-256 checksum How to use checksums |
f19c6ea088c4f2e1c3fd7b893601e6d1fa398191828dcb752c8a02b4e4c4b958
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Release files / fastrtc_compact-0.0.1-py3-none-any.whl
| Download URL | fastrtc_compact-0.0.1-py3-none-any.whl |
|---|---|
| Size | 815.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6d8544cec2e6163e401b3b330043e77c5eadedfe61f18a363c4a9ddc709b6241
|
|
BLAKE2b-256 checksum How to use checksums |
edbdf6cdbe239a7bb416bf5d00d9a54ca4a2595f683f007bc58634dee03b82f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Security for fastrtc-compact 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.