我目前正在制作一个Discord机器人,拥有“用户录音”功能。我在VC中测试它时注意到,13分钟后输出的.pcm
文件大小达到了约20GB。
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)
}
})
有没有可能将大小约为20GB的.pcm文件压缩至5-10MB?这似乎很奇怪,因为每个来自Discord.js的Buffer都达到了惊人的4000字节(4KB)(这也导致我的磁盘使用率达到100%,写入速度为60MB / s)。