使用例如播放声音时:
sound(x,fs);
Run Code Online (Sandbox Code Playgroud)
我有时偶然会玩错了.如果x的长度很长,我现在试着等到声音完成.有关如何"中止"播放的任何建议?我已经试过了
sound(mute,fs); % Mute is a short vector containing all zeroes
Run Code Online (Sandbox Code Playgroud)
但那没用.我顺便使用Windows.
更新:
kigurai提出的以下解决方案似乎可以解决问题:
sound(x,fs); % Start the audio
Run Code Online (Sandbox Code Playgroud)
现在杀死音频
clear playsnd
Run Code Online (Sandbox Code Playgroud)
Jac*_*cob 28
Mathworks说(这也适用于sound),
MATLAB中没有任何功能可以在WAVPLAY启动后暂停或停止音频播放.而不是使用WAVPLAY,另一种方法是创建一个AUDIOPLAYER对象.这种类型的对象具有允许暂停,恢复和停止音频回放的方法.例如:
player = audioplayer(Y, Fs)
% start the playback
play(player);
% pause the playback
pause(player);
% resume the playback
resume(player)
% stop the playback
stop(player)
Run Code Online (Sandbox Code Playgroud)
Han*_*rén 25
从未使用过"sound()"但是当我使用wavplay(...,...,'async')播放音频时,我可以通过发出声音来停止声音
clear playsnd
Run Code Online (Sandbox Code Playgroud)
也许这适用于sound()?注意:这是异步播放时.对于同步播放我假设CTRL-C应该打破它,但上次我尝试使用wavplay()时遇到了问题.
使用audioplayer对象 - 它可以让您完全控制对声音的处理.即:
player = audioplayer(x, fs);
play(player) % start the player
stop(player) % stop whenever you like...
Run Code Online (Sandbox Code Playgroud)
Audioplayer还有许多其他有用的东西:http: //www.mathworks.com/help/techdoc/ref/audioplayer.html