Git Product home page Git Product logo

aubiojs's Introduction

aubiojs npm-badge build-badge

Online Demo

aubiojs is a real-time audio processing library based on aubio, now including:

  • pitch detection
  • tempo detection

Usage

Web

<script src="https://unpkg.com/aubiojs"></script>
<script>
  aubio().then(({ Tempo }) => {
    const tempo = new Tempo(bufferSize, hopSize, sampleRate);
    tempo.do(audioBuffer);
    const bpm = tempo.getBpm();
  });
</script>

Node

npm i aubiojs
import aubio from "aubiojs";

const { Tempo } = await aubio();
const tempo = new Tempo(bufferSize, hopSize, sampleRate);
tempo.do(audioBuffer);
const bpm = tempo.getBpm();

Build

This project uses emscripten to compile aubio, make sure you have installed.

npm run build

aubiojs's People

Contributors

andreasjansson avatar ebraminio avatar novikov-alexander avatar qiuxiang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aubiojs's Issues

WASM instead asm.js?

Hi there, as far as I know WASM is the new alternative to asm.js, not sure about toolchain and compile difference between the two I wonder how aubio's wasm build would look like, perhaps faster and smaller binaries? Just wanted to share my thoughts :)

Attack detection

Hi, @qiuxiang!
Thank you very much for such a good library.

I'm qurious can it detect consonants and sound attacks?
I would like to make a hand synchronization trainer for guitar players and would like to check the moment of time when a plector passes the string.

Maybe you've seen Melodyne application. It can distinguish between vowels and consonants in edit mode.
Maybe Aubio has that feature? I would be happy to port it from Aubio to Aubiojs if needed.

Kind regards,
Alexander

Dependency was not found

I cannot build my NUXT project. I get the following error:

Failed to compile with 1 errors
This dependency was not found:
* fs in ./node_modules/aubiojs/build/aubio.js

aubio.Pitch.do returns 0

Right now I'm trying to get your tuner to run in NUXT. However when I run

self.pitchDetector.do(
    event.inputBuffer.getChannelData(0)
)

just like in the tuner project, it always returns zero.

Types are incorrect

When I do Aubio().then TypeScript tells me:

This expression is not callable
typeof Aubio has no call signatures

Pitch shifting

Hello @qiuxiang! Thank you for this library. I'm using it for pitch detection in my browser karaoke game and it works great. I thought of adding transposition so I can lower particularly high pitched songs into player's vocal range. I know there's a pitchshift effect in aubio, but it's not present i this wrapper. I have no experience in WASM so I don't think I will be able to add it myself. Is there any plans on updating this repo with more features from aubio?

Pitch.html example not working on firefox, but I found a soultion :)

Hi! Love the library.

I just noticed that the pitch.html example doesnt work in firefox and I found out why.

The problem is that canvas is put over the audi controls so they are impossible to click.
A simple fix would be to add to z-index to canvas css like that:

        canvas {
            position: absolute;
            top: 0;
            z-index: -1;
        }

problem with node-gyp

Hi i get the following errors :

It might be because I'm running node 20 ?

