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

251
Views
Decode audio from ArrayBuffer received over web-socket in node

I am trying to send audio over web-sockets to node server where I want to store it in local file system. I am able to append the data received in a file, but it is not playable.

Most of the solution I found are for client side which use AudioContext.decodeAudiodata().

client

localAudioStreamRecorder = getMediaStreamRecording(
    localAudioStream,
    'audio/webm;codecs=opus',
    (data: ArrayBuffer) => {
      handleSendRecordingChunk(socket, {
        ...getIdentityPayload({ sessionId, userId, role }),
        data,
        streamType: 'audio',
      })
    }
)

server

const audioStreamPass = fs.createWriteStream(audioFilePath, { flags: 'a' });
const newData = async (socket, eventData, cb) => {
  const { sessionId } = eventData.body;

  if (eventData.body.streamType === 'audio') {
    // Need help here
    audioStreamPass.write(Buffer.from(new Uint8Array(eventData.body.data)));
  }
};

I just want to know, how can I decode this data to something which is playable. Thanks.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Try this on server:

const { Readable } = require('stream');

const audioStreamPass = fs.createWriteStream(audioFilePath, { flags: 'a' });
const newData = async (socket, eventData, cb) => {
  const { sessionId } = eventData.body;

  if (eventData.body.streamType === 'audio') {
    // Create the readable stream from buffer
    const readableStream = Readable.from(buffer);
    //Pipe the stream to the writeable
    readableStream.pipe(audioStreamPass)  
};
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!