Skip to content

[BUG] iOS: onAudioStream audioData.compression is null #285

@alexanderrudnik

Description

@alexanderrudnik

Environment

  • expo-audio-studio version: 2.18.1
  • Expo SDK version: ^53.0.11
  • Platform & OS version: iOS 18.5
  • Device: iPad Air 11 M2

Description

Hi!
First of all thank you for that great library!

I want to stream compressed audio data (AAC) on iOS and Android platforms. But when I listen to onAudioStream event and get audioData, the compression property is always null there.

Android works well, but iOS doesn't transmit compression property (in the source code it is always null). That behaviour was changed in 2.5.0 version (commit - 023b8a1#diff-229908ba37fb197b32c1ae5f915dc74e00f0ad1603b141b55b34a1cc92b78660)

It worked well in expo-audio-studio v2.4.1

Cross-Platform Validation

AudioPlayground Apps

Can this issue be reproduced in the AudioPlayground app?

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

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

  1. Create config and specify output.compressed values there.
  2. Add listiner to onAudioStream
  3. Check the result audio chunk data

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)

Configuration

const config: RecordingConfig = {
  interval: 1000, // 1sec
  sampleRate: Platform.OS === 'ios' ? 44100 : 48000,
  channels: 1,
  encoding: 'pcm_16bit',
  output: {
    primary: {
      enabled: false,
    },
    compressed: {
      enabled: true,
      format: 'aac',
      bitrate: 64000,
    },
  },

  onAudioAnalysis: async analysisEvent => {
    console.log('onAudioAnalysis', analysisEvent);
  },

  onRecordingInterrupted: event => {
    console.log(`Recording interrupted: ${event.reason}`);
  },

  autoResumeAfterInterruption: false,
};

const handleStartRecording = async (handleChunk: (data: any) => void) => {
    const result = await startRecording({
      ...config,
      onAudioStream: async audioData => {
        console.log('onAudioStream', audioData);
        console.log('onAudioStream compression', audioData.compression);
        // handleChunk(audioData.data);
        if (audioData.compression?.data) {
          handleChunk(audioData.compression.data);
        }
      },
    });

    console.log('result', result);

    return result;
  };

Logs

onAudioStream, valid PCM audio data
onAudioStream compression, undefined

[handleAudioEvent] Received audio event:
{
    "fileUri": "",
    "deltaSize": 88200,
    "totalSize": 264600,
    "position": 3254,
    "mimeType": "audio/wav",
    "lastEmittedSize": 264600,
    "streamUuid": "495FB013-6D64-46D5-8B71-22C24E15D600",
    "encodedLength": 117600,
    "compression": undefined
}

Status: paused: false isRecording: true durationMs: 2323 size: 176400 
{
    "mimeType": "audio/aac",
    "fileUri": "file:///var/mobile/Containers/Data/Application/FA89CBE6-2333-415E-B28F-55F15B09D07E/Documents/495FB013-6D64-46D5-8B71-22C24E15D600.m4a",
    "size": 64521,
    "format": "aac",
    "bitrate": 32000
}

Expected Behavior

I expect compressed chunk in onAudioStream event.

Actual Behavior

audioData.compression is null

Additional Context

My goal is to stream AAC audio data. If my approach above is incorrect, could you please suggest a working solution?

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