When an audiofile is played using the SOUND command, it cannot be stopped using Ctrl-C.
According to solution 1-UAQTF, this was fixed in R2011b, but it doesnt seem to work in R2013a.
Best Answer
There are a couple of ways for achieving the ability to interrupt a playing audio file. The first way is by creating an object for playing audio using the AUDIOPLAYER command and then using PLAY and STOP commands to play or stop playing the file. Further, the PAUSE command can be used here to pause the audio file at a certain instant and the RESUME command can be used to resume playing from that instant. Below is an example that illustrates this using a sample audio file of Handel’s “Hallelujah Chorus”.
>>load handel;
>>player = audioplayer(y, Fs);
Now type this at the command prompt to play the file:
>>play(player)
To stop playing type this at the command prompt:
>>stop(player)
Also, to pause playing at any instant:
>>pause(player)
Then to resume playing after pause:
>>resume(player)
For further details on AUDIOPLAYER, please refer to the following documentation:
The second way is to use PLAYBLOCKING to play audio from an AUDIOPLAYER object that is created using the AUDIOPLAYER command. In this case, the audio file can be interrupted by using Ctrl-C. An example is shown below which also uses the sample audio file of Handel’s “Hallelujah Chorus”.
>>load handel;
>>playblocking(audioplayer(y,Fs))
To stop at any instant, use Ctrl-C.
If an audioplayer object is created explicitly then use a function instead to be able to interrupt using Ctrl+C.
This would not need the clearing of the audioplayer object using CLEAR command which is otherwise needed after hitting Ctrl+C to stop playing.
The ability to use the PLAY function with an AUDIOPLAYER object without using the handle to that object is not available in MATLAB.
The proper way to use the PLAY function and AUDIOPLAYER objects is, as stated in the documentation, by using the handle to the AUDIOPLAYER object. For example:
Best Answer