Play a wav audio file and duplicate speed for part of it and keep the rest running with the orginal speed in MATLAB

5 views (last 30 days)
I want to play a part of WAV audio file with different speeds for example double speed and keep the rest of the file working normally with the original speed.
% snd is a wav file last 20 seconds.
specPart = snd((2:7) * 2) % I took a part of it and doubled its speed
sound(specPart , FS) % this will be played in double speed
Now I want to play all snd files including the specPart inside of it.

Answers (2)

Geoff Hayes
Geoff Hayes on 7 Nov 2015
Hussein - I'm guessing that your (2:7) is just an example and that you really want to speed up more than just the 6 samples of data. You could try the following, using a MATLAB sample sound file
load handel.mat
which gives us a sampling frequency, Fs, of 8192, and an array of 73K samples, y (so nearly nine second of data). Suppose that we want to speed up the fourth and fifth seconds. We can do
fourthSecondSample = 8192*3 + 1;
sixthSecondSample = 8192*5 + 1;
% get every second sample for the fourth and fifth seconds
sampledData = y(fourthSecondSample:2:sixthSecondSample-1);
% create the new sound array with the sampled sound data
yp = [y(1: fourthSecondSample-1); sampledData; y(sixthSecondSample:end)];
% play the sound with the sampled data
sound(yp,Fs);

Walter Roberson
Walter Roberson on 7 Nov 2015
Extract the data you want and sound() it with Fs*2 as the rate.

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!