dockermp3icecastliquidsoap

Determine current BPM of Icecast stream


I'm trying to detect the BPM of an Icecast MP3 stream using Liquidsoap, but I'm having trouble getting it to work.

My Dockerfile:

FROM savonet/liquidsoap:8101608

# Copy the script into the image
COPY script.liq /usr/src/app/script.liq

# Set the command to run the script
CMD ["liquidsoap", "/usr/src/app/script.liq"]

I want to use the function mentioned here: https://www.liquidsoap.info/doc-dev/reference#bpm. If that is not possible i can just add additional dependencies to the dockerfile.

It would be nice if the bpm is saved to a local file every 10 seconds. I think its just a few lines of code but im completely new to liquidsoap and the documentation is not really beginner friendly.

Thanks for any help!


Solution

  • I asked them on slack and got an answer :)

    Its as simple as that:

    s = input.http("https://icecast...")
    
    s = bpm(s)
    
    thread.run(every=5., fun () -> print("bpm: #{s.bpm()}"))
    
    output.dummy(fallible=true, s)
    

    (i just have to pipe the output into a file now)

    Edit

    Here is an updated version of the script:

    env = environment()
    in_url = env["ICECAST_URL"]
    out_url = env["OUT_URL"]
    
    def post(data) =
        ignore(process.run("curl -X POST -H 'Content-Type: application/json' --data '#{data}' #{out_url}"))
    end
    
    s = input.http(in_url)
    s_bpm = bpm(s)
    s_rms = rms(duration=2.,s)
    
    thread.run(every=1., fun () -> post("{\"bpm\": #{s_bpm.bpm()}, \"rms\": #{s_rms.rms()}}"))
    output.dummy(fallible=true, s_bpm)
    output.dummy(fallible=true, s_rms)
    

    This new version determines the BPM and RMS of the stream and makes HTTP POST requests to the defined url (The dockerfile needs to be edited when using curl)