【发布时间】:2020-08-25 10:06:39
【问题描述】:
我目前正在制作一个具有“用户记录”功能的 Discord 机器人,我在 VC 中对其进行测试,并注意到输出 .pcm 文件在 13 分钟后约为 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)
}
})
有什么办法可以将.pcm 文件从.. 压缩到.. 我不知道,20GB 到 5-10 MB?这似乎很奇怪,因为来自 Discord.js 的每个 Buffer 都高达 4000 字节 (4KB)
(这也使我的磁盘上限为 100%,写入速度为 60MB/s)
【问题讨论】:
-
这能回答你的问题吗? stackoverflow.com/a/43829712/13176517
-
@Syntle 它没有将文件放入 zip/压缩文件夹中。它更多的是在接收时压缩数据,并将压缩后的数据放入文件本身。尽管如此,该链接确实帮助我更深入地研究相同的模块,并提供了帮助。
标签: javascript node.js discord.js