from the client to the STT output what are the ste...
# ask-ai
m
from the client to the STT output what are the steps the audio take and what the input format?
t
Thanks for reaching out, Khalid. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks for reaching out! Let me walk you through the audio processing pipeline from the client to the Speech-to-Text (STT) output in LiveKit. Here’s how it works step-by-step: 1. Input Audio Capture and Resampling: First, the audio is captured and resampled to 16kHz mono, which is what most STT services require. 2. Audio Chunking: Then, the resampled audio is split into 50ms frames (that’s 800 samples per channel at 16kHz). 3. Frame Processing: Each frame’s duration is tracked carefully, and the audio data is prepped for sending. 4. Encoding: The audio data is converted into bytes and base64-encoded so it can be sent over WebSocket smoothly. 5. Transmission: These encoded audio chunks are then sent as structured messages to the STT service. 6. Provider-Specific Processing: Finally, different STT providers process the incoming audio according to their own settings. Just so you have the full picture, the standard input audio format looks like this: • Encoding: 16-bit signed little-endian PCM (pcm_s16le) • Sample Rate: 16000 Hz (16kHz) • Channels: Mono • Bit Depth: 16 bits per sample If you’d like me to dive deeper into any particular step or if you have any other questions, please don’t hesitate to ask. I’m here to help! Sources: AI Agents Framework | livekit/livekit_composite | DeepWiki | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/stt.py | agents/src/inference/stt.ts
m
in wish step and what the format of the audio capture from the user ?
t
Thank you for your question! The audio is captured from the user using the LiveKit client SDK on their device. At first, the format might be a bit different depending on the device and platform, but don’t worry—it gets standardized pretty early on during the input resampling step. During this step, the audio is converted to the following format: • Encoding: 16-bit signed little-endian PCM (pcm_s16le) • Sample Rate: 16000 Hz (16kHz) • Channels: Mono This resampling happens right after the user's speech is captured and just before it’s divided into 50ms frames (800 samples per frame) for the next stages of processing and transmission. If you’d like me to walk you through more details about this step or how the initial capture works, please don’t hesitate to ask—I’m here to help! Sources: Pipeline nodes and hooks | LiveKit Docs | AI Agents Framework | livekit/livekit_composite | DeepWiki | OpenAI and LiveKit partner to turn Advanced Voice into an API | sample-app-record-local/src/main/java/io/livekit/android/sample/record/Vide...
m
is it possible to send an audio file instead of get it from the user device microphone ? like load the file from the a server ?
t
Absolutely, you can send an audio file to LiveKit instead of capturing audio directly from the user's microphone. You have the option to load the file from a server or local storage and then publish it to a LiveKit room as an audio track. Here’s how you can do this with different SDKs: • Node.js SDK: You can read a file (like a .wav), parse its metadata, and publish frames using
AudioSource.captureFrame()
. • Rust SDK: Using a
WavReader
, you can read and push audio frames into a
NativeAudioSource
. • Swift SDK: You can work with custom audio buffers (
AVAudioPCMBuffer
) to mix or replace the microphone input. Just a heads-up: make sure your audio file is properly chunked (for example, into 20ms frames) and matches the expected format (16kHz mono PCM) to ensure everything works smoothly. If the file’s format is different, you might need to resample it. If you’d like, I’m here to help with specific guidance tailored to your use case or SDK—just let me know! Sources: Camera & microphone | LiveKit Docs | examples/publish-wav/index.ts | examples/play_from_disk/change-sophie.wav | Docs/audio.md | Processing raw media tracks | LiveKit Docs
m
before the input resampling step is the input has any format ?
t
Just to give you a clearer picture, before the input resampling step, the audio input doesn’t have a fixed format but usually defaults to: • Sample Rate: 48kHz • Bit Depth: 16-bit • Channels: Configurable (commonly mono or stereo) LiveKit is quite flexible and supports various input formats, including sample rates ranging from 8kHz to 48kHz, and bit depths like 16-bit, 32-bit integer, or 32-bit float. After that, these inputs are resampled to 16kHz mono for the next steps in processing. If you’d like, I’m here to help with more details about specific configurations or supported formats—just let me know! Sources: livekit-compose-components/src/main/java/io/livekit/android/compose/ui/audi... | Tests/LiveKitCoreTests/AVFoundation/AVAudioPCMBufferTests.swift | livekit-rtc/livekit/rtc/audio_resampler.py | AI Agents Framework | livekit/livekit_composite | DeepWiki | livekit-plugins/livekit-plugins-clova/livekit/plugins/clova/constants.py
m
is the input resampling step happen in the backend (Agent) or in the Livekit OSS ?
t
I’d love to help you understand the input resampling step a bit better! This happens behind the scenes in the backend (Agent), where we use the
AudioResampler
component from LiveKit OSS to handle the actual resampling. Here’s a friendly breakdown of how it works: • The Agent backend takes care of managing the resampling process, making sure audio frames are converted to the right format (like 16kHz mono). • The
AudioResampler
from LiveKit OSS does the technical resampling, relying on the Sox resampling library to ensure the conversion is top quality. • Whenever the input sample rate doesn’t match the needed output rate, resampling kicks in and is smoothly managed during the audio processing pipeline. If you have any questions or want me to explain anything in more detail, please don’t hesitate to ask—I’m here to help! Sources: livekit-agents/livekit/agents/voice/room_io/_input.py | AI Agents Framework | livekit/livekit_composite | DeepWiki | livekit-rtc/livekit/rtc/audio_resampler.py | Agent Session & Activity Management | livekit/livekit_composite | DeepWiki | Processing raw media tracks | LiveKit Docs