Stop audio from playing using sound()

564 views (last 30 days)
YT
YT on 12 Feb 2019
Commented: Jan on 11 Mar 2022
Matlab Online (ver R2018b)
I'm playing some audio using sound(y,Fs) but I can't find a way to stop the audio from playing. You can guess that it gets even worse when you (accidentally) execute the command twice (yes it plays the music over eachother instead of replacing it). Refreshing the page is the only option for now.
p.s.
I know you can use audioplayer(y,Fs) for offline versions but it won't work online.
  1 Comment
Jan
Jan on 11 Mar 2022
The sound() command does call audioplayer() internally in R2018b. So I cannot see a reason to prefer sound() instead or using audioplayer() directly.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 12 Feb 2019
sound() can only be interrupted by killing matlab .
  4 Comments
Jan
Jan on 11 Mar 2022
@Walter Roberson: Do you agree to accept Joe V's answer, because it is working?

Sign in to comment.

More Answers (2)

Joe V
Joe V on 27 Jun 2019

MUHAMMAD HAIDIEL SHAFIS BIN MAZELAN
lol u guys can also use this too...
[a, fs] = audioread('yourfilehere.mp3');
plot (a(1:100000,1))
fs =1.0*fs; %%We can adjust our speed of our song by multiplying our fs with any desired numbers.
sound (a,fs);
y = input ('Press 1 to stop the music: ');
while y~=1
fprintf ('You didn''t enter 1 ');
fprintf ('\n');
end
clear sound;
  2 Comments
Rik
Rik on 6 Jan 2021
Also, the relevant code is equivalent to the other answer. What does this one add?

Sign in to comment.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!