nutritious-bird-16298
12/12/2025, 8:56 PMtall-airline-16756
12/12/2025, 8:56 PMtall-airline-16756
12/12/2025, 8:57 PMAudioSource (or whatever you use to publish audio) is created with the same sample rate and channel count. Mismatches force resampling which can change pitch.
1. Verify frame sizing / buffering
◦ Stream audio in WebRTC-friendly frame sizes (typically 20ms frames). Very small or irregular frames can cause playback artifacts or timing issues that affect pitch.
1. Inspect React Native / native WebRTC audio settings
◦ The React Native SDK uses native WebRTC (react-native-webrtc) which may resample or apply processing. Check whether any audio preferences are set that select a voice/communication audio path instead of a media playback path.
1. Check iOS audio session (if issue is on iOS)
◦ iOS may apply voice processing (echo cancellation, sample-rate conversion) when the audio session category is a communication/voice mode. Try configuring the audio session for media playback (no voice processing) or disabling voice processing if your setup exposes that option.
1. Cross-check on a minimal client
◦ Test playing the same remote track in a minimal WebRTC/React Native app (or native WebRTC sample) to confirm whether the issue reproduces outside your app’s audio pipeline.
If you want, share these specifics and I’ll help narrow it down:
• React Native SDK + react-native-webrtc versions
• iOS version(s) and device models where you observe it
• ElevenLabs sample rate / file properties
• How you’re creating/publishing the audio frames (code snippet or AudioSource settings)
I can then suggest exact code changes or config settings to stop client-side resampling/voice processing. Would you like to share those details?
Sources: Camera & microphone | LiveKit docs | LiveKit coming to React Native! | client-sdk-flutter | livekit/livekit_composite | DeepWiki | client-sdk-swift | livekit/livekit_composite | DeepWiki | React Native quickstart | LiveKit docsnutritious-bird-16298
12/12/2025, 9:02 PMlivekit-agents, with no special audio-related logic on the server side. We have not set audio_output on the room options. How do I check the sample rate and/or frame sizing?
On the client side, we are only using useIOSAudioManagement with preferSpeakerOutput=true. I have tested overriding the audioCategory to playAndRecord and the audioMode to default without any improvement.tall-airline-16756
12/12/2025, 9:02 PMfrom livekit.agents import voice
await session.start(
room_options=voice.RoomOptions(
audio_output=voice.AudioOutputOptions(
sample_rate=24000,
num_channels=1
)
)
)
• If your ElevenLabs TTS produces a different rate (e.g., 16k or 48k), set the agent’s sample_rate to match the TTS output. Mismatched sample rates are the most likely cause of pitch shift.
2) Verify TTS output sample rate
• Export or inspect the raw TTS audio file (local file or buffer) and check its sample rate and channels (many OS tools or audio editors show this). If the TTS plugin supports a sample_rate parameter, set it to the same value you set on the agent.
3) Frame sizing / chunking
• WebRTC expects regular frames (typically 10–20 ms). Ensure you send audio frames sized accordingly from the agent to avoid timing artifacts.
• If you stream small/uniform chunks from TTS, buffer/repack them into 20ms frames before publishing.
4) React Native client constraints
• The React Native SDK does not expose raw frame/sample inspection for playback. Because the observability recording sounds correct, the problem is client-side playback/resampling.
• You already tried useIOSAudioManagement and switching categories — good. Also check:
◦ No other audio middleware is active (e.g., background music, voice-effect libs).
◦ Audio routing or sample-rate conversions applied by any native modules you include.
• If possible, test with a non-React Native client (web or native desktop) subscribing to the same room: if that playback is correct, the issue is specific to React Native / react-native-webrtc pipeline.
What I need from you to proceed
• Which TTS plugin and its configured sample_rate (or the audio file’s sample rate).
• Your agent audio_output config (or confirm you set it to 24000/other).
• Whether non-React-Native clients (web/desktop) hear the audio correctly when subscribing to the same room.
If you share those three items I’ll provide exact changes or a minimal repro test to isolate whether it’s resampling, iOS session processing, or react-native-webrtc playback behavior.
Sources: Agent session | LiveKit docs | Rime TTS plugin guide | LiveKit Docs | Smallest AI TTS plugin guide | LiveKit docs | Camera & microphone | LiveKit docsnutritious-bird-16298
12/12/2025, 9:07 PMIf your ElevenLabs TTS produces a different rate (e.g., 16k or 48k), set the agent’sDoes the ElevenLabs livekit plugin support changing this? Or inspecting it somehow? There are some Livekit docs suggesting differen sample rates for different APIs/codecs/etc. https://help.elevenlabs.io/hc/en-us/articles/15754340124305-What-audio-formats-do-you-support Or: using livekit agents how can i easily save the raw TTS audio file? Do I need to add a TTS node and redirect it somewhere? Similarly, using livekit agents how do I/can I control the frame size?to match the TTS output. Mismatched sample rates are the most likely cause of pitch shift.sample_rate
tall-airline-16756
12/12/2025, 9:07 PMsample_rate parameter you can set.
• Yes — you can save raw TTS audio by consuming the TTS stream and writing frames to a file (WAV).
• Yes — you can control frame size by configuring frame_size_ms in `RoomOptions.audio_input`/`audio_output` or by repacking frames you receive from TTS.stream().
What to do next (step‑by‑step)
1) Set and confirm ElevenLabs TTS sample rate
• When creating the ElevenLabs TTS instance, set sample_rate to the value you want (e.g., 24000 or 48000):
from livekit.plugins import elevenlabs
tts = elevenlabs.TTS(voice_id="your-voice-id", model="eleven_multilingual_v2", sample_rate=24000)
• Make the agent’s audio_output use the same sample rate (see step 2). End-to-end sample-rate consistency prevents resampling pitch shifts.
2) Save raw TTS audio to a file
• Use TTS.stream() and write frames to a WAV file. Example (async):
import wave
from livekit.plugins import elevenlabs
tts = elevenlabs.TTS(voice_id="your-voice-id", sample_rate=24000)
stream = tts.stream()
with wave.open("tts_out.wav", "wb") as wf:
wf.setnchannels(1)
wf.setsampwidth(2) # 16-bit PCM
wf.setframerate(24000)
async for chunk in stream:
frame = chunk.audio.frame
wf.writeframes(frame.data)
• This produces the exact audio the plugin generated so you can inspect sample rate, channels, and listen locally.
3) Configure agent room audio output and frame size
• Explicitly set audio_output in RoomOptions to match the TTS sample rate and channel count:
from livekit.agents.voice import room_io
await session.start(
room_options=room_io.RoomOptions(
audio_output=room_io.AudioOutputOptions(
sample_rate=24000,
num_channels=1
)
)
)
• Control frame size (ms) for input/output where available:
room_io.AudioInputOptions(frame_size_ms=20)
Supported sizes are multiples of 10ms (commonly 10, 20, 50). If TTS.stream() emits frames at a fixed size, you can repackage them into your desired ms length before publishing.
4) Verify and debug
• Save the TTS WAV and open it in an editor (or run sox --i tts_out.wav) to confirm sample rate and channels.
• Set agent audio_output.sample_rate to that same value.
• Join the room with a minimal non-React Native client (web or desktop). If that client plays correctly while the React Native app does not, the issue is in the React Native / react-native-webrtc playback pipeline (resampling or iOS audio session).
If you want, share:
• The ElevenLabs sample_rate you’re currently using (or a TTS file),
• Your RoomOptions snippet (if any),
• Whether non-RN clients play correctly.
I’ll provide the exact code/config tweaks to match rates, repack frames, or isolate React Native playback differences.
Sources: ElevenLabs TTS plugin guide | LiveKit Docs | Text-to-speech (TTS) models | LiveKit Docs | Agent session | LiveKit docs | Processing raw media tracks | LiveKit docs | Smallest AI TTS plugin guide | LiveKit docsnutritious-bird-16298
12/12/2025, 9:13 PMTTSEncoding = Literal[
"mp3_22050_32",
"mp3_44100",
"mp3_44100_32",
"mp3_44100_64",
"mp3_44100_96",
"mp3_44100_128",
"mp3_44100_192",
]
A code comment in the plugin shows:
# by default, use 22.05kHz sample rate at 32kbps
# in our testing, reduce TTFB by about ~110ms
_DefaultEncoding: TTSEncoding = “mp3_22050_32"So do I just set sample_rate in my room_io.AudioOutputOptions to 22050 instead of 24000? Is this likely the issue?
tall-airline-16756
12/12/2025, 9:13 PMaudio_output.sample_rate to 22050 to match ElevenLabs’ default mp3_22050_32 encoding. A 22.05 kHz ↔️ 24 kHz mismatch is a very likely cause of the higher‑pitched / “chipmunk” audio you hear.
What to do:
1. In your agent start, explicitly set audio output to 22050 Hz and mono:
from livekit.agents.voice import room_io
await session.start(
room_options=room_io.RoomOptions(
audio_output=room_io.AudioOutputOptions(
sample_rate=22050,
num_channels=1
)
)
)
1. Save a TTS sample (use TTS.stream() to write a WAV) and confirm the file’s sample rate locally to verify it’s 22.05 kHz.
2. Re-test playback in the React Native app. If distortion disappears, the sample-rate mismatch was the cause.
Optional alternative:
• Force ElevenLabs to produce 44.1 kHz by selecting an mp3_44100 encoding, and then set audio_output.sample_rate to 44100 instead — just ensure end-to-end rates match.
If you want, share which encoding you’re using now (or a saved TTS WAV), and I’ll confirm the exact config to apply.
Sources: Agent session | LiveKit docs | ElevenLabs TTS plugin guide | LiveKit Docs