1
votes

I'm currently streaming my microphone from c++ with an standard socket. Now i want to listen to this stream from the web. I have tried accessing the stream from the audio tag directly, but this didn't work.

I also tried to set the Content Type to audio/wav, but this also didn't work.

I have tried to write to an file and access it directly from the audio element, but it wasnt adding the new written parts to the audio element. Also it started from the beginning of the audio and i read that it had a high delay.

Is there a way to stream audio with very low latency?

I have thought on making a get request every 50ms and adding the new data to the audio or recording 50ms of audio and changing the src of the audio at the end of the last clip.

1

1 Answers

0
votes

Streaming audio buffers through a WebSocket and then trying to play it with an <audio> element is not the way to go.

The way to stream audio to your browser with low latency is to use WebRTC.

WebRTC is built in the browser to enable peer-to-peer real-time communications.

That said, you can use some WebRTC implementation in C++ like libwebrtc or Gstreamer to stream your mic input, and then use the native JavaScript API on your browser to receive the audio stream and place it in the srcObject property of an <audio> element to listen in the browser.