-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Trying to do live analysis on mic #4
Comments
Actually, this code makes my callbacks get called just once, above quits before it gets to them: const fs = require('fs')
const { MusicBeatDetector, MusicBeatScheduler, MusicGraph } = require('music-beat-detector')
const { AudioIO, SampleFormat16Bit, getDevices } = require('naudiodon')
console.log(getDevices())
const musicGraph = new MusicGraph()
const ws = fs.createWriteStream('rawAudio.raw')
const ai = new AudioIO({
inOptions: {
channelCount: 2,
sampleFormat: SampleFormat16Bit,
sampleRate: 44100,
deviceId: -1 // Use -1 or omit the deviceId to select the default device
}
})
const musicBeatScheduler = new MusicBeatScheduler(pos => {
console.log(`peak at ${pos}ms`) // your music effect goes here
})
const musicBeatDetector = new MusicBeatDetector({
plotter: musicGraph.getPlotter(),
scheduler: musicBeatScheduler.getScheduler()
})
ai
.pipe(musicBeatDetector.getAnalyzer())
.on('peak-detected', (pos, bpm) => console.log(`peak-detected at ${pos}ms, detected bpm ${bpm}`))
.on('end', () => {
fs.writeFileSync('graph.svg', musicGraph.getSVG())
console.log('end')
})
.pipe(ws)
ai.start()
musicBeatScheduler.start() changing the order of the |
As a sidenote, this records a raw file fine: const fs = require('fs')
const { AudioIO, SampleFormat16Bit } = require('naudiodon')
const ws = fs.createWriteStream('rawAudio.raw')
const ai = new AudioIO({
inOptions: {
channelCount: 2,
sampleFormat: SampleFormat16Bit,
sampleRate: 44100,
deviceId: -1 // Use -1 or omit the deviceId to select the default device
}
})
ai.pipe(ws)
ai.start() |
I thought maybe I should wait for the mic to be const fs = require('fs')
const { AudioIO, SampleFormat16Bit } = require('naudiodon')
const { MusicBeatDetector, MusicBeatScheduler, MusicGraph } = require('music-beat-detector')
const musicGraph = new MusicGraph()
const musicBeatScheduler = new MusicBeatScheduler(pos => {
console.log(`peak at ${pos}ms`) // your music effect goes here
})
const musicBeatDetector = new MusicBeatDetector({
plotter: musicGraph.getPlotter(),
scheduler: musicBeatScheduler.getScheduler()
})
const ws = fs.createWriteStream('rawAudio.raw')
const ai = new AudioIO({
inOptions: {
channelCount: 2,
sampleFormat: SampleFormat16Bit,
sampleRate: 44100,
deviceId: -1 // Use -1 or omit the deviceId to select the default device
}
})
ai
.pipe(musicBeatDetector.getAnalyzer())
.on('peak-detected', (pos, bpm) => console.log(`peak-detected at ${pos}ms, detected bpm ${bpm}`))
.pipe(ws)
.on('ready', () => musicBeatScheduler.start())
.on('end', () => {
fs.writeFileSync('graph.svg', musicGraph.getSVG())
console.log('end')
})
ai.start() |
Also, if you know of another way to beat-analyze mic input, I'm not stuck on this method. Basically, I am trying to accomplish "fire my callback when a beat is detected from mic". If you follow this issue, I tried |
Solution here: konsumer/tplink-lightbulb#35 (comment) |
Hi, I am attempting to get live analysis on mic-input. I am running this code:
When I run it on a mac, I get an audio-file with a single beat, and an SVG with same data:
I get this error after a single beat (seems to be calling my callbacks each once):
Any hints what I am doing wrong?
The text was updated successfully, but these errors were encountered: