function [TPT50, NST50, AR] = arate(x, fs, delka_ramce, init, filename)
%% Funkce pro vypocet artikulacni rychlosti, kde se uvazuji pauzy delsi nez 50 ms
% 
% AR - Artikulační rychlost (Articulation Rate) [slabika/s].

%% Vypocet

[VADi]=detektor(x,fs,delka_ramce,init);

full_time = length(x)/fs;
casova_delka_ramce = full_time/length(VADi);

%odstraneni nul na zacatku
for i=1:length(VADi)
    if(VADi(i)==1)
       newVADi = VADi(i:length(VADi)); 
       break;
    end
end

%odstraneni nul na konci
for i=1:length(newVADi)
    if(newVADi(length(newVADi)+1-i) == 1)
        newnewVADi = newVADi(1:length(newVADi)+1-i);
        break;
    end
end

TST = casova_delka_ramce * length(newnewVADi);

%zjisteni cisla a poctu slabik ve vete
% po - nasleduje cislo nebo I-cislo
% -X          -I-X
%potrebujeme 

for i=1:length(filename)
   if filename(i) == '-'
      if filename(i+1) == 'l'
          strnr = filename(i+3);
          nr = str2num(strnr) +5;
          break;      
      else
          nr = str2num(filename(i+1));
          break;
      end
   end    
end

switch nr
    case 1        
        pocetslabik = 9;
        %file-1
    case 2        
        pocetslabik = 11;
        %file-2
    case 3        
        pocetslabik = 10;
        %file-3
    case 4
        pocetslabik = 11;
    case 5        
        pocetslabik = 9;
        %file-5
    case 6        
        pocetslabik = 9;
        %file-l-1
    case 7
        pocetslabik = 11;
        %file-l-2
    case 8
        pocetslabik = 10;
        %file-l-3
    case 9
        pocetslabik = 11;
        %file-l-4
    case 10
        pocetslabik = 9;
        %file-l-5
    otherwise
        %vypis error
        disp('Soubor nema zadanu hodnotu slabik');
end;

%pauza vesti nez 50ms = 15x casovy ramec
nullcount = 0;
pausecount = 0;
for i=1:length(newnewVADi)
   if(newnewVADi(i) == 0)
       nullcount = nullcount+1;       
   else
       if (nullcount >=15)
           pausecount = pausecount + nullcount;
       end
       nullcount = 0;    
   end    
end

TPT50 = pausecount * casova_delka_ramce;
NST50 = TST - TPT50;
AR = pocetslabik / NST50;


