function varargout = record(varargin)
% RECORD MATLAB code for record.fig
% RECORD, by itself, creates a new RECORD or raises the existing
% singleton*.
%
% H = RECORD returns the handle to a new RECORD or the handle to
% the existing singleton*.
%
% RECORD('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in RECORD.M with the given input arguments.
%
% RECORD('Property','Value',...) creates a new RECORD or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before record_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to record_OpeningFcn via varargin.
%
% *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 record
% Last Modified by GUIDE v2.5 24-Mar-2017 12:44:44
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @record_OpeningFcn, ...
'gui_OutputFcn', @record_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 record is made visible.
function record_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 record (see VARARGIN)
% Choose default command line output for record
handles.output = hObject;
global R
global mytimer1
global Pauserecorder; %暂停标志
global AFR
global T
global F_RecordClose;
T=240;
AFR=dsp.AudioRecorder(8000);
mytimer1=timer('period',1,'TimerFcn',{@Functimer,handles},'BusyMode','queue','Execution','fixedRate'); %初始化定时器
R = audiorecorder( 8000, 8 ,1 );
Pauserecorder=1;
F_RecordClose=0;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes record wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = record_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;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global R
global a
global b
global mytimer1
global Pauserecorder; %暂停标志
global AFR
global T
T=240;
a=-1;
b=0;
record(R);
Pauserecorder=0;
start(mytimer1);
%%%%%%%%
tic;
while toc<T,
audio = step(AFR);
axes(handles.axes1);
plot(audio);
axis([0,800,-1.5,1.5]);
xf=fft(audio);
f=(1/length(audio):1/length(audio):1/2)*8000;
axes(handles.axes2);
stairs(f,abs(xf(1:length(audio)/2)));
axis([0,3400,0,100]);
drawnow;
%%%%
%%%%%
%[x,y]=meshgrid(f, F);
%z=x.*exp(-x.^2-y.^2); % 计算函数值zz也是21x21的矩阵
%surf(x, y, z); % 画出立体曲面图
%stem(f,y);%针状图
%stairs(f,y);%阶梯图
% bar(f,abs(xf(1:length(audio)/2)));
%e = std(abs(xf(1:length(audio)/2)))*ones(size(f));
%errorbar(f,abs(xf(1:length(audio)/2)),e);
% loglog(f,abs(xf(1:length(audio)/2)));
% semilogx(f,abs(xf(1:length(audio)/2)));
% semilogy(f,abs(xf(1:length(audio)/2)));
drawnow;
% axes(handles.signal_axes);
% xf = fft(audio,512);
% f=(1/length(audio):1/length(audio):1/2)*Fs;
% plot(f,abs(xf(1:length(audio)/2)));
% drawnow;
% pause(1);
end
%pause(AP.QueueDuration); % wait until audio is played to the end
release(AFR); % close the input file
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global R
global Pauserecorder; %暂停标志
global T
global AFR
T=toc;
Pauserecorder=1;
pause(R);
release(AFR);
AFR=dsp.AudioRecorder(8000);
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global F_RecordClose;
global myspeech
name=get(handles.edit1,'String');
audiowrite(name,myspeech,8000);
F_RecordClose=1;
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global R
global Pauserecorder; %暂停标志
global T
global AFR
Pauserecorder=0;
T=240;
resume(R);
tic;
while toc<T,
audio = step(AFR);
axes(handles.axes1);
plot(audio);
axis([0,800,-1.5,1.5]);
xf=fft(audio);
f=(1/length(audio):1/length(audio):1/2)*8000;
axes(handles.axes2);
stairs(f,abs(xf(1:length(audio)/2)));
axis([0,3400,0,200]);
drawnow;
% axes(handles.signal_axes);
% xf = fft(audio,512);
% f=(1/length(audio):1/length(audio):1/2)*Fs;
% plot(f,abs(xf(1:length(audio)/2)));
% drawnow;
% pause(1);
end
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global R
global mytimer1
global myspeech
global T
T=toc;
stop(R);
stop(mytimer1);
myspeech = getaudiodata(R);
axes(handles.axes1);
plot(myspeech);
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
%handles.filename=get(hObject,'String');
%guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 Functimer(hObject, eventdata, handles)
global a
global b
global Pauserecorder; %暂停标志
if(Pauserecorder==0)
a=a+1;
if(a==60)
a=0;
b=b+1;
if(b>60)
b=0;
end
end
end
set(handles.text1,'String',num2str(a));
set(handles.text2,'String',num2str(b));
%resume(R);