MIR toolbox store features
36 次查看(过去 30 天)
显示 更早的评论
Hi!
I am sending this message in the hope that someone is able to help identify what's wrong in the Matlab code below.
I am using the MIR toolbox to extract some features of several audio files within a folder. Then I am trying to store the features for each audio file. However, with my current code it seems to only store the features for the first audio file in my folder so I am definitely missing some code here but not sure what to add to the script. Would you be able to tell me what's wrong in my code please? Thanks so much in advance
% Load the MIR toolbox
addpath('C:\Users\anari\OneDrive\Desktop\New folder\01 Coding\mirtoolbox-1.8.2'); % MIR toolbox path
% Specifies the folder containing the audio files
audioFolder = 'C:\Users\anari\OneDrive\Desktop\New folder\01 Coding\Experiment3_audio_files_bars'; % folder path
audioFiles = dir(fullfile(audioFolder, '*.wav'));
% Initialize a struct to hold features for all audio files
allFeatures = struct();
% Loop through each audio file in the folder
for i = 1:length(audioFiles)
% Get the file name
fileName = audioFiles(i).name;
filePath = fullfile(audioFolder, fileName);
% Load the audio file
x = miraudio(filePath); % Load the audio file
% Extract features
% Basic MIR audio operations
basicLength = mirlength(x)
basicPeaks = mirpeaks(x)
% Dynamic Features
dynamicEnvelope = mirenvelope(x)
%Rythm Features
rythmTempo = mirtempo(x)
rythmMetrical = mirmetre(x)
rythmBeatSpectrum = mirbeatspectrum(x)
rythmPulseClarity = mirpulseclarity(x)
% Timbre Features
timbreBrightness = mirbrightness(x)
timbreRoughness = mirroughness(x)
timbreSpectrumIrregularity = mirregularity(x)
% Pitch Features
pitch = mirpitch(x)
% Tonality
tonalityChromagram = mirchromagram (x)
tonalityKeyStrengths= mirkeystrength(x)
tonalityKeysModes= mirkey (x)
tonalityKeyStrengthsMapping= mirkeysom(x)
tonalityModeEstimate= mirmode(x)
tonalityTonalCentroid= mirtonalcentroid(x)
tonalityHarmonicChangeDetection= mirhcdf (x)
% Store features in the struct
allFeatures(i).FileName = fileName;
allFeatures(i).basicLength = mirgetdata(basicLength);
allFeatures(i).basicPeaks = mirgetdata(basicPeaks);
allFeatures(i).dynamicEnvelope = mirgetdata(dynamicEnvelope);
allFeatures(i).rythmTempo = mirgetdata(rythmTempo);
allFeatures(i).rythmBeatSpectrum = mirgetdata(rythmBeatSpectrum);
allFeatures(i).rythmPulseClarity = mirgetdata(rythmPulseClarity);
allFeatures(i).timbreBrightness = mirgetdata(timbreBrightness);
allFeatures(i).timbreRoughness = mirgetdata(timbreRoughness);
allFeatures(i).timbreSpectrumIrregularity = mirgetdata(timbreSpectrumIrregularity);
allFeatures(i).pitch = mirgetdata(pitch);
allFeatures(i).tonalityChromagram = mirgetdata(tonalityChromagram);
allFeatures(i).tonalityKeyStrengths = mirgetdata(tonalityKeyStrengths);
allFeatures(i).tonalityKeysModes = mirgetdata(tonalityKeysModes);
allFeatures(i).tonalityKeyStrengthsMapping = mirgetdata(tonalityKeyStrengthsMapping);
allFeatures(i).tonalityModeEstimate = mirgetdata(tonalityModeEstimate);
allFeatures(i).tonalityTonalCentroid = mirgetdata(tonalityTonalCentroid);
allFeatures(i).tonalityHarmonicChangeDetection = mirgetdata(tonalityHarmonicChangeDetection);
end
% Display the extracted features for all audio files
disp(allFeatures);
1 个评论
Walter Roberson
2024-11-4,4:29
audioFolder = 'C:\Users\anari\OneDrive\Desktop\New folder\01 Coding\Experiment3_audio_files_bars'; % folder path
audioFiles = dir(fullfile(audioFolder, '*.wav'));
I notice that you are storing the files on OneDrive.
Unfortunately, using OneDrive is not entirely reliable. Because of that, there is the possibility that the dir() lists only the first wav file in the folder. It would be safer if your files were stored locally instead of on OneDrive.
回答(1 个)
Shishir Reddy
2024-11-4,4:03
Hi Rita
As per my understanding, you would like to store the features of all the audio files in the folder, but the current code only stores the features for the first audio.
As I don't have the access to the files, here are a few general steps that can be followed to investigate if only the features of the first audio are being stored.
1. It should be ensured that loop is iterating over all the files, this can be done by adding a simple debug statement inside the loop.
fprintf('Processing file %d of %d: %s\n', i, length(audioFiles), fileName);
2. If any of the file is empty or it has some incompatible data, it might lead to issues in storing features. These cases should be handled appropriately, possibly by assigning a default value or skipping the iteration.
3. After the loop, verify that 'allFeatures' contains the entries for each file.
disp({allFeatures.FileName});
I hope this resolves the issue.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!