To read multiple audio files as an index and get the length of each file, you can do the following steps:
dir
function to get the details of all the files with a specific extension (e.g., .wav
) in that folder.audioread
function.length
function and store it in another array.Here's an example code snippet that demonstrates this:
main.m660 chars19 lines
In this example, folder
is the path to the folder containing the audio files, extension
is the file extension of the audio files (assuming all audio files have the same extension), and file_names
and file_lengths
are the arrays that will store the filenames and lengths of the audio files, respectively.
The dir
function is used to get the details of all the audio files in the folder that have the .wav
extension. The fullfile
function is used to create the full path to each audio file. The audioread
function is used to read each audio file and return the audio waveform and its sample rate. Finally, the length
function is used to get the length of each audio waveform.
Note that this code assumes that all audio files have the same sample rate. If this is not the case, you may need to resample the audio to a common sample rate before computing the length.
gistlibby LogSnag