Skip to content

Add USB microphone input device support#1611

Merged
aleksandar-apostolov merged 4 commits intodevelopfrom
feature/usb-microphone-support
Feb 10, 2026
Merged

Add USB microphone input device support#1611
aleksandar-apostolov merged 4 commits intodevelopfrom
feature/usb-microphone-support

Conversation

@aleksandar-apostolov
Copy link
Contributor

@aleksandar-apostolov aleksandar-apostolov commented Feb 6, 2026

Goal

Add support for detecting and selecting USB audio input devices (microphones) that are not recognized by Twilio AudioSwitch.

Problem: USB microphones that are input-only (e.g., Rode Wireless Go II) are not detected by AudioSwitch because it uses ACTION_HEADSET_PLUG broadcast which only fires for devices with both input AND output capabilities. This causes professional USB microphones to be invisible to the SDK.

Reported issue: Live streaming feature on Patreon doesn't detect Rode Wireless Go II mics on OnePlus Nord 4, while the same mics work fine with the native Camera app.

Implementation

Use Android's native AudioDeviceCallback API (API 23+) to detect USB input devices, then route audio via JavaAudioDeviceModule.setPreferredInputDevice().

Changes:

  1. New UsbAudioInputDevice class - Wraps AudioDeviceInfo for USB input devices

  2. MicrophoneManager additions:

    • usbInputDevices: StateFlow<List<UsbAudioInputDevice>> - detected USB devices
    • selectedUsbDevice: StateFlow<UsbAudioInputDevice?> - current selection
    • listUsbDevices() - get available USB input devices
    • selectUsbDevice(device) - route audio to specific USB device
    • clearUsbDeviceSelection() - restore default routing
    • Auto-selects first USB device when detected (if none selected)
  3. StreamPeerConnectionFactory additions:

    • setPreferredAudioInputDevice(AudioDeviceInfo?) - expose WebRTC device routing

Usage:

// USB detection is automatic on API 23+
// List USB microphones
call.microphone.listUsbDevices().collect { devices ->
    Log.d("USB", "Found USB mics: $devices")
}

// Select a specific USB microphone
val rodeMic = call.microphone.usbInputDevices.value
    .firstOrNull { "Rode" in it.name }
rodeMic?.let { call.microphone.selectUsbDevice(it) }

// Clear selection (restore default)
call.microphone.clearUsbDeviceSelection()

Testing

  • Test with other USB microphones
  • Test USB device hotplug (connect/disconnect during call)
  • Verify audio quality and latency
  • Test on different Android versions

## Goal

**NOTE: This is a DRAFT PR for testing purposes only.**

Add support for detecting and selecting USB audio input devices (microphones)
that are not recognized by Twilio AudioSwitch.

## Problem

USB microphones that are input-only (e.g., Rode Wireless Go II) are not detected
by AudioSwitch because it uses ACTION_HEADSET_PLUG broadcast which only fires
for devices with both input AND output capabilities.

This causes professional USB microphones to be invisible to the SDK, and the
app always falls back to the phone's built-in microphone.

## Solution

1. Add UsbAudioInputDevice class to represent USB input devices using
   Android's native AudioDeviceInfo API

2. Add AudioDeviceCallback in MicrophoneManager to detect USB devices:
   - usbInputDevices: StateFlow - detected devices
   - selectedUsbDevice: StateFlow - current selection
   - listUsbDevices() - get available USB input devices
   - selectUsbDevice(device) - route audio to USB device
   - clearUsbDeviceSelection() - restore default routing

3. Expose setPreferredAudioInputDevice() in StreamPeerConnectionFactory
   to route WebRTC audio capture to the selected device via
   JavaAudioDeviceModule.setPreferredInputDevice()

## Requirements

- Android M (API 23) or higher for USB device detection
- USB device must be connected before/during the call
@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

PR checklist ✅

All required conditions are satisfied:

  • Title length is OK (or ignored by label).
  • At least one pr: label exists.
  • Sections ### Goal, ### Implementation, and ### Testing are filled.

🎉 Great job! This PR is ready for review.

@aleksandar-apostolov aleksandar-apostolov changed the title feat(audio): add USB microphone input device support add USB microphone input device support Feb 6, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

SDK Size Comparison 📏

SDK Before After Difference Status
stream-video-android-core 11.96 MB 11.96 MB 0.00 MB 🟢
stream-video-android-ui-xml 5.68 MB 5.68 MB 0.00 MB 🟢
stream-video-android-ui-compose 6.27 MB 6.27 MB 0.00 MB 🟢

@aleksandar-apostolov aleksandar-apostolov added the pr:new-feature Adds new functionality label Feb 10, 2026
@aleksandar-apostolov aleksandar-apostolov changed the title add USB microphone input device support Add USB microphone input device support Feb 10, 2026
@aleksandar-apostolov aleksandar-apostolov marked this pull request as ready for review February 10, 2026 09:43
@aleksandar-apostolov aleksandar-apostolov requested a review from a team as a code owner February 10, 2026 09:43
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
4.6% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@aleksandar-apostolov aleksandar-apostolov merged commit ad80323 into develop Feb 10, 2026
19 of 25 checks passed
@aleksandar-apostolov aleksandar-apostolov deleted the feature/usb-microphone-support branch February 10, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:new-feature Adds new functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants