function varargout = zkouseni(varargin)
%ZKOUSENI M-file for zkouseni.fig
%      ZKOUSENI, by itself, creates a new ZKOUSENI or raises the existing
%      singleton*.
%
%      H = ZKOUSENI returns the handle to a new ZKOUSENI or the handle to
%      the existing singleton*.
%
%      ZKOUSENI('Property','Value',...) creates a new ZKOUSENI using the
%      given property value pairs. Unrecognized properties are passed via
%      varargin to zkouseni_OpeningFcn.  This calling syntax produces a
%      warning when there is an existing singleton*.
%
%      ZKOUSENI('CALLBACK') and ZKOUSENI('CALLBACK',hObject,...) call the
%      local function named CALLBACK in ZKOUSENI.M with the given input
%      arguments.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help zkouseni

% Last Modified by GUIDE v2.5 16-May-2009 23:13:12

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @zkouseni_OpeningFcn, ...
                   'gui_OutputFcn',  @zkouseni_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 zkouseni is made visible.
function zkouseni_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   unrecognized PropertyName/PropertyValue pairs from the
%            command line (see VARARGIN)

% Choose default command line output for zkouseni
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes zkouseni wait for user response (see UIRESUME)
% uiwait(handles.figure1);

%adr = varargin;
global c;
global pocet_obrazku;
global adres;
global nazvy;
global vada;
global net;


vada = varargin{2};
adres = varargin{1};

if vada == 1
    vadna_hlaska = ('"R"');
    pocet_obrazku = 10;
    nazvy = {'trubka','drak','pračka','kráva','hrad','beruška','hrnec','brambory','ryba','kočárek'};
    load net_r;
    net = net_r;
    
elseif vada == 2
    vadna_hlaska = ('"Ř"');
    pocet_obrazku = 9;
    nazvy = {'třešně','hřeben','pařez','polštář','peřina','dveře','kuchař','námořník','řepa'};
    load net_rr;
    net = net_rr;
    
elseif vada == 3
    vadna_hlaska = ('"S"'); 
    pocet_obrazku = 8;
    nazvy = {'pes','kost','sova','sněhulák','miska','vlasy','postel','spí'};
    load net_s;
    net = net_s;
    
elseif vada == 4
    vadna_hlaska = ('"Š"'); 
    pocet_obrazku = 6;
    nazvy = {'myš','koš','šála','šnek','liška','šiška'};
    load net_ss;
    net = net_ss;
      
end

c = 1;

cesta = strcat(pwd, varargin{1}, '1.jpg');
A = imread(cesta);
hx = gcf;
figure(hx)
set(findobj('Tag','axes4'), 'UserData', imshow(A));

set(findobj('Tag','text_nazev'), 'FontSize',14);
set(findobj('Tag','text_nazev'), 'FontWeight','bold');
set(findobj('Tag','text_nazev'), 'String', nazvy(1));

set(findobj('Tag','nadpis'), 'FontSize',16);
set(findobj('Tag','nadpis'), 'FontWeight','bold');
set(findobj('Tag','nadpis'), 'FontAngle','italic');
set(findobj('Tag','nadpis'), 'String', vadna_hlaska);

set(findobj('Tag','cislo_aktualniho_slova'), 'String', strcat(num2str(c), '.'));
set(findobj('Tag','slov_celkem'), 'String', pocet_obrazku);


% --- Outputs from this function are returned to the command line.
function varargout = zkouseni_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 pushbutton_zpet_Callback(hObject, eventdata, handles)
global c;
global adres;
global nazvy;

if c >= 2
    c = c-1;
    cesta = strcat(pwd, adres, num2str(c), '.jpg');
    set(findobj('Tag','text_nazev'), 'String', nazvy(c));
    A = imread(cesta);
    hx = gcf;
    figure(hx)
    set(findobj('Tag','axes4'), 'UserData', imshow(A));
    set(findobj('Tag','cislo_aktualniho_slova'), 'String', strcat(num2str(c), '.'));
else
end




function pushbutton_dalsi_Callback(hObject, eventdata, handles)
global c;
global pocet_obrazku;
global adres;
global nazvy;

if c <= pocet_obrazku
    if c == pocet_obrazku
    else
        c = c+1;
    end
    cesta = strcat(pwd, adres, num2str(c), '.jpg');
    set(findobj('Tag','text_nazev'), 'String', nazvy(c));
    A = imread(cesta);
    hx = gcf;
    figure(hx)
    set(findobj('Tag','axes4'), 'UserData', imshow(A));
    set(findobj('Tag','cislo_aktualniho_slova'), 'String', strcat(num2str(c), '.'));
else
end




function pushbutton_znova_Callback(hObject, eventdata, handles)

global net;
global c;
global nazvy;

nahravani;


% in = fix(clock);
% fin = fix(clock);
% curr = zeros(1,6);
% test = -1;
% i = 0;
% 
% % pocet sekund (3minuty)
% sec = 6;
% min = 0.1;
% 
% while i < sec
%     set(findobj('Tag','cas'), 'String', strcat(num2str(i), 's'));
%     if test ~= fin(6)
%         test = fin(6);
%         i = i+1;
%         clc;
%         if fin(6) > 9
%             disp(strcat(num2str(fin(5)),':',num2str(fin(6))));
%         else
%             disp(strcat(num2str(fin(5)),':0',num2str(fin(6))));
%         end
%     end
%     fin = fix(clock);
% end

a = char(nazvy(c));
[hlaska hlasitost] = vyber_hlasku(a);
close(nahravani);
melkepst = mfcc(hlaska,16000,256,128,20,1024);
%melkepst = melkepst(2:20,:);


output = zeros(2,1000);
     [M N]=size(melkepst);
       for i=1:N
        r = sim(net, melkepst(:,i)); 
            if r(1)>r(2)
                output(1,i)=1; %správna promluva
            else
                output(2,i)=1; %chybná promluva
            end
       end


spravna = sum(output(1,:));
spatna = sum(output(2,:));

if spravna == spatna
    vysledek = 0;
elseif spravna > spatna
    vysledek = 1;
else
    vysledek = 0;
end
     

%  sdel vysledek
if hlasitost == 1
    hlasiteji;
else
    if vysledek == 1 
        spravne;    
    else
        spatne;
        %get(d);
    end
end

function figure1_CloseRequestFcn(hObject, eventdata, handles)
delete(hObject);
clear all;