jonahfox@Jonahs-MacBook-Pro aubiojs-main % npm i aubio
npm ERR! code 1
npm ERR! path /Users/jonahfox/Downloads/aubiojs-main/node_modules/ref
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! CXX(target) Release/obj.target/binding/src/binding.o
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | darwin | arm64
npm ERR! gyp info find Python using Python version 3.11.6 found at "/opt/homebrew/opt/[email protected]/bin/python3.11"
npm ERR! gyp info spawn /opt/homebrew/opt/[email protected]/bin/python3.11
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args '/Users/jonahfox/Library/pnpm/nodejs/20.11.1/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args 'binding.gyp',
npm ERR! gyp info spawn args '-f',
npm ERR! gyp info spawn args 'make',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/Users/jonahfox/Downloads/aubiojs-main/node_modules/ref/build/config.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/Users/jonahfox/Library/pnpm/nodejs/20.11.1/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/Users/jonahfox/Library/Caches/node-gyp/20.11.1/include/node/common.gypi',
npm ERR! gyp info spawn args '-Dlibrary=shared_library',
npm ERR! gyp info spawn args '-Dvisibility=default',
npm ERR! gyp info spawn args '-Dnode_root_dir=/Users/jonahfox/Library/Caches/node-gyp/20.11.1',
npm ERR! gyp info spawn args '-Dnode_gyp_dir=/Users/jonahfox/Library/pnpm/nodejs/20.11.1/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args '-Dnode_lib_file=/Users/jonahfox/Library/Caches/node-gyp/20.11.1/<(target_arch)/node.lib',
npm ERR! gyp info spawn args '-Dmodule_root_dir=/Users/jonahfox/Downloads/aubiojs-main/node_modules/ref',
npm ERR! gyp info spawn args '-Dnode_engine=v8',
npm ERR! gyp info spawn args '--depth=.',
npm ERR! gyp info spawn args '--no-parallel',
npm ERR! gyp info spawn args '--generator-output',
npm ERR! gyp info spawn args 'build',
npm ERR! gyp info spawn args '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! ../src/binding.cc:222:43: error: too few arguments to function call, single argument 'isolate' was not specified
npm ERR! bool persistent = info[3]->BooleanValue();
npm ERR! ~~~~~~~~~~~~~~~~~~~~~ ^
npm ERR! /Users/jonahfox/Library/Caches/node-gyp/20.11.1/include/node/v8-value.h:418:8: note: 'BooleanValue' declared here
npm ERR! bool BooleanValue(Isolate* isolate) const;
npm ERR! ^
npm ERR! ../src/binding.cc:253:38: error: too few arguments to function call, single argument 'context' was not specified
npm ERR! size_t size = info[2]->Uint32Value();
npm ERR! ~~~~~~~~~~~~~~~~~~~~ ^
npm ERR! /Users/jonahfox/Library/Caches/node-gyp/20.11.1/include/node/v8-value.h:426:41: note: 'Uint32Value' declared here
npm ERR! V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
npm ERR! ^
npm ERR! ../src/binding.cc:253:10: error: no viable conversion from 'Maybe<uint32_t>' (aka 'Maybe') to 'size_t' (aka 'unsigned long')
npm ERR! size_t size = info[2]->Uint32Value();
npm ERR! ^ ~~~~~~~~~~~~~~~~~~~~~~
npm ERR! ../src/binding.cc:360:23: error: no matching constructor for initialization of 'String::Utf8Value'
npm ERR! String::Utf8Value _str(in);

Trying to use aubiojs to do pitch detection

(I put this in your tuner project by mistake)

In index.html

<script src="https://unpkg.com/aubiojs"></script>

I have this in ts (ignore the name, this is not a worklet, it starts one , now that scriptnode is deprecated), using your .d.ts file

class PitchDetectWorklet {
    audioContext!: AudioContext;
    running: boolean = false;
    pitchWorklet!: AudioWorkletNode;
    cb: (note: number, freq: number) => void;
    options: PitchDetectOptions;
    stream!: MediaStream;
    aupitch!: Pitch;  <<<<==
    au!: Aubio; <<<< ====

and then

        this.au = await aubio();
        this.aupitch = new this.au.Pitch('default', 128 * (this.options.buffersize || 10), 1, this.audioContext.sampleRate );

this all works fine.

But then when I get a buffer from my worklet I do

            var buff = ev.data.buff;
            var freq = that.aupitch.do(buff);

I always get

 Uncaught RuntimeError: null function or function signature mismatch
at 00068a0a:0x15c89
at 00068a0a:0xe02b
at Pitch$do [as do] (eval at Gb (aubiojs:38:242), <anonymous>:9:10)
at MessagePort.pitchWorklet.port.onmessage (worklet_caller.js:34:51)
I think I have copied everything from your tuner demo. I have run out of ideas

fails edge and chrome

chrome gives better debug stack

    local.get $var1
    i32.load offset=8
    local.get $var1
    i32.load offset=4
    local.get $var1
    i32.load offset=12
    i32.load offset=40
    call_indirect (param i32 i32 i32) <<<<<===== 15c89
    local.get $var1
    i32.load offset=8
    local.get $var1
    i32.load offset=12
    f32.load offset=52
    call $func92
    i32.const 1
    i32.eq
    if
      local.get $var1
      i32.load offset=4
      i32.load offset=4
      f32.const 0.0

tempo.do() and onset.do() return a single value only instead of an array

I believe that in the underlying Aubio implementation, tempo.do() and onset.do() return vectors containing all beat and onset event locations within the last processed buffer.

However, the methods exposed in JS return only a single value:

This means that with tempo, we can't get the estimated location of each beat, and with onset we can only get the last onset event.

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.