Raspberry Pi Realtime Streaming Audio with Flask Server

I’m trying to create a raspberry pi server that inputs anything that comes in the audio jack, and live streams it on the local network, to where anyone with a browser can listen to the audio.

I know how to input audio from the audio jack, i just need help live streaming the audio in real time and playing it in browser. How would I be able to stream the audio real time from the flask back end, and play it automatically in the client? Would I rather use AJAX or Web Sockets? How exactly would I do it? How would I do it if multiple clients need to access the same source while maintaining the real time latency?

1 Like

you dont use any of that, you use icecast and liquidsoap.
both firefox and chrome/chromium (edge will soon be chromium based) will play .m3u files.
just set http://:/stream.name as the home page and it will play when the browser starts.
or you could embed that in your webpage you design as well.

simple liquidsoap script (it is far more powerful than this) that plays a .m3u list and every 4th song is randomly picked.

#path to liquidsoap
#!/usr/bin/liquidsoap 
  #path to the logfile, call it whatever you want
  set("log.file.path","./your.log") 

  #this sets up a variable containing your .m3u file , call it whatever you like
  radio = playlist("/path/to/your.m3u") 

  #this defines the the randomness of the playlist, 1 being every song ,2 being every other song etc 
  radio = random(weights = [4],[radio]) 

  #this sets the various needed audio and connection info 
  #the connection info is defined in your icecast.xml (icecast config file) 
  #bit/sample rate can be whatever you want use some reason with this 
  #ports and passwords need to match the icecast.xml settings. 
  # this is all one line 
  output.icecast(%mp3(bitrate=64, samplerate=44100), host = "your.icecast.server", port =<chosen in icecast.xml>, password = "hackme", mount = "your.stream", mksafe(radio))