The audio output from my app, using the react nati...
# ask-ai
n
The audio output from my app, using the react native SDK, is noticeably different than the raw audio being produced by the TTS node. I am using ElevenLabs for TTS and noticed the voice does not sound the same as in their playground. I have recorded the audio output from the app, and compared it to the same audio generation recorded in Livekit’s observability tool. The audio from the app is higher pitched and most nasal or “chipmunk-ey”. The audio captured by Livekit’s observability tool is what would expect (i.e. it closely matches the voice sample from the ElevenLabs playground). Is Livekit’s SDK doing some additional processing on the client side, or is this due to something in the WebRTC stack or in iOS’s audio controls, or something else? I’ve confirmed this issue happens across multiple devices.
t
Thanks for reaching out, Cecchi. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about why the React Native app’s audio sounds higher-pitched and “chipmunk-ey” compared to the ElevenLabs source and LiveKit’s observability recording. Short answer: LiveKit does not intentionally pitch-shift audio on the server, and because the observability recording matches ElevenLabs, the distortion is happening on the client side — most likely due to sample-rate / format mismatches, WebRTC resampling, or iOS audio-session voice processing during playback. What to check next (concise steps you can try now) 1. Confirm sample rate and channels ◦ Verify the exact sample rate (e.g., 24000, 44100, 48000 Hz) and channel count of the ElevenLabs TTS audio. ◦ Ensure the
AudioSource
(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 docs
n
We are using
livekit-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.
t
Thanks — I’m responding to your follow-up about how to check sample rate and frame sizing and the client-side settings you tried. Quick answers and next steps 1) Agent / server-side check (easy, effective) • The agent defaults to 24,000 Hz mono. Explicitly set and log the audio output used when starting the session to confirm it:
Copy code
from 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 docs
n
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.
Does 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?
t
Thanks — I’m addressing your three asks: (1) can ElevenLabs plugin change/inspect sample rate, (2) how to save raw TTS audio with livekit-agents, and (3) how to control frame size. Short answers • Yes — the ElevenLabs plugin supports a
sample_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):
Copy code
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):
Copy code
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:
Copy code
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:
Copy code
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 docs
n
It looks like ElevenLabs TTS does not support sample rate directly but derives it based on a provided encoding. The options are:
Copy code
TTSEncoding = 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?
t
Yes — set your agent’s
audio_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:
Copy code
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