Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop sound in MATLAB?

Tags:

matlab

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
like image 768
S.C. Madsen Avatar asked Nov 16 '09 13:11

S.C. Madsen


People also ask

How do I stop a recording in MATLAB?

stop( audioObj ) stops audio playback or recording in progress.

How do you stop a function in MATLAB?

To stop execution of a MATLAB® command, press Ctrl+C or Ctrl+Break.

Why is MATLAB beeping?

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.

What does the sound command do in MATLAB?

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.


3 Answers

Try this command Definitely works !!

clear sound

like image 93
Ella Avatar answered Oct 10 '22 06:10

Ella


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)
like image 24
Jacob Avatar answered Oct 10 '22 05:10

Jacob


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.

like image 25
Hannes Ovrén Avatar answered Oct 10 '22 04:10

Hannes Ovrén