'How to live stream python-generated audio signals?

I am working on a project that generates audio signals randomly. The Python program I wrote can generate continuous audio signals that I could, for instance, save in an audio file.

Now I would like to broadcast this Python-generated signal through the internet via a straightforward web radio-like interface. The program generates data faster than the audio reading rate and runs on the server. I wonder how I could create an audio stream from this setting that could be readable by anyone with the server's link.

The solution I have in mind works iteratively. I first need to define a buffer within which I can generate chunks of audio samples (for instance an hour in the program below). At every iteration of an infinite while loop, the audio generated by the program could be written in a file that can be used for live streaming. My question is: does anyone have experience in this matter, and what would be the file format I should consider for that?

import numpy as np

SAMPLING_RATE = 44100
BUFFER_DURATION_SEC = 3600

# Turn buffer duration into number of samples
buffer_size = BUFFER_DURATION_SEC * SAMPLING_RATE

while True:

    # Generate audio signal over the buffer
    audio_signal = np.random.randn(buffer_size)

    # Save or live stream the audio signal (what I am looking for):
    # live_stream(audio_signal)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source