Play 2 wav files after each other
18 views (last 30 days)
Show older comments
I am trying to play 2 files after each other.
However, I tried multiple things and it either plays the two files simultaniously or the second file does not get played at all.
This is th ecode I tried:
[y1, Fs1] = audioread('file1.wav'); %this file is 5 seconds long
[y2, Fs2] = audioread('file2.wav'); %this file is 1.6 seconds long
player = audioplayer(y1, Fs1);
player2 = audioplayer(y2, Fs2);
play(player);
pause(2);
play(player2);
Like this they just play simultaniously, without a time difference of 2 seconds.
File2 does not get played 2 seconds later than file1.
Can anyone help me with this?
0 Comments
Answers (1)
Star Strider
on 19 Feb 2020
[y1, Fs1] = audioread('file1.wav'); %this file is 5 seconds long
[y2, Fs2] = audioread('file2.wav'); %this file is 1.6 seconds long
player = audioplayer(y1, Fs1);
player2 = audioplayer(y2, Fs2);
playblocking(player);
playblocking(player2);
2 Comments
Star Strider
on 19 Feb 2020
My pleasure.
You did not mention the 2 second delay. I thought you were pausing after the first one to let it finish, and not allowing enough time.
Try this:
playblocking(player);
pause(2)
playblocking(player2);
That worked when I ran it.
See Also
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!