Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

597
Vistas
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?

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda