MTG / essentia.js

JavaScript library for music/audio analysis and processing powered by Essentia WebAssembly
https://essentia.upf.edu/essentiajs
GNU Affero General Public License v3.0
628 stars 41 forks source link

TypeError: Cannot convert "undefined" to unsigned int #81

Closed yashsavla9 closed 2 years ago

yashsavla9 commented 2 years ago

What is the issue about?

What part(s) of Essentia.js is involved?

Description

TypeError: Cannot convert "undefined" to unsigned int at Object.toWireType File essentia.js/dist/essentia-wasm.umd.js:19:2523624

Steps to reproduce / Code snippets / Screenshots

var esLib = require('essentia.js');
const essentia = new esLib.Essentia(esLib.EssentiaWASM);
console.log("essentia.js version: ", essentia.version);
let wav = require('node-wav');
let buffer = fs.readFileSync('./recordings/test.wav');
// Decode wav audio file using node-wav package
let audio = wav.decode(buffer);
// Convert audio data into VectorFloat type
const audioLeftChannelData = essentia.arrayToVector(audio.channelData[0]);
const audioRightChannelData = essentia.arrayToVector(audio.channelData[1]);

// Downmix stereo audio to mono
const audioDownMixed = essentia.MonoMixer(audioLeftChannelData, audioRightChannelData).audio;

// Create overlapping frames of the audio with given frameSize and hopSize
let frames = essentia.FrameGenerator(audioDownMixed,
    1024, // frameSize
    512 // hopSize
);

// Iterate through frames and compute danceability feature
for (var i=0; i < frames.size(); i++) {
    let danceability = essentia.Danceability(frames.get(i)).danceability;
    console.log("Danceability: ", danceability);
};
// delete frames from memmory
frames.delete();

// After the use of essentia.js
essentia.delete();

System info

Macos 11.3.1 Nodejs 14.0.0 essentia.js version: 2.1-beta6-dev

albincorreya commented 2 years ago

@yashsavla9 Thanks for reporting, found out to be an error in the example code. The error happens because FrameGenerator expects the audio data to be as JS Float32TypedArray (see here).

Have a look at the updated node.js examples.

yashsavla9 commented 2 years ago

@yashsavla9 Thanks for reporting, found out to be an error in the example code. The error happens because FrameGenerator expects the audio data to be as JS Float32TypedArray (see here).

Have a look at the updated node.js examples.

Thanks @albincorreya