Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

348
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda