I am facing an agent voice stuttering issue, what ...
# ask-ai
h
I am facing an agent voice stuttering issue, what could be the reason for this ?
t
Thanks for reaching out, Issam. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks so much for reaching out! To help us get to the bottom of the voice stuttering issue, could you share a bit more about what you’re experiencing? For example: • Is the stuttering happening for everyone in the call or just certain participants? • Does it happen all the time or just now and then? • Are there any particular network setups or devices involved that you’ve noticed? • Is this issue happening in one specific room or across different rooms? Your answers will really help us understand what’s going on and find the best solution for you.
h
• The setup is a 2-participants in a room. • Stuttering seems to be random and intermittent from the agent speaking side. • It's happening with diff STT's and TTS's plugins we're using. noticeably AWS STT. • it's happening across different rooms
t
I'm here to help you with the intermittent voice stuttering issue you're experiencing with the AWS STT and TTS plugins. Let's walk through some steps together that might improve your experience: • Network Latency: It’s a good idea to make sure your agent deployment is close to the AWS regions hosting Amazon Transcribe and Polly services. You can do this by setting the
speech_region
parameter in the STT plugin to the right AWS region (for example,
us-east-1
). • Latency Monitoring: To get a clearer picture of any delays, try using the
livekit.agents.metrics
API. It helps monitor important latency metrics like Time To First Token (TTFT) and Time To First Byte (TTFB), which can point out where things might be slowing down. • STT Plugin Behavior: Just a heads up, Amazon Transcribe may restart sessions after 15 seconds of inactivity, which can sometimes cause interruptions. Keeping a steady audio input can help prevent these restarts. • TTS Plugin Configuration: Since Amazon Polly works in non-streaming mode, there might be some delays. You can optimize performance by matching the
sample_rate
to your output and choosing the right
speech_engine
(like
neural
for better quality). • Agent Deployment: For smoother operation, deploying agents on dedicated servers can help avoid CPU contention. Also, using load balancing with multiple agent instances can boost reliability. • Error Handling: It’s helpful to use error events to spot and recover from any service interruptions. You might also want to consider fallback options to keep things running smoothly. If you’d like, I’m here to assist with any specific configurations or troubleshooting steps. Just let me know how I can support you! Sources: Community & Support | livekit/livekit_composite | DeepWiki | Getting Help & Troubleshooting | livekit/livekit_composite | DeepWiki | Amazon Transcribe plugin guide | LiveKit Docs | examples/voice_agents/error_callback.py | Amazon Polly TTS plugin guide | LiveKit Docs
h
Elaborate more on TTS Plugin Configuration
t
I'm happy to share the detailed configuration options for the Amazon Polly TTS plugin in LiveKit with you: • Voice: You can specify the voice ID for speech synthesis (for example,
Joanna
). If you'd like to explore all available voices, you can find the full list in the Amazon Polly documentation. • Language: This lets you set the language code for synthesis, which is especially helpful if you're working with bilingual voices (like
en-IN
or
hi-IN
). • Speech Engine: You have options like
standard
,
neural
,
long-form
, or
generative
. The default is
generative
. Neural engines usually offer higher quality, though they might have a bit more latency. • Text Type: Choose
text
for plain text or
ssml
if you want to use Speech Synthesis Markup Language (SSML) — this gives you more control over pronunciation and intonation. • Sample Rate: You can set the audio frequency in Hz (the default is
16000
). Just make sure it fits your output needs. • Region: Specify the AWS region (like
us-west-2
) to help minimize latency. • Authentication: You'll need to provide AWS credentials either directly as arguments (
api_key
and
api_secret
) or through environment variables (
AWS_ACCESS_KEY_ID
and
AWS_SECRET_ACCESS_KEY
). If you'd like to customize speech even more, setting
text_type="ssml"
and using SSML-formatted text can give you fine-grained control over pitch, rate, and pronunciation. Here's a quick example configuration to get you started:
Copy code
from livekit.plugins.aws import TTS

