How can I receive http audio streams in Matlab?

I used to put the URL (ex: http://192.168.1.23:8000/stream.m3u) for the audio stream into Simulink Multimedia File Reader "File Name" parameter but this no longer functions. Is there a new way of getting streaming audio into a Simulink model? Is there a function that allows me to receive http streams in a Matlab script?

7 Comments

filename = "liveStreamUrl"
afr = dsp.AudioFileReader(fileName);
adw = audioDeviceWriter('SampleRate', afr.SampleRate);
while ~isDone(afr)
audio = afr();
adw(audio);
end
release(afr);
release(adw);
Thanks for the try Massimo,
Tried the script with a local file and it works, but a URL like http://streaming503.radionomy.com/smooth-jazz-wjti-milwaukee-1025 will not work. The error is:
Error using dsp.AudioFileReader
Unsupported file: smooth-jazz-wjti-milwaukee-1025
Error in AudioStream_Analyzer001 (line 4)
afr = dsp.AudioFileReader(fileName,'ReadRange',[1 inf]);
It is probably because I am stuck using Matlab R2021a on my older Mac. It appears that Matlab versions have a very narrow OS compatability window.
I've tried your link, and it works on my Matlab 2023a on Windows.
As you wrote, maybe the issue is some compatibility on the matlab version for Mac
Massimo,
I have a Windows machine and R2021a works fine. Though only on MP3 streams. FLAC, OPUS, and AAC+ do not work. No specs on dsp.AudioFileReader in help.
The milwaukee URL gives me Unsupported file smooth-jazz-wjti-milwaukee-1025 on R2023a on Mac.
Interesting test.
On Mac, Matlab R2021a playing a FLAC or WAV file from my local drive will read on the dsp.AudioFileReader, but MP3 and M4A will not (fails as "unsupported file"). Streaming from the web, FLAC, MP3, AAC, or OPUS streams will not play at all. Doesn't seem like dsp.AudioFileReader is very useful on Mac.
On Windows, Matlab R2021a plays FLAC, WAV, MP3, and M4A files that were tested. Streaming only works on MP3 format streams.
I'm trying to receive multiple HTTP streams to mix them in a multichannel output. Like:
fileName1 = "live Stream 1"
afr1 = dsp.AudioFileReader(fileName1);
fileName2 = "live Stream 2"
afr2 = dsp.AudioFileReader(fileName2);
adw = audioDeviceWriter('SampleRate', 48000,...
'Driver','ASIO',...
'Device','default',...
'BufferSize', 32,...
'BitDepth','24-bit integer',...
'ChannelMappingSource', 'property',...
'ChannelMapping',1:4);
setup(adw ,zeros(afr1.SamplesPerFrame,4))
tic
while ~isDone(afr) && toc<60
audio = [afr1() afr2()];
adw(audio);
end
release(afr1);
release(afr2);
release(adw);
and this works fine, just a a bit slow before it starts playing. Anyway, if I try to add more streams the script becomes unresponsive, and it exits reporting this:
Error using AudioFileReader
Could not add the data source to the filter graph.
I've tried to pin pot the problem, and my last guess is in that the several http requests create a too long packets waiting.
Do you have any suggestion on this issue?
Thanks

Sign in to comment.

Answers (2)

Assuming you need to Process Audio file in your Simulink model:
The “From Multimedia Fileblock accepts the audio files which have extensions such as
.wav, .wma, .avi, .aif, .aifc, .aiff, .mp3, .au, .snd, .mp4, .m4a, .flac, .ogg
So if you need to access web based data use following function in MATLAB
webread(url)
And then you can access the data in Simulink using “From Workspace” block and can process it further.
You can refer to below documentation link for more details on how to use “webread” function.
Richard Keniuk
Richard Keniuk on 26 Aug 2019
Edited: Richard Keniuk on 26 Aug 2019
Thanks for the input Urmila,
Looks like webread will only work for file with a fixed filesize download (picture, web page data, image). I am trying to receive live a live audio stream which has no end. Maybe I am missing something here. I am using this URL for a test: "http://70.38.12.44:8100/stream"

1 Comment

Hi Richard,
did you found a workaround for getting the live audio stream with webread?
thanks
Massimo

Sign in to comment.

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Products

Release

R2019a

Asked:

on 24 Jul 2019

Edited:

on 26 May 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!