Recent findings suggest that in the last few months, many new real-time speech models have been released and entire companies have been founded around both open and closed source models. To name a few milestones:.
Despite the explosion on the model and funding side, it's still difficult to build real-time AI applications that stream audio and video, especially in Python. (Related: Tech Report: Easily Build and Share ROCm Kernels with H...)
It has been revealed that that's why we're excited to announce FastRTC, the real-time communication library for Python. The library is designed to make it super easy to build real-time audio and video AI applications entirely in Python!
It has been revealed that in this blog post, we'll walk through the basics of FastRTC by building real-time audio applications. At the end, you'll understand the core features of FastRTC:. (Related: Building the Open Agent Ecosystem Together: Introducing...)
We'll start by building the "hello world" of real-time audio: echoing back what the user indicates. In FastRTC, this is as simple as:.
In a recent development, the next level is to use an LLM to respond to the user. FastRTC comes with built-in speech-to-text and text-to-speech capabilities, so working with LLMs is really easy. Let's change our echo function accordingly:.
We're using the SambaNova API since it's fast. The get_stt_model() will fetch Moonshine Base and get_tts_model() will fetch Kokoro from the Hub, both of which have been further optimized for on-device CPU inference. But you can use any LLM/text-to-speech/speech-to-text API or even a speech-to-speech model. Bring the tools you love - FastRTC just handles the real-time communication layer.
It has been revealed that if instead of stream.ui.launch(), you call stream.fastphone(), you'll get a free phone number to call into your stream. Note, a Hugging Face token is required. Increased limits for PRO accounts.
You'll see something like this in your terminal:.
You can then call the number and it will connect you to your stream!
Thank you for checking out FastRTC!
Can fastphone() accept an Indian phone number?
We're working on getting a whatsapp number.
📻 🎙️ Hey, I generated an AI podcast about this blog post, check it out!
This podcast is generated via ngxson/kokoro-podcast-generator, using DeepSeek-R1 and Kokoro-TTS.
I have a question for concurrency when use tts_model and stt_model. How does each type of model handle multiple requests at the same time. (e.g. batching technique ? cpu-only threading ....) @freddyaboulton.
According to recent reports, hi @MRU4913 ! Each stream is an independent event in the event loop. But you can limit how many streams run concurrently very easily. There is a parameter in the Stream class.
Industry observers note that taking a while to connect. Are you on a VPN? Anyone else stuck with this error (I am not using VPN)? This only happens on Gemini examples.
Sources indicate that hi @Nirav-Madhani - I am not sure. Let me see. Feel free to clone and run locally in the meantime.
Would be very cool if you can also add a example with Azure OpenAI-API.
Hi @MechanicCoder - please feel free to add an example here if you’d like. It should be straightforward- take the example in this blog post and replace the LLM with the api call for the LLM on Azure you like.
Hey, have a working example...should I send you a repo link?
Can I connect something like FreeSWITCH and have its RTC directly parsed by fastRTC?
I have not tried this myself but I think so. The FastRTC server is completely open so you can integrate with any telephony/webrtc client.
Please open a PR to add a guide on how to do this: https://github.com/freddyaboulton/fastrtc/blob/main/docs/userguide/audio.md.
Also feel free to join the HF discord and ask questions in the fastrtc-channels: https://discord.gg/TSWU7HyaYu.
In a recent development, hi, I'm new to WebRTC applications, and one of my main questions is: how does the process of capturing audio work? I mean, in demos, you always take the audio directly from the microphone, but I'd like to know if it's possible to get the input audio from a specific port (for example, a listening port where RTP packets are arriving). I guess I need to better understand how WebRTC communications work...Thank you!
It has been revealed that can you tell me a bit more about the use case @JuanRoyo ? WebRTC requires a "handshake" to happen between the two clients. This handshake is taken care of by the webrtc/offer route of the FastRTC server. So you can just send a post request there. See this js code snippet:.
https://fastrtc.org/userguide/api/.
