extract audio features from music
조회 수: 5 (최근 30일)
이전 댓글 표시
My code below is failing to extract the audio features specified on the code and I can't solve the problem. Anyone can help please? Thanks very much
Matlab presents the following errors:
'Unrecognized function or variable 'spectralCentroid'.
Error in AudioFeaturesExtractAudioToolbox_01>extractAudioFeatures (line 49)
spectralCentroid = spectralCentroid(audio,sampleRate);
Error in AudioFeaturesExtractAudioToolbox_01 (line 20)
features = extractAudioFeatures(audio,sampleRate,chosenFeatures);'
%This code extracts audio features from all audio files within a folder and saves the extracted features in separate '.mat' files
% select the folder path where audio files are located
folderPath = 'C:\Users\xxxxx\Documents\MATLAB\Experiment3';
%get a list of all audio files in the folder
fileList = dir(fullfile(folderPath,'*.wav'));
%Specify the chosen audio features
chosenFeatures = {'mfcc','spectralCentroid','spectralRolloff'};
% Loop through each audio file
for i = 1:length(fileList)
% Read the audio file
filePath = fullfile(folderPath,fileList(i).name);
[audio,sampleRate] = audioread(filePath);
% Extract chosen audio features
features = extractAudioFeatures(audio,sampleRate,chosenFeatures);
% Do something with extracted features (e.g. save to a file)
saveFilePath = fullfile(folderPath,[fileList(i).name '_features.mat']);
save(saveFilePath,'features');
end
%%
% Function to extract the chosen audio features
function features = extractAudioFeatures(audio,sampleRate,chosenFeatures)
% Convert audio to mono if it is stereo
if size(audio,2) > 1
audio = mean(audio,2);
end
% Normalize the audio signal
audio = audio / max(abs(audio));
% Extract the chosen audio features
features = struct();
if ismember('mfcc', chosenFeatures)
mfccCoeffs = mfcc(audio,sampleRate);
features.mfcc = mean(mfccCoeffs,2); % Take the mean across time
end
if ismember('spectralCentroid',chosenFeatures)
spectralCentroid = spectralCentroid(audio,sampleRate);
features.spectralCentroid = mean(spectralCentroid); %single value
end
if ismember('spectralRolloff = mean(spectralRolloff', chosenFeatures)
spectralRolloff = spectralRolloffPoint(audio, sampleRate);
features.spectralRolloff = mean(spectralRolloff); %single value
end
% Add more feature extractions as needed later
end
댓글 수: 0
답변 (1개)
Star Strider
2023년 9월 24일
The spectralCentroid function was introduced in R2019a. You need to have that or a later release to be able to use it.
댓글 수: 6
참고 항목
카테고리
Help Center 및 File Exchange에서 Audio and Video Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!