Expected audioIn to be one of these types: single, double Instead its type was cell.

12 views (last 30 days)
can anyone help me please
clc; clear; close all;
trainDir = 'dataset';
ext = '*.wav';
maxAmp = 0.5;
dinfo = dir(fullfile(trainDir, '**', ext));
filenames = fullfile({dinfo.folder}, {dinfo.name});
nfiles = length(filenames);
audio = cell(nfiles,1);
labels = cell(nfiles,1);
feature = cell(nfiles,1);
for K = 1 : nfiles
thisfile = filenames{K};
[fullparent, label] = fileparts(thisfile);
[~, foldername] = fileparts(fullparent);
[y,fs] = audioread(thisfile);
labels{K} = foldername;
y = resample(y,15000,32000);
norm = zeros(length(y),1);
if( maxAmp > 1 || maxAmp < 0 )
fprintf('(ampMax) out of bound.');
else
if max(y) > abs(min(y))
norm = y*(maxAmp/max(y));
else
norm = y*((-maxAmp)/min(y));
end
end
audio{K} = norm;
end
[m,~] = size(labels) ;
P = 0.80 ;
idx = randperm(m);
trainAudio = audio(idx(1:round(P*m)),:) ;
testAudio = audio(idx(round(P*m)+1:end),:) ;
trainLabels = labels(idx(1:round(P*m)),:) ;
testLabels = labels(idx(round(P*m)+1:end),:) ;
aFE = audioFeatureExtractor("SampleRate",fs, ...
"SpectralDescriptorInput","melSpectrum", ...
"spectralCentroid",true, ...
"spectralSlope",true);
featuresTrain = extract(aFE,trainAudio);
featuresTrain = permute(featuresTrain,[2,1,3]);
featuresTrain = squeeze(num2cell(featuresTrain,[1,2]));
[numFeatures,numHopsPerSequence] = size(featuresTrain{1});
featuresTest = extract(aFE,testAudio);
featuresTest = permute(featuresTest,[2,1,3]);
featuresTest = squeeze(num2cell(featuresTest,[1,2]));
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(50,"OutputMode","last")
fullyConnectedLayer(numel(unique(trainLabels)))
softmaxLayer
classificationLayer];
options = trainingOptions("adam", ...
"Shuffle","every-epoch", ...
"ValidationData",{featuresValidation,labelsValidation}, ...
"Plots","training-progress", ...
"Verbose",false);
net = trainNetwork(featuresTrain,trainLabels,layers,options);
  1 Comment
FOG
FOG on 29 May 2022
here some error
Error in audioFeatureExtractor/extract (line 626)
validateattributes(x,{'single','double'},{'2d','real'},'extract','audioIn')
Error in test2 (line 53)
featuresTrain = extract(aFE,trainAudio);

Sign in to comment.

Answers (1)

jibrahim
jibrahim on 6 Jun 2022
Hi FOG,
In this call to extract,trainAudio is a cell array:
featuresTrain = extract(aFE,trainAudio);
extract does not support cell array inputs. You will have to call extract on each signal separately. Something like this:
for K = 1 : nfiles
featuresTrain{K} = extract(aFE,trainAudio{K});
end

Categories

Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!