How to read audio on app designer from simulink
32 views (last 30 days)
Show older comments
Roberto Lemaitre on 24 May 2021
Answered: Pavan Guntha on 1 Sep 2021
I want to be able to read the audio output from my simulink simulation on app designer, here's my simulation:
The output is the result of the filtering of an audio file and then everything is summed at the end. I've tried different things but can't manage to get the audio output on my app designer app to later play it, pause it, etc...
If possible, i would like to read the audio with audioplayer to be able to more easily pause and play it. This is the code i have at the moment for writing and reading for example an audio file from my pc.
Any tip or recommendation will be greatly appreciated!
Pavan Guntha on 1 Sep 2021
One of the possible solutions is to use 'sim' command to simulate the Simulink model from the MATLAB App (as you have used in 'subirButtonPushed' callback function). In order to play/ pause/ stop the audio from the MATLAB App, you could use respective playback functions on the 'audioplayer' object as illustrated in the example below.
1) The Simulink model stores the output to a '.wav' file as shown in the figure.
2) The 'startupFcn' function of the MATLAB App simulates the Simulink model and the creates an audioplayer object.
3) The four buttons in the MATLAB App (Play, Pause, Resume & Stop) are attached to their respective callback functions to perform appropriate playback function.
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
[app.audio, app.Fs] = audioread('simuLinkMusic.wav');
app.player = audioplayer(app.audio, app.Fs);
% Button pushed function: PlayButton
function PlayButtonPushed(app, event)
% Button pushed function: PauseButton
function PauseButtonPushed(app, event)
% Button pushed function: StopButton
function StopButtonPushed(app, event)
% Button pushed function: ResumeButton
function ResumeButtonPushed(app, event)
For more information on playback functions, you could have a look at the documentation page: Play or Record Audio
Hope this helps!
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!