Segment audio file using time
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Melissa Ette
el 27 de Oct. de 2020
Respondida: Mathieu NOE
el 28 de Oct. de 2020
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 comentarios
Mario Malic
el 27 de Oct. de 2020
Hi Mathieu,
It would be great if you post this in an answer section.
Respuesta aceptada
Mathieu NOE
el 27 de Oct. de 2020
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;
Más respuestas (1)
Mathieu NOE
el 28 de Oct. de 2020
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
0 comentarios
Ver también
Categorías
Más información sobre Multirate Signal Processing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!