% nahrani signalu z mikrofonu do MATLABu


resp = input('Press ENTER to record a word or type STOP+ENTER','s');

while strcmp(resp,'') ,
    
    
    % starsi verze s WAVRECORD
    %%%%%%%%%%%%%%%%%%%%%%%%%%

    % fs=16000;  % 8000, 11025, 22050, 44100, 48000, and 96000 Hz
    % channels=1;  % 1 or 2 (mono or stereo)
    % 
    % to = 5 ;   % signal duration in seconds
    % 
    % 
    % sig = wavrecord ( to*fs, fs, channels ) ;

    % nova verze s AUDIRECORDER
    %   MATLAB 2014 a vyse
    %%%%%%%%%%%%%%%%%%%%%%%%%%%

    fs=16000;  % 8000, 11025, 22050, 44100, 48000, and 96000 Hz
    bits=16;   % 8, 16, or 24
    channels=1;  % 1 or 2 (mono or stereo)

    to = 5 ;   % signal duration in seconds

    r = audiorecorder(fs, bits, channels);

    record(r);     % speak into microphone...
    pause(to) ;
    stop(r);

    sig = getaudiodata(r, 'double'); % get data as int16 array

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % observing the result
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    figure(1)
    subplot(211)
    plot((1:length(sig))./fs,sig)
    subplot(212)
    wlen=floor(0.032*fs);
    spectrogram(sig,wlen,[],[],fs,'yaxis')
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % New prompt
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    resp = input('Press ENTER to record a word or type STOP+ENTER','s');

end
