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

14 次查看(过去 30 天)
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.

回答(1 个)

Daniel M
Daniel M 2019-10-23
编辑:Daniel M 2019-10-23
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

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by