gradio-app/fastrtc
A Python framework for streaming audio and video over WebRTC and WebSocket
Automated SPDX check for reference only — not legal advice. Disclaimer
GitHub Star History
Full-history star trajectory from GitHub official history. Switch ranges or hover any point for exact counts.
Evidence-Backed Technical Brief
AI Deep ReviewArchitecture & Core Mechanics
FastRTC is a Python media framework, with the application boundary at Stream(handler=..., modality=..., mode=...). In the bidirectional examples, webcam frames go to a Python callback that returns processed frames, while an audio handler can yield chunks as (sample_rate, ndarray) tuples. ReplyOnPause wraps the audio reply handler to invoke it on a detected pause, separating turn detection from application logic.
The repository separates backend/ and frontend/, with demo/, docs/, and test/ alongside them. The Python manifest includes aiortc and aioice for WebRTC and ICE, Gradio for the built-in UI, and NumPy, librosa, and Numba in the runtime dependency set. The same Stream abstraction supports either a built-in UI via .ui.launch() or FastAPI-mounted WebRTC and WebSocket endpoints via .mount(app). Model calls and application-specific processing live in the handler rather than the transport configuration.
Key Capabilities & Differentiators
The practical range runs from echo audio and NumPy webcam transforms to real-time Whisper transcription and YOLOv10 detection on browser webcam frames. The webcam detection example passes a Gradio slider value into the frame handler as a confidence threshold, illustrating how UI parameters can affect processing without changing the media transport.
For voice, one example composes Groq-hosted Whisper transcription, Claude 3.5 Haiku, and ElevenLabs streaming TTS, turning pcm_24000 output into 24 kHz 16-bit NumPy chunks. That example streams synthesized audio back but waits for transcription and the text reply before synthesis. Other demos illustrate Gemini audio/video chat, Gemini and OpenAI real-time voice APIs, and Kyutai Moshi. These are integration examples, not evidence that their models or client SDKs ship with the base package. For audio-only testing by phone, .fastphone() can obtain a temporary number with a Hugging Face token.
Trade-offs & Limitations
Compared with integrating aiortc and FastAPI directly, FastRTC saves work where media callbacks, pause-triggered replies, and a test UI match the application. The abstraction is less compelling when a team already owns its media stack or needs tighter control of session behavior. Compared with a managed real-time communications platform, the self-hosted path gives the team control of the Python service but leaves it responsible for connectivity, authentication, and capacity planning. Test WebRTC across the actual client networks, including whether they need a relay.
Inference placement is a separate decision. Hosted APIs avoid running those models locally but introduce network dependencies, provider limits and costs, and external data handling. Local inference avoids that dependency only if the entire model path is local, and sizing then depends on model choice and concurrency. For a chained voice application, measure end-of-turn to first returned audio, not just transport latency: pause detection, transcription, text generation, and synthesis can each contribute.
Hardware & Deployment Guide
Install fastrtc on Python 3.10 or newer, or install fastrtc[vad, tts] for built-in pause detection and TTS. Gradio is constrained to >=4.0,<6.0. On Python 3.13 and later the manifest conditionally adds audioop-lts, standard-aifc, and standard-sunau. Use .ui.launch() for a quick functional check or mount the stream on a FastAPI app for a custom frontend; the serving example uses uvicorn app:app --host 0.0.0.0 --port 8000.
Self-hosting the Python service does not make cloud-backed examples offline. A restricted network deployment must separately provision local inference and model files, and validate client connectivity. Release 0.0.34 added configurable OpenAPI tags for mounted endpoints and moved some print output to logging; 0.0.33 addressed Gradio Lite compatibility for versions before 5.46.0, and 0.0.32 fixed an async client instance reuse bug.
Stream wraps a Python frame callback or an audio generator; the audio examples pass (sample_rate, ndarray) tuples.ReplyOnPause invokes reply logic on a detected pause; built-in pause detection and TTS use the vad and tts extras, respectively..ui.launch() or mount WebRTC and WebSocket endpoints on FastAPI with .mount(app)..fastphone() provides a free temporary number for audio-only streams and requires a Hugging Face token.Python teams that want to validate a voice agent, browser transcription, or live webcam inference in Gradio, then integrate the same media handler into a FastAPI service.
You need a managed communications service, production telephony rather than a temporary test number, or direct control over the lower-level media stack.
Quick Start & Installation
pip install fastrtcComparison vs. Top Voice, Vision & Video Alternatives
Full comparison →| Repository | Stars | 7d Trend | Stack | License | Core Positioning |
|---|---|---|---|---|---|
| fastrtc ★ | 4.6k | +1 | JavaScript | MIT | A Python framework for streaming audio and video over WebRTC and WebSocket |
| mlx-audio | 8.4k | +32 | Python | MIT | MLX inference SDK for local speech and audio pipelines on Apple Silicon |
| whisperX | 26.5k | +677 | Python | BSD-2-Clause | Batched Whisper with forced alignment for word timings and optional speaker labe |
| RealtimeSTT | 10.3k | +11 | Python | Apache-2.0 | Local streaming speech-to-text: a Python SDK and FastAPI service for low-latency |
AI Context Briefing (for Claude / Cursor / Windsurf)
Standardized architecture summary & quickstart commands ready to paste into coding agents.
curl -sL https://repoforai.com/repo/gradio-app/fastrtc.md
Active README embeds unlock Hot-Tier 6h Telemetry Refresh automatically (zero pay-to-rank).
Frequently Asked Questions about fastrtc
Can I reuse the same stream in a Gradio demo and an existing FastAPI service?
Stream handler and call stream.mount(app) on the FastAPI app. Mounting exposes WebRTC and WebSocket endpoints; your frontend still has to use the chosen transport and manage its connection. Use stream.ui.launch() to test the handler before integrating a custom client.Do I need a GPU, and what should I load-test?
Can I self-host FastRTC commercially and keep media in my environment?
When is FastRTC a better fit than building directly on aiortc?
Upstream README & Documentation
This profile focuses on independent engineering analysis and live telemetry. Read the full upstream README, changelog, and examples directly on GitHub.
Top 10 Breakout Open-Source AI Repos, Every Thursday
Signal-only digest of fast-growing AI repos, SPDX license alerts, and architecture picks. Zero spam.
Zero spam · 1-click unsubscribe · Privacy Policy