tts = TTS(
    voice="Joanna",
    language="en-US",
    speech_engine="neural",
    text_type="ssml",
    sample_rate=24000,
    region="us-west-2"
)
Please feel free to reach out if you'd like help with any specific configurations or if you have any questions — I'm here to help! Sources: Amazon Polly TTS plugin guide | LiveKit Docs | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/__init__.py
h
More on : Since Amazon Polly works in non-streaming mode, there might be some delays. You can optimize performance by matching the
sample_rate
to your output
t
I’m glad you asked about this! Amazon Polly works in a non-streaming mode, which means it generates the entire audio before playing it back. Because of this, you might notice some delays, especially with longer responses. To help things run more smoothly, optimizing the
sample_rate
is a great step—it makes sure the audio output is processed efficiently and fits well with your playback setup, reducing any extra processing or mismatches. Here’s a little example to illustrate: • If your playback system expects audio at 16 kHz, setting
sample_rate=16000
means the audio won’t need resampling, saving you some processing time. • Choosing higher sample rates like 24 kHz can give you better audio quality, but it might add a bit more processing time. So, it’s all about finding the right balance between quality and performance for what you need. If you’d like, I’m here to help you with any other questions or to walk you through setting this up—just let me know!
h
So for AWS STT:
sample_rate=8_000 if is_telephony else 24_000
For ElevenLabs TTS, on default
t
Here are some friendly recommendations for the
sample_rate
settings when working with AWS STT and ElevenLabs TTS: • AWS STT: It’s best to use
sample_rate=24000
. This is the default and necessary setting for Amazon Transcribe integration within LiveKit. • ElevenLabs TTS: The default is
sample_rate=22050
, which is great for keeping latency low (about 110ms faster time-to-first-byte). If you’re aiming for higher audio quality, you can set it to
sample_rate=44100
, though this might add a little latency. To help you get the best results, try to match the TTS output sample rate with the rest of your audio pipeline to avoid any resampling issues. If you’d like, I’m here to help you with any specific configurations or questions you have! Sources: livekit-plugins/livekit-plugins-clova/livekit/plugins/clova/constants.py | translators/tts_translator.py | Smallest AI TTS plugin guide | LiveKit Docs
h
| try to match the TTS output sample rate with the rest of your audio pipeline Like what configuration should be here when having aws sampling 24000
t
I understand you're looking to match the TTS output sample rate with AWS STT's 24,000 Hz. To do this, you'll want to configure the ElevenLabs TTS plugin to output audio at the same rate. However, ElevenLabs TTS typically defaults to 22,050 Hz and doesn’t natively support 24,000 Hz, though it does offer higher rates like 44,100 Hz as options. Here are a couple of friendly suggestions you might find helpful: • You can use the default ElevenLabs sample rate (22,050 Hz) and then resample the audio to 24,000 Hz within your audio pipeline. • Alternatively, you could set ElevenLabs to a higher sample rate, such as 44,100 Hz, and then resample it down to 24,000 Hz to align with AWS STT. If you'd like, I’m here to guide you through the resampling process or assist further with your setup. Just let me know how I can help!
h
for context, i am also getting this error msg:
inference is slower than realtime
, for record i m using silero VAD with prewarm approach
t
It looks like you're encountering the "inference is slower than realtime" error, which happens when processing audio frames for voice activity detection (VAD) takes longer than the actual audio duration, causing some delays. Let’s walk through some common causes and easy fixes together: • Hardware Limitations: It’s a good idea to use compute-optimized hardware. Burstable instances like AWS t3 might run out of CPU credits if they’re under constant load, which can slow things down. • Model Loading Delays: To speed things up, try prewarming the Silero VAD model when your agent starts. This way, it’s fully loaded and ready to go when you need it. • Sample Rate Mismatches: Make sure your input audio sample rate matches what the model expects (either 8kHz or 16kHz). This helps avoid extra resampling time. If you’d like, I’m here to help you set these up or answer any other questions you have! Sources: livekit-plugins/livekit-plugins-silero/livekit/plugins/silero/onnx_model.py | examples/src/restaurant_agent.ts | LiveKit turn detector plugin | LiveKit Docs
h
my resources are under utilised, so it can't be a resource issue. prewarm is there. can this be related to stuttering issue ? how can i check sample rate for vad ?
t
Let's walk through how to check and set the sample rate for Silero VAD in LiveKit together: • Supported Sample Rates: Silero VAD works best with 8,000 Hz and 16,000 Hz, and it defaults to 16,000 Hz. • Configuration: You can easily specify the sample rate when loading the VAD model. For example, in Python:
Copy code
from livekit.plugins import silero

# Load VAD with a specific sample rate (e.g., 8000 Hz)
vad = silero.VAD.load(sample_rate=8000)
• Verification: To double-check the sample rate you've set, take a look at the
_opts.sample_rate
attribute in Python or
#opts.sampleRate
in Node.js while debugging. • Resampling: If your input audio’s sample rate is different, don’t worry—the VAD plugin will automatically resample it to the configured rate for you. Since you mentioned your resources are underutilized and prewarming is enabled, mismatched sample rates could be causing the stuttering and the "inference is slower than realtime" error. To help smooth things out, try to ensure your input audio is either 8 kHz or 16 kHz to minimize extra resampling work. Please feel free to reach out if you’d like me to help with anything else or clarify any steps! Sources: Silero VAD plugin | LiveKit Docs | livekit-plugins/livekit-plugins-silero/livekit/plugins/silero/vad.py | plugins/silero/src/vad.ts
h
how do i verify this : try to ensure your input audio is either 8 kHz or 16 kHz to minimize extra resampling work.
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
h
i think this is happening only when using AWS STT, any idea about this?
what;'s livekit audio default webrtc sample rate ?