Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!