I concatenate two AudioBuffers into one.
It seems to me this should be possible without using the MediaRecorder, for I don't need to record in realtime.
This is what I do now:
concatAudio(buffers: AudioBuffer[]): void {
const totalLength = buffers.reduce((acc, buffer) => acc + buffer.length, 0);
const audioContext = new AudioContext();
const audioBuffer = audioContext.createBuffer(1, totalLength, 48000);
const src = audioContext.createBufferSource();
const dst = audioContext.createMediaStreamDestination();
let offset = 0;
buffers.map((buffer) => {
audioBuffer.getChannelData(0).set(buffer.getChannelData(0), offset);
offset += buffer.length;
});
src.buffer = audioBuffer;
src.connect(dst);
src.start();
this.recordAudio(dst.stream, audioBuffer.duration);
}
In recordAudio() I feed the stream into a MediaRecorder.
Recording the new stream now takes as long as the duration of the two Audiobuffers played in sequence...
Is there another way?
Thanks.