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

157
Visualizações
How can I concatenate streaming audio?

I have a webapp that records audio from the user's microphone. It sends the data to the server. The relevant code looks like this:

class Recorder {
  // ...
  setRecorder() {
    this.recorder = new RecordRTC(this.stream, {
      type: 'audio',
      mimeType: this.mimeType,
      recorderType: StereoAudioRecorder,
      timeSlice: 2000, // Interval to send recorded data
      ondataavailable: async blob => { // send the data to the server
        let seq = this.seq++
        let data = await blob.arrayBuffer()
        if(this.socket.connected) {
          try {
            this.socket.emit('audio', {
              id: this.id,
              seq,
              mimeType: this.mimeType,
              data
            })
          } catch (e) {
            console.error('caught an error', e)
            this.stopRecording()
          }
        }
      },
      sampleRate: 44100,
      desiredSampleRate: 44100,
      numberOfAudioChannels: 1
    })
  }
}

On the server side (Express.js), I send the data as it's received to any interested clients. Here's the relevant code:

app.get('/play', (req, res, next) => {
    try {
      let id = req.query.id
      let mimeType
      if(!recordings[id]) {
        // ...
      }
      emitter // the EventEmitter that's handling this
        .on(`audio ${id}`, data => {
          if(!mimeType) {
            mimeType = data.mimeType
            res.writeHead(200, {'Content-Type': mimeType})
          }
          res.write(data.data)
        })
        .on(`close ${id}`, () => {
          console.debug({type:'audio close', id})
          res.end()
        })
    } catch (e) {
      next(e)
    }
  })

The issue is that each chunk I get from the client appears to be a complete WAV file, and concatenating such files doesn't work. When trying to play such a file, you only hear the first chunk.

I've been searching for hours for information about how to concatenate the input files (or any other method that would result in a stream that can be listened to). It seems that there's very little information out there about this topic.

I've been looking in particular at ffmpeg, but despite its purported ability to concatenate files, it expects the files to all be given on the command line. I'm receiving streaming data, so I can't practically list filenames in advance; I would have to send multiple files in on stdin, but that doesn't work.

Can anyone point me in the right direction? I would think that concatenating audio files would be a common need, but I can't find any tools that are capable of doing it without knowing in advance all of the data to be processed. Or am I barking up the wrong tree here?

about 4 years ago · Juan Pablo Isaza
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