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

156
Views
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
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!