How can i listen to the microphone and eventually decode any detected ggwave messages and print them to the console using nodejs?
I already tried this code:
const recorder = require('node-record-lpcm16');
const ggwave = require('ggwave');
ggwave().then(function(ggwave) {
const parameters = ggwave.getDefaultParameters();
let instance = ggwave.init(parameters);
const audioStream = recorder.record({
sampleRate: 48000,
}).stream().on('error', err => {
console.error('recorder threw an error:', err);
});
let audioBuffer = Buffer.alloc(0);
audioStream.on('data', (chunk) => {
audioBuffer = Buffer.concat([audioBuffer, chunk]);
const messages = ggwave.decode(instance, audioBuffer);
if(messages.length > 0) {
console.log('Received message:', messages);
audioBuffer = Buffer.alloc(0);
}
});
});
process.on('SIGINT', () => {
console.log('Registrazione interrotta');
process.exit();
});
But it just spams this to the console and it doesn't decode anything if a play a ggwave message from a speaker next to the microphone:
Receiving sound data ...
Received end marker. Frames left = 1804, recorded = 2
Analyzing captured data ..
Failed to capture sound data. Please try again (length = 0)
Receiving sound data ...
Received end marker. Frames left = 1804, recorded = 2
Analyzing captured data ..
Failed to capture sound data. Please try again (length = 0)
Receiving sound data ...
Received end marker. Frames left = 1804, recorded = 2
Analyzing captured data ..
Failed to capture sound data. Please try again (length = 0)
Receiving sound data ...
Received end marker. Frames left = 1804, recorded = 2
Analyzing captured data ..
Failed to capture sound data. Please try again (length = 0)