folder1 = fullfile(matlabroot,'SpeakerRecognition','training')
folder2 = fullfile(matlabroot,'SpeakerRecognition','validation')
adsTrain = audioDatastore(folder1,"IncludeSubfolders",true)
adsTest = audioDatastore(folder2)
adsTrain.Labels = cellfun(@(file) num2str(numel(adsTrain.Files)), adsTrain.Files, 'UniformOutput', false);
adsTest.Labels = repmat(num2str(numel(adsTest.Files)), numel(adsTest.Files), 1);
adsTrain
trainDatastoreCount = countEachLabel(adsTrain)
adsTest
testDatastoreCount = countEachLabel(adsTest)
[sampleTrain,dsInfo] = read(adsTrain);
sound(sampleTrain,dsInfo.SampleRate)
reset(adsTrain)
fs = dsInfo.SampleRate;
windowLength = round(0.03*fs);
overlapLength = round(0.025*fs);
afe = audioFeatureExtractor(SampleRate=fs, ...
Window=hamming(windowLength,"periodic"),OverlapLength=overlapLength, ...
zerocrossrate=true,shortTimeEnergy=true,pitch=true,mfcc=true);
featureMap = info(afe)
features = [];
labels = [];
energyThreshold = [0.005];
zcrThreshold = 0.2;
keepLen = round(length(sampleTrain)/5);
while hasdata(adsTrain)
[audioIn,dsInfo] = read(adsTrain);
% Take the first portion of each recording to speed up code
audioIn = audioIn(1:keepLen);
feat = extract(afe,audioIn);
isSpeech = feat(:,featureMap.shortTimeEnergy) > energyThreshold;
isVoiced = feat(:,featureMap.zerocrossrate) < zcrThreshold;
voicedSpeech = isSpeech & isVoiced;
feat(~voicedSpeech,:) = [];
feat(:,[featureMap.zerocrossrate,featureMap.shortTimeEnergy]) = [];
label = repelem(dsInfo.Label,size(feat,1));
features = [features;feat];
labels = [labels,label];
end
M = mean(features,1);
S = std(features,[],1);
features = (features-M)./S;
this is my the error that i get when i try to run. its looks like i trying to access the element that does not exist, however i don't know how to modified the code to solve this error.i hope to know how to modified this error that was happening.
Index in position 2 exceeds array bounds.
Error in data (line 49) isSpeech = feat(:,featureMap.shortTimeEnergy) > energyThreshold;
i hope to find the solution for this problem. thanks in advance