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

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

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