Getting amplitude value from pcm stream

Hey guys. I am trying to get an amplitude value from my live pcm stream but very stuck. Code below
3 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Joopst
Joopst2y ago
connection.receiver.speaking.on('start', userId => {
if (!connection.receiver.subscriptions.has(userId)){
const opusStream = connection.receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.Manual,
},
});

//decode opus stream to pcm
const decoder = new prism.opus.Decoder({
rate: 48000,
channels: 2,
frameSize: 960,
});

const pcmStream = opusStream.pipe(decoder);

pcmStream.on('data', (chunk) => {
console.log(calcrms_db(chunk));
});
}
});
connection.receiver.speaking.on('start', userId => {
if (!connection.receiver.subscriptions.has(userId)){
const opusStream = connection.receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.Manual,
},
});

//decode opus stream to pcm
const decoder = new prism.opus.Decoder({
rate: 48000,
channels: 2,
frameSize: 960,
});

const pcmStream = opusStream.pipe(decoder);

pcmStream.on('data', (chunk) => {
console.log(calcrms_db(chunk));
});
}
});
Outputs something like this
23.079337219775482
23.079337219775482
40.7620869525427
44.53559919238725
44.06395586687512
43.951678273428044
44.03326819268514
44.6989977410556
44.47046882648833
44.447959109342385
44.66329382799398
44.72887957632754
44.67471010522133
43.98916272199328
44.462545011909796
23.079337219775482
23.079337219775482
23.079337219775482
-Infinity
-Infinity
-Infinity
-Infinity
-Infinity
-Infinity
-Infinity
-Infinity
-Infinity
-Infinity
23.079337219775482
23.079337219775482
40.7620869525427
44.53559919238725
44.06395586687512
43.951678273428044
44.03326819268514
44.6989977410556
44.47046882648833
44.447959109342385
44.66329382799398
44.72887957632754
44.67471010522133
43.98916272199328
44.462545011909796
23.079337219775482
23.079337219775482
23.079337219775482
-Infinity
-Infinity
-Infinity
-Infinity
-Infinity
-Infinity
-Infinity
-Infinity
-Infinity
-Infinity
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View