Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating the same data as the Web API #80

Open
samueleastdev opened this issue Apr 3, 2021 · 0 comments
Open

Creating the same data as the Web API #80

samueleastdev opened this issue Apr 3, 2021 · 0 comments

Comments

@samueleastdev
Copy link

samueleastdev commented Apr 3, 2021

Hi All,

I am using the following code to generate my data from an audio file.

window.AudioContext = window.AudioContext || window.webkitAudioContext;
const audioContext = new AudioContext();

const drawAudio = url => {
    fetch(url)
        .then(response => response.arrayBuffer())
        .then(arrayBuffer => audioContext.decodeAudioData(arrayBuffer))
        .then(audioBuffer => filterData(audioBuffer));
};

const filterData = audioBuffer => {
    const rawData = audioBuffer.getChannelData(0);
    console.log(rawData);

};

drawAudio('https://983yqbz442.s3.amazonaws.com/andyc.mp3');

I am trying to get the same data from a local file with the Node js library like this.

const fs = require('fs');

const AudioContext = require('web-audio-api').AudioContext;

const audioContext = new AudioContext;

let resp = fs.readFileSync('./samples/andyc.mp3');

audioContext.decodeAudioData(resp, buffer => {
    
    console.log(buffer);

});

But I get 2 different results.

If you look at the web api it produces.

You can check the console.log here https://output.jsbin.com/haloneb/1

first 4 values of array

0: 0.0031128879636526108
1: 0.0052797021344304085
2: -0.000030517578125
3: 0.0016174810007214546

But the Node js one produces this first 4 values of array

0: 0
1: 0
2: 0
3: 0

Am i missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant