Skip to main content
Version: Latest

File concatenation
Mobile only

You can concatenate existing audio files without creating an AudioContext using the exported concatAudioFiles function.

This is useful when recording with the rotateIntervalBytes option. Rotation keeps long recordings split into smaller files while recording, and concatAudioFiles can join those files back into one file after the recording is finished.

warning

concatAudioFiles is not supported on web.

caution

Only WAV, M4A, FLAC, ADTS, and OGG (Opus) concatenation is supported — the recording formats available on both iOS and Android.

WAV and FLAC decode the segments and write them out again through the system encoder — WAV as 32-bit float PCM, FLAC losslessly. M4A remuxes AAC packets with system APIs — iOS AVFoundation and Android MediaExtractor/MediaMuxer. OGG re-pages the Opus packets with the bundled libogg on both platforms, so it is unavailable when the package's static libraries are disabled with disableStaticExternalLibs.

ADTS (.aac) appends complete encoded frames without decoding or re-encoding. Inputs must use the same sample rate and channel configuration. An incomplete trailing frame, such as one left by an app crash, is discarded before the next file's frames are appended.

Segment size and quality

Each rotated chunk is a separate encode, so very small rotateIntervalBytes values can still produce clicks, muffled joins, or timing gaps after concatenation.

If playback quality is poor after joining rotated files, increase rotateIntervalBytes (for example ≥ 200 KB) or record without rotation.

concatAudioFiles​

Concatenates compatible local audio files into a single output file.

ParameterTypeDescription
inputPathsstring[]Local filesystem paths or file:// URLs to concatenate, in output order.
outputPathstringLocal filesystem path or file:// URL where the joined audio file should be written.

Returns Promise<string>.​

The promise resolves with the provided outputPath when concatenation completes.

Compatibility​

All input files must use compatible audio parameters. In practice, files should come from the same recorder configuration:

  • the same container format,
  • the same audio codec,
  • the same sample rate,
  • the same channel layout,
  • compatible codec parameters.

Use an output path with an extension that matches the input files, for example joining .m4a segments into an .m4a output file, .wav segments into a .wav output file, .flac segments into a .flac output file, ADTS .aac segments into an .aac output file, or .ogg segments into an .ogg output file.

Example usage with rotated recordings

import { AudioRecorder, FileDirectory, FileFormat, concatAudioFiles } from 'react-native-audio-api';

async function finalizeRotatedRecording() {
const audioRecorder = new AudioRecorder();

audioRecorder.enableFileOutput({
directory: FileDirectory.Cache,
fileName: 'meeting',
format: FileFormat.M4A,
rotateIntervalBytes: 8 * 1024 * 1024,
});

// Start and stop the recorder as usual.
const result = await audioRecorder.stop();

if (result.status === 'success') {
const outputPath = result.paths[0].replace(/[^/]+$/, 'meeting-complete.m4a');

await concatAudioFiles(result.paths, outputPath);
}
}

Example usage with explicit paths

import { concatAudioFiles } from 'react-native-audio-api';

const outputPath = '/path/to/session.m4a';

await concatAudioFiles(
['/path/to/session-001.m4a', '/path/to/session-002.m4a', '/path/to/session-003.m4a'],
outputPath
);

We are Software Mansion.