Recently I discovered the Micro-RTSP-Audio Project from Thomas Pfitzinger which is based on Micro-RTSP from Kevin Hester.

The Real Time Streaming Protocol (RTSP) is an application-level network communication system that transfers real-time data from multimedia to an endpoint device by communicating directly with the server streaming the data.

I tried to adapt the library to make sure that it is also compiling in Arduino and converted the example to comply with the Arduino conventions. However when I started to test it, I was running into memory errors and I spent almost a full day looking at the source code trying to figure out what could be wrong and while doing this, I took the chance to perform some optimizations.

In the end it turned out that the issue was not in the library code but in the provided example: some objects where allocated on the stack and after the setup method, these objects were not valid any more!

My updated Micro-RTSP-Audio Library can be found on Github and the example is working now and I am providing an nice integration into my Audio Tools Library:

Arduino Sketch

#include "AudioTools.h"
#include "AudioLibs/RTSPStream.h"
#include "AudioStreamer.h"
#include "RTSPServer.h"

int port = 554;
int channels = 1;
int sample_rate = 16000;
int bits_per_sample = 16;
const char* wifi = "wifi";
const char* password = "password";

SineFromTable<int16_t> sineWave(32000);                // subclass of SoundGenerator 
GeneratedSoundStream<int16_t> sound(sineWave);             // Stream generated from sine wave
RTSPSourceAudioStream source(sound);                       // Stream sound via RTSP
AudioStreamer streamer = AudioStreamer(&source);
RTSPServer rtsp = RTSPServer(&streamer, port);

void setup() {
  AudioLogger::instance().begin(Serial, AudioLogger::Info);

  // Setup sine wave
  auto cfgS = sineWave.defaultConfig();
  cfgS.channels = channels;
  cfgS.sample_rate = sample_rate;
  cfgS.bits_per_sample = bits_per_sample;
  sineWave.begin(cfgS, N_B4);

  // Start Wifi & RTSP
  rtsp.begin(wifi, password);

void loop() { delay(1000); }

This (potentially updated) example can be found on Github.

To listen to the generated sound you can use the VLC Media Player. Goto -> File -> Open Network and enter the URL rtsp://server-address

Caveat: Please note that currently only the sampling rate 16000 with 1 channel is supported!


Leif · 29. September 2023 at 16:40

Hello Phil,

I found your great project to stream audio via RSTP and EPS with little effort. I tried to compile the project but it doesn’t work because this file is missing:

Compilation error: AudioLibs/RTSPStream.h: No such file or directory

Has something changed?

Thanks for the help and
Many greetings

    pschatzmann · 29. September 2023 at 17:33

    No change: you still need to install the AudioTools library!

Jérôme · 6. April 2023 at 1:26

Do you think it is possible to combine rtsp audio and video on an esp32 cam? That will be really awesome.

    pschatzmann · 14. April 2023 at 7:08

    No, audio will only work with very low sampling rates.
    So I don’t expect that it will work if you add video…

Jérôme · 4. April 2023 at 15:44

Hello, I have uploaded the sketch example streams-i2s-webserver_wav but the sound of the microphone through the web page only crackles. I use EPS32-WROOM-32 and INMP411 Microphone. I tried with another INMP411 freshly bought but same result. Do you have any ideas?

    pschatzmann · 4. April 2023 at 15:57

    Please check the discussions about the INMP411 the on Github.

Jérôme · 31. March 2023 at 12:37

Also wanted to know if it is possible to live stream audio from INMP441 microphone using rtsp or this is only possible via http (like your streams-i2s-webserver_wav exemple)

Jérôme · 31. March 2023 at 12:15

Hello Phil, thanks a lot for your share.
How can I know the rtsp://server-address?
How the server-address is provided? Is it possible to change it?

    pschatzmann · 31. March 2023 at 12:20

    Of cause, it is the tcp/ip address of the ESP32! The port is specified in the sketch.
    You can register your own name with mDNS but this has nothing to do with this functionality.

      Jérôme · 31. March 2023 at 12:54

      Thanks for your fast answer! Ok so I need to define so where that I want to use the Wifi Station mode (to get an IP address from my router). I will check in your project where to change that 🙂

        Jérôme · 31. March 2023 at 21:40

        I really don’t find where to configure the Wifi parameter to use the station mode :-/ Can you give me some help?

          pschatzmann · 31. March 2023 at 22:03

          There is nothing to configure. It is by default in station mode.
          Anything else does not make a lot of sense…

          Jérôme · 1. April 2023 at 9:46

          Thanks! I made it works with streams-i2s-webserver_wav 🙂 next step rtsp. Have a nice day.

Mira · 30. November 2022 at 0:02

my ArduinoIDE (1.8.19) write error:
“C:\Arduino ESP32\portable\sketchbook\libraries\arduino-audio-tools-main\src/AudioLibs/AudioKit.h:4:25: fatal error: AudioKitHAL.h: No such file or directory”
I have installed both linked libraries “updated Micro-RTSP-Audio Library” and “my Audio Tools Library”.

Where can i found “AudioKitHAL.h”, please?
Thank you

Han · 12. October 2022 at 9:43

Hello, i enjoyed reading it! thanks for sharing.
i have question might be ridiculous, if i stopped the stream, am i be able to view the previous streams?

    pschatzmann · 12. October 2022 at 11:14

    I don’t know. I guess this depends on the software that you use…

Arduino Audio Tools - RTSP Revisited - Phil Schatzmann · 2. April 2023 at 18:06

[…] some time ago, I was describing how we can stream audio with the help of RTSP. In that example we needed to provide a data stream from which we can read the […]

Leave a Reply

Avatar placeholder

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