able-jackal-84140
07/13/2025, 8:14 PMtall-airline-16756
07/13/2025, 8:15 PMtall-airline-16756
07/13/2025, 8:15 PMAudioSource
and LocalAudioTrack
objects to create real-time audio publishing pipelines that immediately transmit captured frames.
• DataStreamAudioOutput and buffer management: These approaches push buffered audio as soon as it’s available, using async iterables and real-time publishing logic to minimize delay.
• Web application streaming: In browser-based solutions, connect WebAudio nodes to MediaStreamAudioDestinationNode
and publish to LiveKit as audio is created.
The main principle is to process and publish audio in small chunks or frames as they are produced, allowing immediate playback and streaming even if the generation/upload is ongoing. Let me know if you need implementation details for a specific platform or integration method.
Sources: Agents Core Architecture | livekit/livekit_composite | DeepWiki | ChunkedStream | LiveKit Agents | Receiving and publishing tracks | LiveKit Docs | livekit-agents/livekit/agents/voice/room_io/_pre_connect_audio.py | Sources/LiveKit/Core/PreConnectAudioBuffer.swift | Stream music over WebRTC using React and WebAudioable-jackal-84140
07/13/2025, 8:23 PMtall-airline-16756
07/13/2025, 8:24 PMfrom livekit import rtc
# Define your audio parameters
SAMPLE_RATE = 48000
NUM_CHANNELS = 1 # mono
# Create an audio source and a local audio track
source = rtc.AudioSource(SAMPLE_RATE, NUM_CHANNELS)
track = rtc.LocalAudioTrack.create_audio_track("my-audio-track", source)
• JavaScript/TypeScript Web SDK:
import { createLocalAudioTrack } from 'livekit-client';
// Create a local microphone track
const audioTrack = await createLocalAudioTrack({
channelCount: 1, // Use 2 for stereo
echoCancellation: true,
});
Once you've created your local audio track, you can easily publish it to a LiveKit room using your participant instance. No sweat!
Want more specific guidance? Just let me know about your platform or use case, and I'll be happy to provide step-by-step instructions that are perfect for your setup. 😊
Sources: packages/livekit-rtc/src/proto/track_pb.ts | Hi-fi audio | LiveKit Docs | livekit-rtc/livekit/rtc/_proto/track_pb2.pyi | Publishing tracks | LiveKit Docsable-jackal-84140
07/13/2025, 8:27 PMtall-airline-16756
07/13/2025, 8:28 PMsession.say()
method is your new best friend! Just pass an audio
parameter with an AsyncIterator
of rtc.AudioFrame
objects. It's perfect for those moments when you want to stream a custom or pre-recorded audio clip during your session.
• Want some background tunes or ambient sounds? The BackgroundAudioPlayer
has got your back! Use play()
to keep those sounds rolling, even while your agent is doing its thing.
• Feeling a bit more technical? No worries! You can totally create an AudioSource
and LocalAudioTrack
, capture your frames, and publish them to the agent's room. It's like being a DJ for your own audio stream!
• Working with JavaScript or TypeScript? The AgentPlayout
is your synchronization superhero, keeping your text and audio streams in perfect harmony.
Want a more personalized walkthrough? Just let me know what kind of agent you're working with and what type of audio you're looking to play. I'd love to help you find the perfect solution!
Sources: meditation_assistant/audio_handler.py | AgentPlayout | LiveKit Agents | agents/src/multimodal/multimodal_agent.ts | basics/playing_audio.py | examples/voice_agents/background_audio.py