Record from an online audio stream

I would like to record a few seconds of audio from an online .mp3 or .aac stream, for example from http://ais.absoluteradio.co.uk/absoluteclassicrock.mp3.

I tried several ways: from within a terminal window, with R and with Julia. None was successful so far. I guess the main issue is the fact that online streams do not have and ‘end’.

Perhaps someone here can help me out, as I am not too familiar with the Julia Audio packages. Any help is welcome, thanks in advance!

With Kaldi I’ve discovered pyaudio, I think it can do what you want:
https://stackoverflow.com/questions/32480393/pyaudio-recording-audio-from-streaming-python

Le sam. 11 avr. 2020 à 13:14, Martijn via JuliaLang julialang@discoursemail.com a écrit :

Not sure if this helps, but you may check out

@ssfrr might know more about streaming audio capture in Julia

Thanks @apieum and @baggepinnen,

I looked into PortAudio.jl and I can now sample from an analog input like my mic. Works very well.

Now I need to grab a few seconds of data from an online audio stream, i.e. already digitized. Unfortunately, MP3.jl doesn’t support reading from a stream as far as I know…

Thanks again.

Have you tried with sockets to grab few seconds of data like pyaudio example ?
This example was for julia 0.6, but it may still work: How to read from socket in non-blocking mode - #6 by Keno
Instead of while !eof(socket)
You can use size of received data…

Hi @apieum,

Thanks for the link. I will try to do what was done in the pyaudio example, yes.

I also tried the code below using HTTP.jl, but is doesn’t read any bytes:

using HTTP
HTTP.open( "GET", "http://ais.absoluteradio.co.uk/absoluteclassicrock.mp3") do io

     cycles, totbytes = 0, 0
     while cycles < 100 

         bytes = readavailable( io)
         nbytes = length( bytes)

         cycles += 1; totbytes += nbytes

         println( "Cycles: $cycles;  bytes read: $totbytes")
         if nbytes > 0
             println( bytes)
         end

     end

end

This is working fine:

using HTTP
HTTP.open("GET", "http://ais.absoluteradio.co.uk/absoluteclassicrock.mp3") do http
    n = Ref(0)
    r = startread(http)
    while !eof(http) && n[] < 1000
        bytes = read(http, 100)
        println("GET data: $bytes")
        n[]+=length(bytes)
    end
    @show n
end
2 Likes

Hi @apieum,

That is indeed working and looks very good :+1:

This will help me forward. Merci beaucoupe pour votre aide!

1 Like