Building Real-Time Voice Applications: Integrating a Low-Latency Text-to-Speech API
The latency of a conversational voice application often depends on the performance of various architectural components.
After a user asks a question, there’s a wait until the answer is ready. Once it’s generated, you face another delay: the latency between when speech synthesis starts and when the text-to-speech model transforms it into speech.
Using ElevenLabs’ text to speech API, you can dramatically shorten wait times and build highly interactive voice agents for conversational use cases like voice assistants, educational applications, customer support applications, and more.
Measure Time to First Audio
A lot happens between when a user speaks and when they receive a response. For a conversational application, there’s likely a step to recognize speech, then pass it to a language model to process, formulate a response, synthesize audio, and speak it to the user through the device’s speakers. All of these steps take a non-trivial amount of time.
The most important metric is “time to first audio,” or the time from when the user speaks to when the first audio is received. Server-side latency is certainly one component, but other factors like network distance and audio player buffering can affect the time to first audio the user perceives.
By focusing on this metric, you and your team will have a better chance of correctly diagnosing the bottleneck in your application. It may seem like you’re synthesizing speech fast enough, but the audio isn’t playing quickly. You may want to reduce how long the application buffers audio, or see if you can decrease the hops between your services.
Choose the Right Streaming Method
If your response is ready and does not need to be generated in real-time (such as an assistant providing you with instructions on how to do something inside the app), a good place to start is using HTTP streaming. In this case, you submit the text you wish to generate audio for, and the model streams back audio chunks as they become available. This means you can start playing the response without waiting for the full response to be generated.
But say you’re building a real-time conversational agent and want to stream text input into an audio generation model as a language model generates it. In this case, you may not want to wait for an entire sentence to come through. In this scenario, the ideal choice is to open a WebSocket connection to stream text and receive audio chunks over the same connection as they’re generated.
However, this approach comes with a couple of things to keep in mind. First, you have to properly manage WebSocket connection states and handle incoming audio data. Also, account for potential interruptions (i.e., the user could interrupt what the assistant is saying by starting to speak).
Adjust Buffering for Natural Speech
When using streaming, you must accept a compromise. The shorter the text chunks you send, the less time your end-user has to wait for the first words. The larger the text chunks you send, the more the model can contextualize what is being said and find natural places to pause, and the less likely the response is to be interrupted or cut off mid-sentence.
Where the balance lies depends on your application’s use case. For example, if you’re building a voice assistant for short questions and answers, it will require different chunk sizes than an audiobook player. Experiment with different chunk sizes based on real conversations and play them back. See if you have any unnatural breaks or cut-offs. The WebSocket documentation for the ElevenLabs API includes an option to set chunk scheduling, which you can use to configure the behavior.
Test the Experience, Not Just the API
Test for actual, practical use cases. Record the time between the user’s request and the first sample of sound the user hears. Check for playback interruptions during longer playback. Run the same test for different network conditions as well. A stable connection might mask issues that could surface once on mobile data.
Note that different voice selection also makes a big difference. While a low-latency model can be a convenient choice for quick interactions, developers should evaluate pronunciation and expressiveness to find the best fit for the application. For a more thorough test of text-to-speech quality, test pronunciation of names, numbers, and subject-specific terminology using content directly from the application.
Prepare for Real Conversations
Speech is just half of it. If you’re building an interactive voice interface, make sure you play back speech properly and have fallback options if the connection isn’t reliable.
Try a single tightly defined interaction first. Then measure the latency the user experiences before tweaking and iterating on the parts where you see the most friction. A well-implemented voice integration can go a long way toward making your voice interaction feel not only faster, but much more natural.

