Skip to content

Instantly share code, notes, and snippets.

@maietta
Created October 8, 2023 20:22
Show Gist options
  • Save maietta/b04bc969c4f03e01f6ee308b4e4e13e3 to your computer and use it in GitHub Desktop.
Save maietta/b04bc969c4f03e01f6ee308b4e4e13e3 to your computer and use it in GitHub Desktop.
Capture audio from soundcard, stream to Shoutcast server & archive 1 minute intervals.
# Set log level
set("log.level", 4)
# Capture audio from the ALSA sound card interface
input_stream = input.alsa(device="default")
# Function to add breaks every minute
def add_breaks(~duration, s) =
let duration = duration * 60. in
sequence([s, blank(duration)])
end
# Add breaks every minute to the input stream
sliced_input = add_breaks(1., input_stream)
# Function to save a slice every minute
def save_slice(m) =
timestamp = int_of_float(gettimeofday())
filename = "/path/to/save/directory/"^timestamp^".mp3"
output.file(%mp3, fallible=true, append=true, filename, m)
end
# On each "track" (every minute), save a slice
sliced_input = on_track(save_slice, sliced_input)
# Relay the stream to an Icecast server
output.icecast(
%mp3,
host = "your.icecast.server",
port = 8000,
password = "yourpassword",
mount = "relay",
input_stream
)
# Play the sliced input (this is necessary to ensure the on_track function is triggered)
output.dummy(sliced_input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment