Git Product home page Git Product logo

Comments (12)

catalli avatar catalli commented on May 28, 2024

Until this is fixed, are there any workarounds to implement meyda completely serverside?

from meyda.

jakubfiala avatar jakubfiala commented on May 28, 2024

@Number-42 yes, I've done it, it's a bit hacky but it's possible with v2.0. Here's how to do it so you can also use spectral features:

  • you first include the meyda and jsfft stuff separately
var jsfft = require("./node_modules/meyda/node_modules/jsfft/")
var complex_array = require("./node_modules/meyda/node_modules/jsfft/lib/complex_array.js")
var extractors = require("./node_modules/meyda/dist/node/featureExtractors.js")
var utils = require("./utils.js")
var meyda_utils = require("meyda").utils
  • then you need to use jsfft to extract your amplitude spectrum
function getSpectrum(_d) {

    var windowedSignal = meyda_utils.applyWindow(_d, 'hanning')
    // create complexarray to hold the spectrum
    var data = new complex_array.ComplexArray(_d.length)
    // map time domain
    data.map(function(value, i, n) {
        value.real = windowedSignal[i]
    });
    // transform
    var spec = data.FFT();
    // assign to meyda
    var ampSpectrum = new Float32Array(_d.length/2)
    for (var i = 0; i < _d.length/2; i++) {
        ampSpectrum[i] = Math.sqrt(Math.pow(spec.real[i],2) + Math.pow(spec.imag[i],2))
    }

    return ampSpectrum
}
  • then, you can extract features
var mfccs = extractors.mfcc({
    ampSpectrum: getSpectrum(signal),
    bufferSize: bufSize,
    sampleRate: 44100
});

(obviously, signal.length === bufSize)

Good news is, v3.0.0 which will have an easy offline API and even a CLI for wav files, is almost finished ✨

from meyda.

catalli avatar catalli commented on May 28, 2024

Thank you. Any callback functions get an array of feature values extracted in the order their names were fed into meyda.start() as arguments, right?

from meyda.

jakubfiala avatar jakubfiala commented on May 28, 2024

@hughrawlinson correct me if I'm wrong, but I think in v2.0.0 the callback receives an object, with feature names as keys. It is in the same order though.

Of course, meyda.start() won't run without Web Audio.

from meyda.

catalli avatar catalli commented on May 28, 2024

I'm assuming that callbacks are defined inside mfccs. Does extraction automatically start, or does mfccs.get() have to be run first? I see that get() returns output once (the example in the documentation has it used to define a single variable), which I assume to contain all feature values extracted throughout the input file. Is the output a JSON containing all feature extracted feature sets in chronological order, or an array of arrays?

Does this workaround work with time-domain features?

What is _d supposed to be, and how can that property be extracted from a local file with a known path? Is the buffer size defined as a number of samples or bytes?

from meyda.

jakubfiala avatar jakubfiala commented on May 28, 2024

Not sure what you mean there – this workaround works if you have a chunk of audio data (should be a Float32Array btw), and you want to extract a feature (could be spectral or temporal) on that one chunk, once. The get and start methods are not applicable here, we will have something like that in v3.

Because there's no Web Audio in node.js (I'm assuming that's what you're using), the internal ScriptProcessor doesn't run, and therefore Meyda can't analyze an audio stream on its own. You have to create that functionality yourself, by splitting your audio into bufferSize-length chunks, and feeding each chunk into the extractor function – in the example above, extractors.mfcc().

For temporal features, you pass signal: your_signal instead of ampSpectrum.

The output in this case is either a Number or Array, depending on the feature. See wiki for info on which features are represented by a single value and which by an array (I know, the wiki could be more descriptive).

_d is the time-domain signal you pass to our getSpectrum function, which then returns the amplitude spectrum of that signal.

Let's keep this thread for discussion on the issue, I'm happy to help out if you have further questions though. Feel free to tweet at @fiala__ or send an email to the address on my profile.

Thanks,

jakub

from meyda.

hughrawlinson avatar hughrawlinson commented on May 28, 2024

Yes, all of what Jakub said πŸ˜„

I was nearly done writing a big long comment to cover all of that, and then Jakub's comment covered it all, and more! πŸ˜„

from meyda.

jakubfiala avatar jakubfiala commented on May 28, 2024

It's the Meyda vibe! πŸ’ƒ

from meyda.

catalli avatar catalli commented on May 28, 2024

Sorry to have been a bother.

Also, I assume it's been tried, but node-web-audio-api seems like it'd help with the offline implementation.

from meyda.

jakubfiala avatar jakubfiala commented on May 28, 2024

No problem, you haven't! As I said, if you need help, feel free to get in touch.

RE: node-web-audio, yes, it certainly would, SΓ©bastien is doing a great job on that one. However, only a handful of nodes are implemented, and I think live audio in node is still not widespread enough.
Then again, SPN is already implemented, so theoretically, Meyda should already run on it!

from meyda.

jakubfiala avatar jakubfiala commented on May 28, 2024

Actually, it probably won't run on it, but a tiny code modification like adding require('web-audio-api'). where the SPN is created should do the job

from meyda.

jakubfiala avatar jakubfiala commented on May 28, 2024

I've put the above hack for v2 in this gist if anyone finds it more convenient.

from meyda.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.