【问题标题】:Discord.JS voice Recording and Data CompressionDiscord.JS 录音和数据压缩
【发布时间】: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


【解决方案1】:

我将回答我自己的问题,但我相信我知道我做错了什么。

this.us.on("data", (chunk) =>{
    console.log(chunk)
    this.us.pipe(this.ws)
})

我在那个部分是不正确的,因为每当收到数据时我都会发送数据,不是一次,而是两次。我还使用了zlib 模块(https://npmjs.org/package/zlib),它对数据/语音压缩的帮助更大。

this.us.on("data", (chunk) => {
    let slowBuf = this.zlib.deflate(chunk, (er, res) => {
        console.log(res)
        this.ws.write(res)
    })
})

这很神奇,现在每 2 分钟左右的测试写入 600KB 的数据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多