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/AudioKit.h"
#include "AudioLibs/MicroRTSPAudio.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 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!


Leave a Reply

Avatar placeholder

Your email address will not be published.