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

조회 수: 5 (최근 30일)
FOG
FOG 2022년 5월 29일
답변: jibrahim 2022년 6월 6일
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
FOG
FOG 2022년 5월 29일
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);

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

답변 (1개)

jibrahim
jibrahim 2022년 6월 6일
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

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by