I’m using LiveKit SDK version 2.23.0, but sometime...
# ask-ai
w
I’m using LiveKit SDK version 2.23.0, but sometimes the voice burging doesn’t work properly. It looks like the mic buffer isn’t being captured by LiveKit or the audio isn’t being sent to the agent. However, on the web version everything works perfectly. What could be causing this issue, and how can I fix it?
t
Thanks for reaching out, Sandip. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m looking into the voice buffering problem you described (SDK 2.23.0: mic buffer not captured / audio not sent, web works). A few targeted questions and immediate checks will help narrow this down quickly. Questions 1. Which platform and SDK binding are you using? (Flutter, iOS native, Android native, React Native, etc.) 2. Are you using any audio-related plugins or background services (for example
flutter_background_service
) alongside LiveKit? 3. Is the pre-connect buffering explicitly enabled in your client code (e.g.,
withPreconnectAudio
or equivalent)? 4. Are microphone permissions confirmed and granted at runtime on the device? (iOS
Info.plist
, Android
AndroidManifest.xml
) 5. Can you reproduce this consistently on a single platform/device or is it intermittent across multiple devices? Immediate actions you can try • Ensure pre-connect audio is enabled in your platform code (use
withPreconnectAudio
or the SDK equivalent). • Verify microphone permissions are declared and granted on the device. • If using Flutter on iOS, remove or disable background/audio-interfering plugins (e.g.,
flutter_background_service
) to rule out plugin conflicts. • Set
bypassVoiceProcessing
explicitly (try
false
) during SDK initialization so echo cancellation/AGC/noise suppression run consistently. • Test on a device without extra audio plugins to see if the issue persists; this isolates SDK vs app/plugin interactions. • If possible, upgrade the SDK from 2.23.0 to the latest patch — known mobile audio issues have been fixed in later releases. If you tell me the platform and your answers to the questions above, I’ll give exact code locations and the next steps to test and fix this. Sources: Agent speech and audio | LiveKit docs | [Flutter iOS] SoundWaveformWidget / AudioVisualizerWidget Not Working (Miss... | Mobile SDKs (Flutter, iOS, Android) | livekit/livekit_composite | DeepWiki | Android quickstart | LiveKit docs
w
1. I am building android client app with livekit 2. No I am not doing any audio related service's 3. I am not do anything extra for buffer collection. Livekit SDK itself getting all 4. Yes Microphone permission is there. 5. Yes it is on device android 14
t
Thanks — based on your answers (Android client, no extra audio services, permissions granted, Android 14), the most likely cause is that pre-connect (instant connect) audio buffering isn’t enabled. The Android SDK does not start the mic buffer automatically unless you explicitly enable it. What to do now 1. Wrap your connection code in
withPreconnectAudio { ... }
so the SDK starts capturing mic audio while connecting. Example:
Copy code
room.withPreconnectAudio {
  val (url, token) = tokenService.fetchConnectionDetails()
  room.connect(url = url, token = token)
}
1. Ensure you request
RECORD_AUDIO
at runtime (manifest + runtime prompt). 2. Don’t manually call
setMicrophoneEnabled(true)
before/inside
withPreconnectAudio
— let
withPreconnectAudio
manage the mic. 3. If the problem persists after enabling
withPreconnectAudio
, try updating from 2.23.0 to a newer SDK build (mobile audio fixes were made in later releases). If you want, paste the snippet where you connect to the room and I’ll point out exactly where to add
withPreconnectAudio
and any small changes to verify. Sources: Agent speech and audio | LiveKit docs | Android quickstart | LiveKit docs
w
LiveKitWrapper.kt
t
Thanks — quick check: were you able to add
withPreconnectAudio { ... }
around your room connect call and test on the Android 14 device? If you did and it still fails, please paste the connect snippet (or describe any errors/log output) and I’ll point out exactly what to change and what to inspect next.
w
Can you mentioned where to add
t
Wrap the code that performs the Room connection with
withPreconnectAudio { ... }
. Put the wrapper immediately before you call
room.connect(...)
so the SDK starts the mic capture while the connection completes. Example placement in a typical flow:
Copy code
// obtain url/token first (or inside the block if you fetch there)
val (url, token) = tokenService.fetchConnectionDetails()

// start pre-connect audio, then connect
room.withPreconnectAudio {
  room.connect(
    url = url,
    token = token,
    // any other connect options you already use
  )
}
If you fetch the token asynchronously inside the block, do that instead:
Copy code
room.withPreconnectAudio {
  val (url, token) = tokenService.fetchConnectionDetails()
  room.connect(url = url, token = token)
}
What to check after adding: • Ensure you are not calling
setMicrophoneEnabled(true)
before or instead of this block. • Confirm runtime
RECORD_AUDIO
permission is granted on Android 14. • Watch logs for any errors during
withPreconnectAudio
or
room.connect
. Paste your current connect snippet if you want me to insert the exact lines for your code.
w
I have already uploaded livekit wrapper code
t
Thanks — please paste the part of your LiveKit wrapper where you call
room.connect(...)
(or the surrounding function). I’ll insert the exact
withPreconnectAudio { ... }
placement and any small fixes for Android 14.
w
// Connection method fun connectToRoom(userName: String, metadata: String, userToken: String?, callback: CallbackInterfaces.ConnectionCallback) { if (isCleanedUp.get()) { callback.onError("LiveKitWrapper has been cleaned up") return } // Prevent multiple simultaneous connections if (!isConnecting.compareAndSet(false, true)) { Log.w(TAG, "Connection already in progress, ignoring duplicate request") callback.onError("Connection already in progress") return } scope.launch { try { Log.d(TAG, "Connecting user '$userName' to LiveKit room...") // Clean up any existing connection completely before starting new one cleanupExistingConnection() _connectionState.postValue(ConnectionState.CONNECTING) val connectionDetails = withTimeout(CONNECTION_TIMEOUT) { getConnectionDetails(userName, metadata) } if (connectionDetails != null) { Log.d(TAG, "Connecting to LiveKit server: ${connectionDetails.url}") val audioOptions = AudioOptions( audioOutputType = AudioType.MediaAudioType() ) val liveKitOverrides = LiveKitOverrides( audioOptions = audioOptions ) LiveKit.enableWebRTCLogging = true LiveKit.loggingLevel = LoggingLevel.DEBUG val newRoom = LiveKit.create( appContext = context, overrides = liveKitOverrides ) // LiveKit.trace = true // enables detailed logs this@LiveKitWrapper.room = newRoom // Connect with timeout withTimeout(CONNECTION_TIMEOUT) { newRoom.connect( url = connectionDetails.url, token = connectionDetails.token, options = ConnectOptions() ) } // Setup event listeners BEFORE enabling microphone setupEventListeners() // Enable microphone for real voice detection scope.launch(Dispatchers.IO) { // <─ 1. move off Main while (!isConnected() && !isCleanedUp.get()) { Log.d(TAG, "Waiting for connection before enabling microphone") delay(100) } withContext(Dispatchers.Main) { newRoom.localParticipant.setMicrophoneEnabled(true) _isRecording.postValue(true) Log.d(TAG, "Microphone enabled after connection verification") } } Log.d(TAG, "Microphone enabled - using real LiveKit voice detection") _connectionState.postValue(ConnectionState.CONNECTED) startAgentFlow() Log.d(TAG, "Successfully connected - real-time voice detection active") callback.onSuccess() } else { Log.e(TAG, "Failed to get connection details") _connectionState.postValue(ConnectionState.ERROR) callback.onError("Failed to get connection details") } } catch (e: TimeoutCancellationException) { Log.e(TAG, "Connection timeout: ${e.message}", e) _connectionState.postValue(ConnectionState.ERROR) callback.onError("Connection timeout") } catch (e: Exception) { Log.e(TAG, "Connection failed: ${e.message}", e) _connectionState.postValue(ConnectionState.ERROR) callback.onError("Connection failed: ${e.message}") } finally { isConnecting.set(false) } } }
t
Thanks — I reviewed your connect code. Place
withPreconnectAudio { ... }
around the call to
newRoom.connect(...)
so microphone capture starts while the room is connecting. Replace your current connect block with this pattern:
Copy code
// start pre-connect audio, then connect
newRoom.withPreconnectAudio {
  // perform the connect while mic is being buffered
  withTimeout(CONNECTION_TIMEOUT) {
    newRoom.connect(
      url = connectionDetails.url,
      token = connectionDetails.token,
      options = ConnectOptions()
    )
  }
}
Minimal integrated change in your function (showing context):
Copy code
val newRoom = LiveKit.create(appContext = context, overrides = liveKitOverrides)
this@LiveKitWrapper.room = newRoom

// START: enable pre-connect audio here
newRoom.withPreconnectAudio {
  withTimeout(CONNECTION_TIMEOUT) {
    newRoom.connect(
      url = connectionDetails.url,
      token = connectionDetails.token,
      options = ConnectOptions()
    )
  }
}
// END

// Setup event listeners BEFORE enabling microphone
setupEventListeners()

// existing microphone enable loop...
Notes: • Don’t call
setMicrophoneEnabled(true)
before or instead of
withPreconnectAudio
— let the block handle initial capture. • Keep your runtime
RECORD_AUDIO
permission checks. • Test on the Android 14 device after this change and share logs or the connect snippet if buffering still fails.