monstercat / bpm.js

Pure js bpm detection on raw audio streams
53 stars 11 forks source link

Get it work with sox-stream #5

Open roccomuso opened 7 years ago

roccomuso commented 7 years ago

It would be cool if we find a way to make it work with sox-stream. Any hint?

I wasn't able to get it working using this code:

var createBpmSink = require('../')
var sox = require('sox-stream')
var fs  = require('fs')
var src = fs.createReadStream('hellberg.mp3')

var transcode = sox({
        input: {
        type: 'mp3',
                encoding: 'float',
        rate: 44100,
        channels: 2
        },
    output: {
        type: 'mp3'
    }
})

var bpmSink = createBpmSink()
src.pipe(transcode).pipe(bpmSink)

bpmSink.on("bpm", function(bpm){
   console.log(Math.floor(bpm))
   createBpmSink()
});

I got an issue: RangeError: Index out of range

Changing the input channel i have this error on sox instead:

Error: sox WARN formats: can't set 1 channels; using 2

jb55 commented 7 years ago

The only thing I can think of is attaching to the on('data') event and making sure that the data coming out of that library is the same as the original example.

roccomuso commented 6 years ago

what do you mean?