Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

342
Visualizações
How can I convert opus packets to mp3/wav

I created a discord bot with discord.js v13, I get trouble with converting the opus packet to other file types, even the discord.js official examples haven't updated for discord.js v13, I got no idea to deal with it, here is part of my code

async function record(interaction, opts = {}) {
    //get voice connection, if there isn't one, create one
    let connection = getVoiceConnection(interaction.guildId);
    if (!connection) {
        if (!interaction.member.voice.channel) return false;
        connection = joinVoice(interaction.member.voice.channel, interaction)
    }
    const memberId = interaction.member.id;

    //create the stream
    const stream = connection.receiver.subscribe(memberId, {
        end: {
            behavior: EndBehaviorType.Manual
        }
    });
    //create the file stream
    const writableStream = fs.createWriteStream(`${opts.filename || interaction.guild.name}.${opts.format || 'opus'}`);
    console.log('Created the streams, started recording');
    //todo: set the stream into client and stop it in another function
    return setTimeout(() => {
        console.log('Creating the decoder')
        let decoder = new prism.opus.Decoder();
        console.log('Created');

        stream.destroy();
        console.log('Stopped recording and saving the stream');
        stream
        .pipe(writableStream)
        stream.on('close', () => {
            console.log('Data Stream closed')
        });
        stream.on('error', (e) => {
            console.error(e)
        });
    }, 5000);
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try setting frameSize, channels and rate for the Decoder:

const opusDecoder = new prism.opus.Decoder({
  frameSize: 960,
  channels: 2,
  rate: 48000,
})

Also not sure if it is intended, but you seem to destroy the stream just before you pipe it into writable stream.

Here is my example that gives stereo 48kHz signed 16-bit PCM stream:

const writeStream = fs.createWriteStream('samples/output.pcm')
const listenStream = connection.receiver.subscribe(userId)

const opusDecoder = new prism.opus.Decoder({
  frameSize: 960,
  channels: 2,
  rate: 48000,
})

listenStream.pipe(opusDecoder).pipe(writeStream)

You can then use Audacity to play the PCM file. Use File -> Import -> Raw Data...

how to import in Audacity

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda