Skip to main content
Version: Next

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, and FLAC 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.

Segment size and quality

concatAudioFiles joins segments losslessly for WAV (32-bit float PCM) and FLAC (lossless re-encode). For M4A, Android remuxes the encoded AAC packets losslessly, while iOS re-encodes the joined audio once through AVFoundation. Each rotated chunk is a separate AAC 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 M4A files, increase rotateIntervalBytes (for example ≥ 200 KB) or record without rotation. WAV and FLAC segments are less sensitive, but the same guidance applies below roughly 512 KB–1 MB per segment.

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, or .flac segments into a .flac 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.