This project has moved and is read-only. For the latest updates, please go here.

Preparing audio for using HTML 5 audio element

Oct 15, 2015 at 11:25 AM

I'm currently having 2 WPF applications.
The first one reads data from my asio soundcard, does some adjustments (volume, mixing, ...) and in the end sends a 16bit 44.1kHz PCM stream over the network if a client is connected.
The second application is this client. It gets the stream over TCP and just plays the data coming in.

This works pretty well and it's very fast.

Now I want to replace my 2nd WPF application with a HTML site. What is the best way to do this?

As I don't use any protocol, do I need to wrap my PCM stream into something?
I know that different browsers need different audio formats to be able to play these.

It is important to keep my almost zero delay and the good audio quality I have right now.

For now this solution has to work in a LAN, so the network shouldn't be a bottleneck.

Kind regards,
Oct 22, 2015 at 9:36 AM

In the last days I played around trying to get a working solution. My first attempt was to run an Icecast server and to send my audio data to this server, so Icecast can do all the HTTP stuff. I tested this before with an Icecast source client called butt. In Chrome I got a delay of about 4 seconds. Not very satisfying. I'm sure I didn't configure the optimal settings though.

This has to go faster, so I tried to get it working without Icecast and butt. I found this on Stackoverflow and also this article from Mark. At the bottom of the second article is explained how to use external encoders.

I've written my own HTTP server and used lame.exe for mp3 and oggenc2.exe for ogg.
My results in regard to delay:
  • Chrome ogg: ~3 seconds
  • Chrome mp3: ~2 seconds
  • Firefox ogg: ~1.5 seconds
  • Firefox mp3: ~2 seconds
(44.1kHz, 16bit, stereo)

I don't know if it possible to go under this 1.5 seconds. If I can do this encoding directly in C# (with interop) it is maybe a bit faster I guess. I found this library for doing this, at least I think I can encode ogg with this library. Ogg Vorbis Interop. I haven't tried it by now.

I wanted to share my discoveries even if no one cares :P

Kind regards,
Oct 28, 2015 at 1:43 PM
Great, thanks for sharing your findings. I'm afraid I haven't done any really low latency encoding myself with those codecs. You'd probably need a lower-level library so you could encode in smaller chunks.