react-native-audio-api
Version:
react-native-audio-api provides system for controlling audio in React Native environment compatible with Web Audio API specification
38 lines (37 loc) • 1.13 kB
JavaScript
;
import AudioBuffer from "./AudioBuffer.js";
import { AudioEventEmitter } from "../events/index.js";
export default class AudioRecorder {
audioEventEmitter = new AudioEventEmitter(global.AudioEventEmitter);
constructor(options) {
this.recorder = global.createAudioRecorder(options);
}
start() {
this.recorder.start();
}
stop() {
this.recorder.stop();
}
connect(node) {
if (node.wasConnected) {
throw new Error('RecorderAdapterNode cannot be connected more than once. Refer to the documentation for more details.');
}
node.wasConnected = true;
this.recorder.connect(node.getNode());
}
disconnect() {
this.recorder.disconnect();
}
onAudioReady(callback) {
const onAudioReadyCallback = event => {
callback({
buffer: new AudioBuffer(event.buffer),
numFrames: event.numFrames,
when: event.when
});
};
const subscription = this.audioEventEmitter.addAudioEventListener('audioReady', onAudioReadyCallback);
this.recorder.onAudioReady = subscription.subscriptionId;
}
}
//# sourceMappingURL=AudioRecorder.js.map