How do i extract a few seconds from a given audio file?

Illustration
Prashant Ram S - 2022-12-16T10:22:32+00:00
Question: How do i extract a few seconds from a given audio file?

I want to extract the first 0.5 seconds of an audio file and make that portion of the signal as 0. I read the audio file and plotted it successfully but I'm having trouble figuring out how to extract the first 0.5 seconds. Should I use a loop? My code so far, is given below.   [x,fs]= audioread('C:\Users\prashantram.s\Desktop\hello.wav'); [m,n]=size(x); dt=1/fs; t=dt*(0:m-1); figure(1); plot(t,x);  

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

idx = t<0.5 ;
x = x(idx) ;

 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!