You are on page 1of 8

function varargout=Reconocimiento_voz_1(varargin)

gui_Singleton =1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn',
@Reconocimiento_voz_1_OpeningFcn, ...
'gui_OutputFcn',
@Reconocimiento_voz_1_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State,
varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before Reconocimiento_voz_1 is made


visible.
function Reconocimiento_voz_1_OpeningFcn(hObject, eventdata,
handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
% varargin command line arguments to Reconocimiento_voz_1
(see VARARGIN)

% Choose default command line output for Reconocimiento_voz_1


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes Reconocimiento_voz_1 wait for user response


(see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command
line.
function varargout = Reconocimiento_voz_1_OutputFcn(hObject,
eventdata, handles)
% varargout cell array for returning output args (see
VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)

% Get default command line output from handles structure


varargout{1} = handles.output;

function sonidoN=normalizar(sonido)
maximo=max(abs(sonido));
n=length(sonido); %calcula el tamao del vector
sonidoN=zeros(1,n);
for i=1:1:n
sonidoN(i)=sonido(i)/maximo;
end

function [nombre, transf_usuario, transff_bd, min_error] =


LeerDirectorio()

voz_usuario=audioread('voz.wav');
norm_usuario=normalizar(voz_usuario);
transf_usuario=abs((fft(norm_usuario))); %transformada rapida
de Fourier
%Esto nos permitira manejar los errores cuando la voz no se
encuentre en
%nuestra BD
min_error=100000;
transff_bd=1;
nombre=' ';
%
lee_audios = dir([pwd '\*.wav']); %el formato de audio puede
ser modificado.
for k = 1:length(lee_audios)%recorre nmero de audios
guardados en el directorio
audio_nom = lee_audios(k).name; %Obtiene el nombre de los
audios

if ~strcmp(audio_nom,'voz.wav')
voz_bd = audioread([pwd '\' audio_nom]);
norm_voz_bd=normalizar(voz_bd);
transf_voz_bd=abs((fft(norm_voz_bd)));

actual_error=mean(abs(transf_voz_bd -
transf_usuario));
if actual_error < min_error
min_error=actual_error;
nombre=audio_nom;
transff_bd=transf_voz_bd;
end
end
end

% --- Executes on button press in GRABAR.


function GRABAR_Callback(hObject, eventdata, handles)
% hObject handle to GRABAR (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
clc %limpia la pantalla
% clear all
global y fs m1 ; %Establecer variables globales
fs=11025; %frecuencia de muestreo
tiempograb=2; %Tiempo de grabacion
v1=audiorecorder(fs,24,1); %funcin de grabacion
recordblocking(v1, tiempograb);
y = v1.getaudiodata();
ts=1/fs;
t=0:ts:tiempograb-ts;
b=[1 -0.95];
yf=filter(b,1,y); %Proceso de filtrado
len = length(y); %longitud del vector
avg_e = sum(y.*y)/len; %promedio seal entera
THRES = 0.2;%umbral
%soundsc(y,fs) %Reproduce seal filtrada
audiowrite('voz.wav',yf,fs); %Graba en archivo .wav
%---- Grafica seal grabada
% figure(1);
% plot(t,y);grid on;
set(handles.axes1); % Establece los ejes de graficacin
axes(handles.axes1);
plot(t,y);% Grafica en los axes
grid on; % Grafica en los axes
handles.y=y;
m1=0;
msgbox('Grabacin Terminada amiguito');
guidata(hObject, handles);

function Selector_Callback(hObject, eventdata, handles)


% hObject handle to Selector (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
global a;
v=get(handles.Selector,'Value');
switch v
case 1
a=arduino('com2','uno');
handles.a=a;
case 2
a=arduino('com3','uno');
handles.a=a;
case 3
a=arduino('com4','uno');
handles.a=a;
case 4
a=arduino('com5','uno');
handles.a=a;
case 5
a=arduino('com6','uno');
handles.a=a;
case 6
a=arduino('com7','uno');
handles.a=a;
otherwise
msgbox('Conecte un arduino');
end
guidata(hObject, handles);

% --- Executes on button press in REPRODUCIR.


function REPRODUCIR_Callback(hObject, eventdata, handles)
% hObject handle to REPRODUCIR (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
[y,fs]=audioread('voz.wav'); %Lectura del archivo grabado
soundsc(y,fs);
% --- Executes on button press in Transformar.
function Transformar_Callback(hObject, eventdata, handles)
% hObject handle to Transformar (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)7
global m1;
m1=0;
y=handles.y;
a=handles.a;
fs=11025;
N=length(y); %calcula el tamao del vector
f=(0:N-1)*fs/N;
[nombre, transf_usuario, transff_bd, band]=LeerDirectorio;
if band < 10
set(handles.axes2); %Establece el axes para graficar
axes(handles.axes2); %Axes habilitado para graficar
plot(f(1:N/2),transff_bd(1:N/2));grid on; %Grafica del
espectro de la letra de la base de datos
set (handles.resultado,'string', upper(nombre(1:end-4)));
% Muestra la letra comparada
x=nombre(1:end-4);
if strcmp(x,'derecha')%condicional para ejecutar el
arduino
writeDigitalPin(a,7,1);
writeDigitalPin(a,8,0);
elseif strcmp(x,'izquierda')
writeDigitalPin(a,8,1);
writeDigitalPin(a,7,0);
elseif strcmp(x,'stop')
writeDigitalPin(a,7,0);
writeDigitalPin(a,8,0);
elseif strcmp(x,'prende')
writeDigitalPin(a,9,1);
writeDigitalPin(a,10,0);
elseif strcmp(x,'uno')
writeDigitalPin(a,10,1);
writeDigitalPin(a,9,0);
elseif strcmp(x,'alto')
writeDigitalPin(a,9,0);
writeDigitalPin(a,10,0);
end

set(handles.axes3); %Establece el axes para graficar


axes(handles.axes3); %Axes habilitado para graficar
plot(f(1:N/2),transf_usuario(1:N/2));grid on; %Grafica
del espectrode la letra pronunciada0
else
set (handles.resultado, 'string', ' ');
msgbox('Advertencia, usted no esta autorizado amiguito');
end

% --- Executes on button press in Agregar_Sonido.


function Agregar_Sonido_Callback(hObject, eventdata, handles)
% hObject handle to Agregar_Sonido (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)7
t = 2;% tiempo de grabacion
Fs = 11025;%frecuencia de muestreo
v = audiorecorder(Fs, 24, 1);%
leer=get(handles.leer1,'String');%nombre de la grabacion
recordblocking(v, t);%sonido en un periodo de tiempo
y = v.getaudiodata();%captura la data del sonido
b=[1 -0.95];
yf=filter(b,1,y);%%%Para filtrar los ruidos
audiowrite (strcat(leer),yf,Fs); %guarda el sonido en formato
wav%
direccion=which(strcat(leer));
msgbox('Grabado con exito compaerito');
msgbox(direccion);
guidata(hObject, handles);% Guardar datos de la funcion

function leer1_Callback(hObject, eventdata, handles)


% hObject handle to leer1 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
% Hints: get(hObject,'String') returns contents of leer1 as
text
% str2double(get(hObject,'String')) returns contents
of leer1 as a double

% --- Executes during object creation, after setting all


properties.
function leer1_CreateFcn(hObject, eventdata, handles)
% hObject handle to leer1 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles empty - handles not created until after all
CreateFcns called

% Hint: edit controls usually have a white background on


Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function resultado_Callback(hObject, eventdata, handles)


% hObject handle to resultado (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)

% Hints: get(hObject,'String') returns contents of resultado


as text
% str2double(get(hObject,'String')) returns contents
of resultado as a double

% --- Executes during object creation, after setting all


properties.
function resultado_CreateFcn(hObject, eventdata, handles)
% hObject handle to resultado (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles empty - handles not created until after all
CreateFcns called
% Hint: edit controls usually have a white background on
Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- Executes on selection change in Selector.

% Hints: contents = cellstr(get(hObject,'String')) returns


Selector contents as cell array
% contents{get(hObject,'Value')} returns selected item
from Selector

% --- Executes during object creation, after setting all


properties.
function Selector_CreateFcn(hObject, eventdata, handles)
% hObject handle to Selector (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles empty - handles not created until after all
CreateFcns call

% Hint: popupmenu controls usually have a white background on


Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

You might also like