Clear Filters
Clear Filters

How do I trim a WAV file from point A to B.

26 views (last 30 days)
AJ516
AJ516 on 23 Oct 2019
Edited: Daniel M on 23 Oct 2019
I am looking into trimming a WAV file to section out a beep sound. The clip is 47 seconds long and was converted from an AAC file. Here is what I am needing for this script.
-Retrieve file
-Use point A and B with different inputs of seconds (ex. A=37 seconds and B =39 seconds, or A=37.5 and B=38.5)
-Send file out in WAV
I can retrive the file and send a new one out just fine. The new thing I would like to learn about is trimming audio clips. How should I do this?
Any script help and code reffeences would be awesome.

Answers (1)

Daniel M
Daniel M on 23 Oct 2019
Edited: Daniel M on 23 Oct 2019
You have the sampling frequency as an output from the audioread function. The time vector would typically go
t = 0:1/fs:(length(soundfile)-1)/fs;
So then, 37 seconds will occur at roughly (37*fs + 1) in t. But this won't always work. Safer is to search for the closest value in your t variable.
[~,loc37] = min(abs(t-37));
[~,loc39] = min(abs(t-39));
x(loc37:loc39) = []; % this will cut out the sections of your sound file between 37 and 39 seconds

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!