how can i play sounds in specific order with specific durations
7 次查看(过去 30 天)
显示 更早的评论
i need to let matlab play the happy birthday song. i already downloaded all the notes as wav files and i also put them in order in a list with the order of the duration.
duration=[0.5, 0.5, 1, 1, 1, 2, 0.5, 0.5, 1, 1, 1, 2, 0.5, 0.5, 1, 1, 1, 1, 3, 0.5, 0.5, 1, 1, 1, 2];
song=[si,si,do,si,mi,re,si,si,do,si,fa,mi,si,si,si,sol,mi,re,do,la,la,sol,mi,fa];
for exemple i need to play the note (si) first with a duration of (0.5 sec).
can anyone help?
0 个评论
回答(1 个)
Spectro
2021-11-30
编辑:Spectro
2021-11-30
Use a forcycle to run through all the notes with the appropriate durations using audioread. Also adjust each sound vector in dependence on the duration. See the idea below:
for i = 1:length(song)
% Load the note
[y, fs] = audioread('yourNote.wav');
% Example of y2 for halft the duration (0.5)
n = length(y);
y2 = y(1:fix(n*0.5), :);
% Play it
soundsc(y2, fs);
end
3 个评论
Spectro
2021-12-1
The code was just a clue to lead you on. In that loop, you have to load the specific note in each iteration and adjust its playing duration. It's playing with the indexes. You already have an example for 0.5.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!