Skip to content

[BUG] Audio switches automatically and breaks the audio analysis #300

@rolandschuetz

Description

@rolandschuetz

Environment

  • expo-audio-studio version: 2.18.1
  • Expo SDK version: 53
  • Platform & OS version: iOS 18
  • Device: iPhone 16

Description

Unintended switching of audio devices, Steps to reproduce:

  1. Configure RecordingConfig with ios.audioSession.categoryOptions = ['AllowBluetooth'] and define a deviceId for the built-in mic
  2. Start the recording, then connect bluetooth AirPods
  3. The waveform stops, no new audio analysis data and the recording switches to the AirPods

Cross-Platform Validation

The above steps can be reproduced with the AudioPlayer app on iOS. I couldn't test on Android because there the recording never started.

Can this issue be reproduced in the AudioPlayground app?

  • Yes, on all platforms (Web, iOS, Android)
  • Yes, but only on specific platforms (please specify): iOS
  • No, it only happens in my app

Reproduction steps in the AudioPlayground app (including any settings you modified):

  1. Microphone: Bulit-In
  2. Advanced Settings > Custom iOS Audio Settings > Mode: Measurement
  3. Advanced Settings > Custom iOS Audio Settings > Category: [Allow Bluetooth]

Even if I disable Allow Bluetooth and start with the internal mic in the sample app and then connect Bluetooth, the waveform stops updating (and I guess the audio switched).

Is the behavior consistent across platforms?

  • Yes, the issue occurs the same way on all platforms I tested
  • No, the behavior differs between platforms (please describe the differences)

Couldn't get the app running on Android.

Configuration

{
            sampleRate: 16000,
            channels: 1,
            encoding: 'pcm_16bit',
            keepAwake: true,
            showNotification: true,
            showWaveformInNotification: false,
            autoResumeAfterInterruption: true,
            android: {
                audioFocusStrategy: 'background',
            },
            ios: {
                audioSession: {
                    category: 'PlayAndRecord',
                    // Use 'Measurement' to minimize system processing during capture for higher STT accuracy.
                    // Avoid 'SpokenAudio' which is intended for playback of spoken content.
                    // Do not set 'DefaultToSpeaker' by default to prevent forcing speaker routing while recording.
                    mode: 'Measurement',
                    categoryOptions: ['AllowBluetooth'],
                },
            },
            output: {
                primary: { enabled: true, format: 'wav' },
                compressed: {
                    enabled: true,
                    format: 'aac',
                    bitrate: compressedBitrate,
                },
            },
            // Ensure that recording continues on the default device if the current device disconnects
            deviceDisconnectionBehavior: 'fallback',

            // Animate metering at ~25 FPS
            enableProcessing: true,
            intervalAnalysis: 20,
            segmentDurationMs: 20,

            onAudioStream: onAudioStream,
            onAudioAnalysis: extractMeteringVisualizationDataFromAudioAnalysis,
            onRecordingInterrupted: handleRecordingInterrupted,
        };

Logs

no logs

Expected Behavior

No device switching

Actual Behavior

Switching to bluetooth

Additional Context

Checklist

  • I have updated to the latest version of expo-audio-studio
  • I have checked the documentation
  • I have tested in the official AudioPlayground app
  • I have verified microphone permissions are properly set up
  • I have filled out all required fields in this template

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions