able-jackal-84140
07/11/2025, 8:00 AMtall-airline-16756
07/11/2025, 8:00 AMtall-airline-16756
07/11/2025, 8:01 AMable-jackal-84140
07/11/2025, 8:01 AMtall-airline-16756
07/11/2025, 8:02 AMimport asyncio
import numpy as np
from livekit import rtc
SAMPLE_RATE = 48000
NUM_CHANNELS = 1
source = rtc.AudioSource(SAMPLE_RATE, NUM_CHANNELS)
track = rtc.LocalAudioTrack.create_audio_track("my_custom_audio", source)
options = rtc.TrackPublishOptions()
options.source = rtc.TrackSource.SOURCE_MICROPHONE
publication = await room.local_participant.publish_track(track, options)
2. Generate and Send Audio Frames: Now let's populate an AudioFrame
with your awesome audio data and stream it away! samples_per_channel = 480 # Adjust as needed
for _ in range(num_frames):
audio_frame = rtc.AudioFrame.create(SAMPLE_RATE, NUM_CHANNELS, samples_per_channel)
audio_data = np.frombuffer(audio_frame.data, dtype=np.int16)
# Fill audio_data with your custom signal (e.g., sine wave, recorded samples)
await source.capture_frame(audio_frame)
Quick Pro Tips:
• Use 48kHz for crystal-clear sound, or 16kHz if you're just chatting.
• Keep your frame timing consistent for super smooth playback.
• Aim for queue sizes between 1000-2000ms to avoid any hiccups.
Got any questions or need help generating those audio frames? I'm right here - just ask, and we'll figure it out together!