Skip to main content

AudioRecorder

AudioRecorder provides a simple way to manage audio recording. It connects to the audio graph through a RecorderAdapterNode and triggers events when new audio data is ready.

Constructor

AudioRecorder(options: AudioRecorderOptions)

interface AudioRecorderOptions {
sampleRate: number;
bufferLengthInSamples: number; //how many samples to be put in the buffer
}

Example

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

function App() {
const recorder = new AudioRecorder({
sampleRate: 16000,
bufferLengthInSamples: 16000,
});

recorder.onAudioReady((event) => {
const { buffer, numFrames, when } = event;

console.log(
'Audio recorder buffer ready:',
buffer.duration,
numFrames,
when
);
});

recorder.start();
}

Properties

None. AudioRecorder has no own or inherited properties.

Methods

start

Starts recording.

Returns undefined.

stop

Stops recording.

Returns undefined.

connect

Connects recorder to the adapter. If the recorder is already connected, it will switch to the new adapter (it is equivalent to calling disconnect() previously). Be careful RecorderAdapterNode can be connected only once. You can't connect same adapter twice (even to different recorders).

ParametersTypeDescription
nodeRecorderAdapterNodeAdapter that we want to connect to.

Returns undefined.

disconnect

Disconnects recorder from the currently connected adapter. It does not need to be called before connect.

Returns undefined.

onAudioReady

Sets a callback after every portion of data deliverance.

ParametersTypeDescription
callback(OnAudioReadyEventType => void)The callback function to handle audio data.

Returns undefined.

Remarks

OnAudioReadyEventType

Type definitions
interface OnAudioReadyEventType {
buffer: AudioBuffer;
numFrames: number; //number of frames in a buffer
}