Segment audio file using time

조회 수: 10 (최근 30일)
Melissa Ette
Melissa Ette 2020년 10월 27일
답변: Mathieu NOE 2020년 10월 28일
I have a .wav file ( song.wav ) that is 5s long, I have time_start= 3.23s and time_end=4.35s and another sing.wav that is 4s long with time_start1=2.38s and time_-end1=3.56s. I want to store the segments of song.wav and sing.wav that start respectively are time_start and time_start1 and end at time_end and time_end1 into a cell array. How do I start? The answer I've seen so far were cutting the file in terms of Fs, that's not it
  댓글 수: 3
Mario Malic
Mario Malic 2020년 10월 27일
Hi Mathieu,
It would be great if you post this in an answer section.
Mathieu NOE
Mathieu NOE 2020년 10월 27일
will do !
tx

댓글을 달려면 로그인하십시오.

채택된 답변

Mathieu NOE
Mathieu NOE 2020년 10월 27일
hello Melissa
you have to do the computation on samples , and you have to know the sampling frequency FS for each wav file
you get this info when you use audioread or wavread
[Y,FS,NBITS]=wavread(FILE) (older matlab)
or
[Y,FS,NBITS]=audioread(FILE) (newer matlab)
then determine start and stop indexes , knowing the start and stop times
song1_start_ind = round(start_time*FS); % must be an integer value
song1_stop_ind = round(stop_time*FS); % must be an integer value
then
song1_extract = song1(song1_start_ind:song1_stop_ind);
do the same on the second wav file :
song2_extract = song2(song2_start_ind:song2_stop_ind);
to save to a cell array :
C{1} = song1_extract;
C{2} = song2_extract;
  댓글 수: 1
Melissa Ette
Melissa Ette 2020년 10월 27일
Thank you so much! How would this work in a loop? I am now trying to do it for a bigger sample

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Mathieu NOE
Mathieu NOE 2020년 10월 28일
hi
this is waht i suggest to do on one single wav file
if it matches your request , the main code can be converted to a function , then you can also create a loop for looping through multiple wav files in your directory. Let me know if this is also of interest for you.
so for the time being, single file / multiple extracts demo :
[song,FS,NBITS]=wavread('demo.wav'); %(older matlab)
% or
% [Y,FS,NBITS]=audioread(FILE); %(newer matlab)
% create list of start / stop time indexes
start_time = [1; 2 ; 3 ; 4]; % length is equal of nb of extracts
stop_time = [5; 6 ; 7 ; 9];
% main loop %
for ci = 1:length(start_time)
% determine start and stop indexes , knowing the start and stop times
song_start_ind = round(start_time(ci)*FS); % must be an integer value
song_stop_ind = round(stop_time(ci)*FS); % must be an integer value
% then extract
song_extract = song(song_start_ind:song_stop_ind);
% save to a cell array :
C{ci} = song_extract;
% % check (plot)
% figure(ci) , plot(song_extract);
end

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by