0

I am trying to record and edit my voice in javascript. Specifically, I am trying to record it in an array that looks like this for my boss [0,102, 301,...] where the values are samples of my voice.

When I record my voice in javascript, I get a Blob type. Is there any way to transform a Blob into the [x, y, z,...] array? Or how is javascript signal processing normally completed?

This is code from this medium article that is how we are doing things. I just can't share the actual company code.

const recordAudio = () =>
    new Promise(async resolve => {
        const stream = await navigator.mediaDevices.getUserMedia({ audio:true});
        const mediaRecorder = new MediaRecorder(stream);
        const audioChunks = [];

        mediaRecorder.addEventListener("dataavailable", event => {
            audioChunks.push(event.data);
        });

        const start = () => mediaRecorder.start();

        const stop = () =>
            new Promise(resolve => {
                mediaRecorder.addEventListener("stop", () => {
                    console.log(audioChunks);
                    console.log(audioChunks)
                    const audioBlob = new Blob (audioChunks);
                    const audioURL = URL.createObjectURL(audioBlob);
                    const audio = new Audio(audioURL);
                    const play = () => audio.play();
                    resolve({ audioBlob, audioURL, play });
                });

                mediaRecorder.stop();
            });

            resolve({ start, stop});
        });

    const sleep = time => new Promise(resolve => setTimeout(resolve, time));

    const handleAction = async () => {
        const recorder = await recordAudio();
        const actionButton = document.getElementById('action');
        actionButton.disabled = true;
        recorder.start();
        await sleep(3000);
        const audio = await recorder.stop();
        audio.play();
        await sleep(3000);
        actionButton.disabled = false;

    }
  • It's completely unclear how `[0,102, 301,...]` "*are samples of your voice*". What is it that your boss wants? – Bergi Jul 11 '20 at 20:57
  • Btw, [never pass an `async function` as the executor to `new Promise`](https://stackoverflow.com/q/43036229/1048572)! Make `recordAudio` an `async` function itself, and drop the `new Promise` around its body. – Bergi Jul 11 '20 at 20:58

0 Answers0