Quite some time ago I was playing with the idea that it should be quite easy to implement a web server in Arduino that provides the same audio signal to multiple users. All that needs to be done is register new connections and close them when the user closes the browser window. Then we just need to copy the same data to all open connections. That’s how my TinyHttp (Audio) Server got started.

This week I decided to finish and release the project and provide a nice integration to my Arduino Audio Tools.

Arduino Sketch

The new server can be treated like any other Audio Sketch: We create a source, the web server as sink and a copier to copy the data from the source to the sink:

#include "AudioTools.h"
#include "AudioLibs/AudioServerEx.h"

const char *ssid = "SSID";
const char *password = "password";
const int sample_rate = 10000;
const int channels = 1;

SineWaveGenerator<int16_t> sineWave;            // Subclass of SoundGenerator with max amplitude of 32000
GeneratedSoundStream<int16_t> in(sineWave);     // Stream generated from sine wave
AudioWAVServerEx server;
StreamCopy copier(server, in);  // copy gen to server

void setup() {

  // start server
  auto cfg = server.defaultConfig();
  cfg.sample_rate = sample_rate;
  cfg.channels = channels;
  cfg.ssid = ssid;
  cfg.password = password; 

  // start generation of sound
  sineWave.begin(channels, sample_rate, N_B4);

// copy the data
void loop() {
  copier.copy(); // copy data to server
  server.copy(); // from server to client

Just open your web browser and type in the indicated address and then you and anybody else can hear the generated sine signal…

Source Code

The source code and further examples be found on Github: Just select the examples that end with serverex


You need to install the following libraries:

  • https://github.com/pschatzmann/arduino-audio-tools
  • https://github.com/pschatzmann/TinyHttp.git


Bruce Doan · 22. September 2022 at 14:19


Do you have time to answer some questions about the ESP32 in audio applications?

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *