admin管理员组文章数量:1384229
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)
本文标签: nodejsDecoding ggwave from microphone using NodeJSStack Overflow
版权声明:本文标题:node.js - Decoding ggwave from microphone using NodeJS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744531257a2611050.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论