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

3 ビュー (過去 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 Center および File ExchangeSequence and Numeric Feature Data Workflows についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by