AI/TLDR

FastRTC

Turns any Python function into a real-time audio and video stream over WebRTC or WebSockets

Audio, Music & VoiceOpen source
Language
Python
License
MIT
$pip install fastrtc

Overview

FastRTC is the real-time communication library for Python, from the team behind Gradio. It solves the plumbing problem that sits under every voice AI demo: getting microphone audio (or webcam video) from a browser to your model and the response back again, with low latency. You write an ordinary Python function; FastRTC wraps it in a `Stream` and handles WebRTC or WebSocket transport.

The parts that are tedious to build yourself come included. Automatic voice activity detection and turn taking mean you only write the logic for responding to the user, rather than deciding when they stopped talking. `.ui.launch()` gives you a WebRTC-enabled Gradio interface for testing, `.mount(app)` attaches the stream to a FastAPI app so your own front end can use the WebRTC or WebSocket endpoint, and `fastphone()` launches the app behind a free temporary phone number.

Because the backend is just a function mounted on FastAPI, it extends to production rather than stopping at the demo — the project's own cookbook covers wiring it to the Gemini and OpenAI real-time voice APIs, streaming webcam video and audio together to a model, and serving a custom JavaScript front end.

What it does

  • Wraps any Python function as a real-time audio/video stream over WebRTC or WebSockets
  • Built-in voice activity detection and turn taking via `ReplyOnPause`, so you only write the response logic
  • `.ui.launch()` for an instant WebRTC-enabled Gradio UI to test against
  • `.mount(app)` to attach the stream to a FastAPI app and expose WebRTC or WebSocket endpoints to your own front end
  • `fastphone()` launches the app and issues a free temporary phone number to call it on
  • Optional `vad` and `tts` extras for pause detection and text to speech
  • Fully customizable backend — a `Stream` is ordinary FastAPI, so it extends to production deployments

Getting started

FastRTC installs from PyPI. Pause detection and text to speech live behind optional extras, so install those if you want the batteries-included voice loop.

Install the library

The base install covers streaming. Add the extras to get built-in pause detection (`ReplyOnPause`) and text to speech.

bashbash
pip install fastrtc

# with built-in pause detection and text to speech
pip install "fastrtc[vad, tts]"

Launch the built-in UI to test

Calling `.ui.launch()` on a Stream starts the WebRTC-enabled Gradio interface, which is the fastest way to talk to your handler and confirm the audio loop works before you build a front end.

pythonpython
stream.ui.launch()

Mount it on your own FastAPI app

`.mount(app)` attaches the stream to a FastAPI application and exposes a WebRTC endpoint (and a WebSocket endpoint) for a custom front end, which is the path to production.

pythonpython
stream.mount(app)

Call it on a real phone number

`fastphone()` launches the application and returns a free temporary phone number, which is useful for testing a voice agent over real telephony without setting up a provider.

pythonpython
stream.fastphone()

Work from the cookbook

The documentation at fastrtc.org includes a cookbook of runnable examples — the Gemini and OpenAI real-time voice APIs, a webcam plus audio chat that streams both feeds to Gemini, and a 'Talk To Claude' demo that shows how to serve a custom JS front end.

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Building a voice agent where the model should reply when the user stops speaking, without hand-rolling turn detection
  • Streaming webcam video and microphone audio together to a multimodal model
  • Putting a WebRTC front end on an existing Python speech-to-text or text-to-speech pipeline
  • Testing a voice application over real telephony using a temporary phone number before committing to a provider

How FastRTC compares

FastRTC alongside other open-source audio, music & voice tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
Whisper★ 109kOpenAI's speech recognition model that transcribes and translates audio across many languages.
GPT-SoVITS★ 61.9kAn open-source WebUI that clones a voice from a short audio sample and turns text into speech, with zero-shot and few-shot fine-tuning.
Voicebox★ 54.9kLocal-first voice studio that clones a voice from a short sample, generates speech across seven TTS engines and 23 languages, handles system-wide dictation, and speaks for agents over MCP.
VibeVoice★ 54.4kMicrosoft's text-to-speech model for generating long, expressive multi-speaker audio like podcasts.
whisper.cpp★ 53.7kA dependency-free C/C++ port of Whisper built on ggml, running speech recognition on CPU, Metal, CUDA, Vulkan and NPUs from phones to servers.
Coqui TTS★ 46kA library of text-to-speech models including the multilingual XTTS voice-cloning model.
ChatTTS★ 39.9kChatTTS is an open-source text-to-speech model tuned for dialogue, with multi-speaker support and fine-grained control over laughter, pauses, and prosody.
FastRTC★ 4.6kTurns any Python function into a real-time audio and video stream over WebRTC or WebSockets