I call getChannelData and perform some actions and remove values from the Float32Array.
How can I encode this data back into a form that can be saved?
const blob = new Blob(this.chunks, { type: audioType });
// generate audio url from blob
const audioContext = new (window.AudioContext ||
window.webkitAudioContext)();
// reading the file with file reader using a method that uses read file in a promise
ReadFile(blob).then((arrayBuffer) => {
audioContext.decodeAudioData(arrayBuffer).then((audioBuffer) => {
const audioBufferSourceNode = audioContext.createBufferSource();
const numChannels = audioBuffer.numberOfChannels;
const leftChannelArray = audioBuffer.getChannelData(0);
// audioBufferSourceNode.buffer = leftChannelArray;
let rightChannelArray;
if (numChannels>1) {
rightChannelArray = audioBuffer.getChannelData(1);
}
const monoChannelTrimmed = trimSilence(leftChannelArray, rightChannelArray) //we look on both sides for silence, we delete the array values and merge the channels
//Now i want to turn monoChannelTrimmed into a usable audio file
Turning this channel back into something that is usable is what I have been struggling with. I have tried some suggestions from other questions in this field such as Converting Float32Array to Uint8Array while Preserving IEEE 754 Representation But nothing has worked if anyone has suggestions I would be very eager to try them.
You can probably use the MediaStream Recording API.
Here is a small snippet of how to use it, mostly taken from the example, but modified to use a WebAudio
OscillatorNode
as the source. You can replace that with anAudioBufferSourceNode
that is playing out yourmonoTrimmedChannel
I tested this locally and it creates a test.webm file that plays a nice oscillator tone as expected. You'll probably want to tweak some things.