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

110
Vistas
Stream IncomingMessage audio data as it's coming in?

I'm trying to use the speaker module to stream audio from a web request, returning an unending stream of audio data in Buffer form to my speakers. So I'm trying to use the res.on('data', . . .) event to do something with the chunks, but I just can't seem to figure out what to do.

I've thought of something along those lines:

const https = require('https');
const Speaker = require('speaker');

var speaker = new Speaker({
    channels: 2,
    bitDepth: 16,
    sampleRate: 44100
});

https.get('<url>', (res) => {
    res.on('data', chunk => {
        /* Somehow convert the Buffer to PCM audio data and 
         * give it to the speaker
         */
    });
});

I've been googling and trying for 2 days, and figured I'd ask here now.

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

The res object you get in callback is a stream, and the speaker instance you created is a writable stream (from docs) , so you can just simply pipe them together. Some thing like this :

// Not tested code.
const https = require('https');
const Speaker = require('speaker');

let speaker = new Speaker({
    channels: 2,
    bitDepth: 16,
    sampleRate: 44100
});

https.get('<url>', (res) => {
    res.pipe(speaker);
});
about 4 years ago · Santiago Gelvez 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