how long are the audio frames that can be accessed...
# ask-ai
i
how long are the audio frames that can be accessed in the agents stt_node
t
Thanks for reaching out, Ed. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi there! I wanted to share a little tip about the audio frames you’re working with in the
stt_node
of LiveKit Agents. These frames don’t come with a predefined length property, but no worries—you can easily figure out the duration yourself using the
samples_per_channel
and
sample_rate
properties of the
AudioFrame
objects. Here’s the simple formula:
Copy code
frame_duration = frame.samples_per_channel / frame.sample_rate
For instance, a 10ms frame at 48kHz would have 480 samples per channel. If you’d like, I’m here to help you with implementing this or tailoring your
stt_node
to fit your needs. Just let me know! Sources: Receiving and publishing tracks | LiveKit Docs | Capturing metrics | LiveKit Docs | livekit-agents/livekit/agents/voice/transcription/_speaking_rate.py | agents/src/voice/io.ts | Camera & microphone | LiveKit Docs
i
if were setting our silero VAD and STT to use 8 kHz sample rate, is it recommended to also set the audio sample rate of RoomInputOptions to 8 kHz from the default 24 kHz?
t
Thanks for reaching out! You don’t need to worry about setting the
RoomInputOptions
audio sample rate to match the 8 kHz sample rate of your Silero VAD and STT. The system is designed to automatically handle resampling for you, ensuring everything works smoothly. By default, the sample rate is set to 24 kHz, which actually helps provide better audio quality for your initial input, and then it internally resamples to the 8 kHz rate that Silero uses. That said, if you’re looking to optimize performance and reduce the resampling work, you can definitely set the sample rate to 8 kHz. Just let me know if you’d like a hand with setting this up—I’m here to help! Sources: Silero VAD plugin | LiveKit Docs | agents/src/voice/audio_recognition.ts | pipeline-tts/rime_tts.py | tests/test_stt.py | Silero VAD plugin | LiveKit Docs
i
yea but is 24 kHz even useful for telephony calls?
t
When it comes to telephony calls, whether a 24 kHz sample rate is the right choice really depends on what your system can handle and what you're aiming for. Using a 24 kHz sample rate allows for HD Voice, which means clearer and more natural audio by capturing a wider range of frequencies. That said, this benefit shines only if your SIP provider and endpoints support wideband codecs like G.722. On the other hand, if your telephony system mostly connects with traditional PSTN networks or needs to work smoothly with older systems, sticking with an 8 kHz sample rate might be the better option. It helps maintain compatibility with narrowband audio standards and keeps bandwidth use lower. I'd be happy to assist you with setting up your system for HD Voice or optimizing it for 8 kHz compatibility—just let me know how I can help! Sources: livekit-plugins/livekit-plugins-silero/livekit/plugins/silero/vad.py | tools/tts/tts.cpp | Runtime/Scripts/RtcAudioSource.cs | res/README.md | res/README.md
i
i thought that PSTN had no energy past 4 kHz? meaning that oversampling to 24 kHz would be useless?
t
You're absolutely right that the PSTN is limited to an audio bandwidth of about 4 kHz because of its 8 kHz sample rate and narrowband codecs like G.711. This means frequencies above 4 kHz get attenuated, so oversampling to 24 kHz doesn't actually add new information for PSTN calls. That said, oversampling to 24 kHz can still be really valuable in modern systems like LiveKit. It helps ensure high-fidelity audio processing, supports better noise cancellation, and improves features like VAD, STT, and TTS. Plus, if your telephony system supports HD Voice (for example, with G.722 codecs), the higher sample rate can capture and transmit a wider frequency range, which means better audio quality for compatible devices. If your focus is solely on PSTN calls, lowering the sample rate to 8 kHz might be more efficient. Please feel free to reach out if you'd like any help optimizing your setup—I’m here to assist! Sources: HD voice for SIP | LiveKit Docs | Speech & Audio Processing | livekit/livekit_composite | DeepWiki | soxr-sys/src/lib.rs
i
gotcha, since we use twilio, the audio is coming from twilio into the livekit room and then being passed to the agent right? so theres no benefit of using a sample rate of 24 kHz?
t
I understand that Twilio doesn’t support HD Voice, so the audio coming from Twilio into the LiveKit room will be limited to narrowband quality (usually around 8 kHz). Because of this, using a 24 kHz sample rate in LiveKit won’t really improve the incoming audio since the source itself is limited by Twilio’s capabilities. If you’d like, we can adjust the sample rate to 8 kHz to better match what Twilio supports and avoid any unnecessary resampling. Please feel free to reach out if you’d like some help setting this up—I’m here to assist you! Sources: HD voice for SIP | LiveKit Docs | livekit-plugins/livekit-plugins-speechmatics/livekit/plugins/speechmatics/t...