i have attached my speech recognition code.this not working properly can you say what is the mistake in this program?
1 view (last 30 days)
Show older comments
function test_project
clc;
close all;
clear all;
filename = 'off12.amr.wav' % Calculate the codebook vector.
cep=learn(filename);
whos cep
cep1 = learn('motoron.amr.wav');
cep1(size(cep1,1):size(cep,1))=0;
for i=1:20
[m1 , ~]=xcorr(cep(:,i),cep1(:,i));
end
% [xcor,~]=xcorr(cep,cep1);
% m1=max(xcorr);
cep2 = learn('off11.amr.wav');
cep2(size(cep1,1):size(cep,1))=0;
for i=1:20
[m2 ~]=xcorr(cep(:,i),cep2(:,i));
end
m1=max(m1);
m2=max(m2);
m1
m2
final=[m1 m2];
solution=max(final);
if solution == m1
disp('motor on');
end
if solution == m2
disp('off');
end
end
%%%%% LEARNING AND MFCC %%%%%
function cep = learn(file)
[filedata, fs] = audioread(file);
% audiowrite('signal.wav',filedata,fs);
% [filedata, fs] = audioread('signal.wav');
[b s]=butter(3,[85/fs 255/fs],'bandpass');
filedata=filter(b,s,filedata);
truncated =filedata(find(filedata));
cep = mfcc(truncated);
end
function cepstrum = mfcc(x)
% FRAME BLOCKING
j=1;
i=1;
[s1, s2] = size(x);
window_length=120;
ww=window_length;
while ( (j+ww) <= s1)
for( k=1 : ww)
x_new(i,k) = x(k+j-1);
end
i = i+1;
j = j + ww;
end
% WINDOWING
j=1;
i=1;
[s1, s2] = size(x);
w = hamming(ww);
while ( (j+ww) <= s1)
for( k=1 : ww)
x_new(i,k)=x_new(i,k) * w(k);
end
i = i + 1;
j = j + ww;
end
length(x_new)
% FAST FOURIER TRANSFOR M
j=1;
i=1;
while ( (j+ww) <= s1)
x_new_freq(i,1:ww) = fft(x_new(i,1:ww));
i = i + 1;
j = j + ww;
end
% MEL FREQUENCY WRAPPING
nr_of_filters = 30;
m = melfb(nr_of_filters,ww,8000);
n2 =1+floor(120/2);
i=1;
j=1;
while ( (j+ww) <= s1)
for (k=1:nr_of_filters)
z_prim = (m * (abs(x_new_freq(i,1:n2)).^2)'); %'
z(i,k) = z_prim(k);
end
j = j + ww;
i = i + 1;
end
i=1;
j=1;
while ( (j+ww) <= s1)
cepstrum_prim = dct(z(i,1:nr_of_filters));
for (k=1:nr_of_filters)
cepstrum(i,k) = cepstrum_prim(k);
end
j = j + ww;
i = i + 1;
end
resolution = i-1;
figure, plot(cepstrum)
end
%%%%% DETERMINING MEL-SPACED FREQUENCY BANK %%%%%
function m = melfb(p,n, fs)
% numberof filters in filterbank
% length of fft
f0 = 700 / fs;
fn2 = floor(n/2);
lr = log(1 + 0.5/f0) / (p+1);
% convert to fft bin numbers with 0 for DC term
bl = n * (f0 * (exp([0 1 p p+1] * lr) - 1));
b1 = floor(bl(1)) + 1;
b2 = ceil(bl(2));
b3 = floor(bl(3));
b4 = min(fn2, ceil(bl(4))) - 1;
pf = log(1 + (b1:b4)/n/f0) / lr;
fp = floor(pf);
pm = pf - fp;
r = [fp(b2:b4) 1+fp(1:b3)];
c = [b2:b4 1:b3] + 1;
v = 2 * [1-pm(b2:b4) pm(1:b3)];
m = sparse(r, c, v, p, 1+fn2);
end
1 Comment
Answers (0)
See Also
Categories
Find more on Speech Recognition 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!