AudioRecorder
Constructor
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();
}
Methods
start
The above starts recording.
Returns undefined
.
stop
The above stops recording.
Returns undefined
.
connect
The above method connects recorder to the adapter. If the recorder is already connected it will change its adapter (it is equivalent of calling disconnect() previously).
Be carefull RecorderAdapterNode
can be connected only once. You can't connect same adapter twice (even to different recorders).
Parameters | Type | Description |
---|---|---|
node | RecorderAdapterNode | Adapter that we want to connect to. |
Returns undefined
disconnect
The above method disconnects recorder from the currently connected adapter. It does not need to be called before connect.
onAudioReady
The above allows user to set a callback after every portion of data deliverance.
Parameters | Type | Description |
---|---|---|
callback | (OnAudioReadyEventType => void) | callback that will be invoked |
Returns undefined
.
Remarks
AudioRecorderOptions
Type definitions
interface AudioRecorderOptions {
sampleRate: number;
bufferLengthInSamples: number; //how many samples to be put in the buffer
}
OnAudioReadyEventType
Type definitions
interface OnAudioReadyEventType {
buffer: AudioBuffer;
numFrames: number; //number of frames in a buffer
when: number; //timestamp
}