Created
October 8, 2023 20:22
-
-
Save maietta/b04bc969c4f03e01f6ee308b4e4e13e3 to your computer and use it in GitHub Desktop.
Capture audio from soundcard, stream to Shoutcast server & archive 1 minute intervals.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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