Creating a modified audiofile

5 views (last 30 days)
Youssef Darwich
Youssef Darwich on 30 Jul 2021
Commented: Youssef Darwich on 6 Aug 2021
Hi,
i have a 2 seconds audiofile. How can i create a 2 min. one from the same data. in other words in need to create a loop of the same data in the original 2 sec. file which goes for 2 min.
i appreciate every help, thanks!
  4 Comments
Jonas
Jonas on 1 Aug 2021
Edited: Jonas on 1 Aug 2021
have a look into the audioread, audiowrite and repmat function
Youssef Darwich
Youssef Darwich on 6 Aug 2021
thanks, this was helpful

Sign in to comment.

Accepted Answer

Yazan
Yazan on 1 Aug 2021
clc, clear
% load data
load handel.mat
filename = 'handel.wav';
audiowrite(filename, y, Fs);
% save only 2 second of audio
y = y(1:2*Fs);
% extend the audio from 2 sec to 2 minutes
rep = round(2*60/2);
yrep = repmat(y, [rep, 1]);
% write the extended audio
audiowrite(filename, yrep, Fs);
% read the extended audio
[y, Fs] = audioread('handel.wav');
% listen to extended audio
sound(y, Fs);

More Answers (0)

Categories

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

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!