필터 지우기
필터 지우기

extract audio features from music

조회 수: 5 (최근 30일)
Rita Campos
Rita Campos 2023년 9월 24일
댓글: Star Strider 2023년 10월 1일
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

답변 (1개)

Star Strider
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
Rita Campos
Rita Campos 2023년 10월 1일
Still in regard to the above code, could you please teach me how to implement BPM tracking in that code. What I need to do is be able to get the BPM for each song that is part of the above folder/fileList.Basically just like I extract other features, I also need to extract BPM.
I have found information regarding audiotoolbox on how to do it, but can't figure out how to make it work as part of my code above.
Any chance you could please help?
Thanks in advance.
Star Strider
Star Strider 2023년 10월 1일
I do not have any experience with the Audio Toolbox, or its functions.

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

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by