1

Trying to record a file and as it is being recorded I want to post it to a server using fetch(). Is there a library that records sound and that pipes it continously to a file (or api)?

1 Answers1

1

You're asking several questions at once. Let's break it into pieces.

How can I capture sound?

I assume you want to record sound from a microphone or other audio input device. To do that, you need to capture it with the MediaDevices API. Specifically, you want to call getUserMedia() to get a MediaStream instance from a particular recording device.

https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia

How can I record a MediaStream?

You can use the MediaRecorder to take a MediaStream, run it through a codec, mux it into a particular format, such as WebM, and output a Blob.

https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder

How can I get MediaStream data as it's being recorded?

When you call mediaRecorder.start(), be sure to call it with the timeslice parameter. Something like mediaRecorder.start(3000) will cause it to emit a dataavailable event roughly every 3 seconds. You can then take this data and ship it off to wherever.

How do I make an HTTP request with a streaming request body?

You can't. At least, not today. See also: Fetch with ReadableStream as Request Body

What you can do is send data via Web Sockets. You can also make HTTP requests for each chunk.

Brad
  • 159,648
  • 54
  • 349
  • 530