I'm currently making a Discord bot that has a "User Recording" feature, and I was in a VC testing it, and kind of noticed that the output .pcm
file was ~20GB after 13 minutes.
this.voiceChannel = await message.member.voice.channel.join()
this.reciever = this.voiceChannel.receiver
this.voiceChannel.on('debug', (debug) => {
let packet = JSON.parse(debug.slice(8))
console.log(packet.op)
if(!packet.d || packet.d && packet.d.speaking != 1) return;
let user = this.client.users.resolve(packet.d.user_id)
if(packet.d.speaking) {
let userStream = this.reciever.createStream(user, {mode: 'pcm', end: 'manual'})
let writeStream = require('fs').createWriteStream('./recording.pcm', {})
this.us = userStream
this.ws = writeStream
this.us.on("data", (chunk) =>{
console.log(chunk)
this.us.pipe(this.ws)
})
this.ws.on("pipe", console.log)
}
})
Is there any way possible to compress the .pcm
file from.. I dunno, 20GB down to 5-10 MB? This seems odd as each Buffer
that comes from Discord.js is a whopping 4000 bytes (4KB)
(This also had my Disk capped out at 100% and writing at 60MB/s)