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

106
Visualizações
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 Respostas
Responde à pergunta

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 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