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 containi开发者_JAVA技巧ng 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
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.
Use the audioplayer object instead - it gives you the full control on what you do with the sound. I.e:
player = audioplayer(x, fs);
play(player) % start the player
stop(player) % stop whenever you like...
Audioplayer has a lot of other useful stuff: http://www.mathworks.com/help/techdoc/ref/audioplayer.html
精彩评论