sound is coming after the picture has disappeared

1 次查看(过去 30 天)
Hi
The sound is still coming up though the picture has disappeared. I want the sound to be there as long as the picture is displayed. How can I manage that? :)
function welcome()
img=imread('Borehole_collapse_ny.png');
image(img);
x=0;
y=0;
width=1.0 ;% measured relative to the figure width
height=1.0; % measured relative to figure height
set(gca, 'units', 'normalized','position',[x y width height])
n=5;
x=rand(1,7000);
sound(x,8000);
pause(n);
close
end

回答(1 个)

Jan
Jan 2022-3-11
编辑:Jan 2022-3-11
x = (rand(1, 70000) - 0.5) * 0.1;
sound(x, 8000);
pause(1)
clear('sound'); % Undocumented
The sound() command calls the modern audioplayer internally. So it is cleaner to use it directly:
a = audioplayer(x, 8000, 16);
play(a)
pause(1);
stop(a)

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by