When playing a sound using e.g:
sound(x,fs);
I sometimes by accident play the wrong one. If x is of substantial length, I currently try to wait until the sound has completed. Any suggestions on how to "abort" the playback? I've already tried
sound(mute,fs); % Mute is a short vector containing all zeroes
But that didn't work. I'm using Windows by the way.
UPDATE:
The following solution proposed by kigurai seems to do the trick:
sound(x,fs); % Start the audio
Now kill audio by
clear playsnd
stop( audioObj ) stops audio playback or recording in progress.
To stop execution of a MATLAB® command, press Ctrl+C or Ctrl+Break.
If you have configured your system not to produce any sound, then beep is silent. beep produces the operating system's default beep sound. To produce a sound and specify its pitch and duration in MATLAB®, use the sound function.
sound (MATLAB Functions) sound(y,Fs), sends the signal in vector y (with sample frequency Fs ) to the speaker on PC and most UNIX platforms. Values in y are assumed to be in the range . Values outside that range are clipped.
Try this command Definitely works !!
clear sound
Mathworks says (and this applies to sound
as well),
There is no function in MATLAB that can pause or stop audio playback once initiated by WAVPLAY. Instead of using WAVPLAY, an alternative is to create an AUDIOPLAYER object. This type of object has methods which allow pausing, resuming and stopping the audio playback. For example:
player = audioplayer(Y, Fs)
% start the playback
play(player);
% pause the playback
pause(player);
% resume the playback
resume(player)
% stop the playback
stop(player)
Never used "sound()" but when I have played audio using wavplay(..., ..., 'async') I can stop the sound by issuing
clear playsnd
Maybe that works with sound() as well? Note: This is when playing asynchronously. For synchronous playback I assume that CTRL-C should break it, but I had issues with wavplay() last time I tried that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With