How to Train and Test any .wav file in a project to recognize the speaker.
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Please help me. I am having a problem. Thank you very much.
+ My "train" file is running by default for 8 files from s1-s8 in "tran \ data \". But I just want it to train an audio file whenever, for different people (each person only trains once any time).
+ I want the same thing for my "test" file.
- Here is my "train" code:
function code = train(traindir, n)
% Speaker Recognition: Training Stage
%
% Input:
% traindir : string name/path of directory contains all train sound files
% n : number of train files in traindir
%
% Output:
% code : trained VQ codebooks, code{i} for i-th speaker
%
% Note:
% Sound files in traindir is supposed to be:
% s1.wav, s2.wav, ..., sn.wav
k = 16; % number of centroids required
for i=1:n % train a VQ codebook for each speaker
% i = {i};
file = sprintf('%s\\s%d.wav', traindir, i);
disp(file);
[s, fs] = audioread(file);
v = mfcc(s, fs); % Compute MFCC's
code{i} = vqCodeBook(v, k); % Train VQ codebook
end
- here is my "test" code:
function test(testdir, n, code)
% Speaker Recognition: Testing Stage
%
% Input:
% testdir : string name of directory contains all test sound files
% n : number of test files in testdir
% code : codebooks of all trained speakers
%
% Note:
% Sound files in testdir is supposed to be:
% s1.wav, s2.wav, ..., sn.wav
%
% Example:
% >> test('C:\data\test\', 8, code);
for k=1:n % read test sound file of each speaker
file = sprintf('%ss%d.wav', testdir, k);
[s, fs] = audioread(file);
v = mfcc(s, fs); % Compute MFCC's
distmin = inf;
k1 = 0;
for l = 1:length(code) % each trained codebook, compute distortion
d = distance(v, code{l});
dist = sum(min(d,[],2)) / size(d,1);
if dist < distmin
distmin = dist;
k1 = l;
end
end
msg = sprintf('Speaker %d matches with speaker %d', k, k1);
disp(msg);
end
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Speech Recognition dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!