Skip to content

Fix: respect external USB-C microphone input during voice message recording#2029

Open
hanxiao wants to merge 1 commit intoTelegramMessenger:masterfrom
hanxiao:fix/external-usb-mic-voice-messages
Open

Fix: respect external USB-C microphone input during voice message recording#2029
hanxiao wants to merge 1 commit intoTelegramMessenger:masterfrom
hanxiao:fix/external-usb-mic-voice-messages

Conversation

@hanxiao
Copy link

@hanxiao hanxiao commented Feb 23, 2026

Problem

When recording voice messages with an external USB-C microphone (e.g. BOYA Mini 2 wireless mic receiver), Telegram ignores the external device and records from the built-in microphone instead.

This happens because setupOutputMode calls overrideOutputAudioPort(.speaker) for voice message recording (.record(false, _, _)). Per Apple docs, this forces both output and input to built-in devices, regardless of other settings.

Other apps (Voice Memos, Camera) correctly use the external microphone. The user can verify the device is recognized in iOS Settings > Sounds & Haptics > Input.

Related: #1195, bugs.telegram.org/c/58429

Fix

After the speaker override, check availableInputs for connected external input devices (excluding built-in mic, Bluetooth, and wired headphones) and restore them as the preferred input via setPreferredInput.

  • 11 lines added, 0 removed
  • No behavior change when no external device is connected
  • Uses try? so failures don't affect existing flows
  • Tested with BOYA Mini 2 USB-C wireless mic on iPhone 17 Pro Max / iOS 26

Diff

case .record(false, _, _):
    try AVAudioSession.sharedInstance().overrideOutputAudioPort(.speaker)
    // overrideOutputAudioPort(.speaker) forces both output AND input
    // to built-in devices. If an external input device (e.g. USB-C
    // microphone) is connected, restore it as the preferred input.
    if let routes = AVAudioSession.sharedInstance().availableInputs {
        for route in routes {
            if route.portType != .builtInMic && !bluetoothPortTypes.contains(route.portType) && route.portType != .headphones {
                let _ = try? AVAudioSession.sharedInstance().setPreferredInput(route)
                break
            }
        }
    }
overrideOutputAudioPort(.speaker) forces both output and input to
built-in devices, ignoring external USB-C microphones (e.g. wireless
mic receivers) that the user selected in iOS Settings.

After the override, check availableInputs for non-built-in, non-bluetooth,
non-headphone input devices and restore them as preferred input.

This preserves existing behavior when no external device is connected.

Fixes: voice messages ignore USB-C microphone on iOS 26+
@CLAassistant
Copy link

CLAassistant commented Feb 26, 2026

CLA assistant check
All committers have signed the CLA.

@hanxiao hanxiao force-pushed the fix/external-usb-mic-voice-messages branch from d385e98 to fa00c05 Compare February 26, 2026 12:24
@520gmail
Copy link

520gmail commented Feb 27, 2026 via email

@520gmail
Copy link

520gmail commented Feb 27, 2026 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants