function varargout = HM(varargin)
% HM MATLAB code for HM.fig
% HM, by itself, creates a new HM or raises the existing
% singleton*.
%
% H = HM returns the handle to a new HM or the handle to
% the existing singleton*.
%
% HM('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in HM.M with the given input arguments.
%
% HM('Property','Value',...) creates a new HM or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before HM_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to HM_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 HM
% Last Modified by GUIDE v2.5 02-Dec-2014 00:35:27
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @HM_OpeningFcn, ...
'gui_OutputFcn', @HM_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 HM is made visible.
function HM_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 HM (see VARARGIN)
% Choose default command line output for HM
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes HM wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = HM_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 start.
function start_Callback(hObject, eventdata, handles)
% hObject handle to start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global myVoice
myVoice = audiorecorder(str2num(get(handles.sf,'string')),8*get(handles.number_of_bits,'value'),1);
% Define callbacks to show when
% recording starts and completes.
myVoice.StartFcn = 'disp(''Start speaking.'')';
myVoice.StopFcn = 'disp(''End of recording.'')';
%myVoice.TimerFcn = @(x,y){axes(handles.axes1);plot(getaudiodata(myVoice))};
record(myVoice);
%
% --- Executes on button press in stop.
function stop_Callback(hObject, eventdata, handles)
% hObject handle to stop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global myVoice
global myRecording
stop(myVoice);
%global myVoice
set(handles.saf,'string',get(handles.sf,'string'));
set(handles.nb,'string',8*get(handles.number_of_bits,'value'));
myRecording = getaudiodata(myVoice);
m=max(abs(max(myRecording)),abs(min(myRecording)));
f=str2num(get(handles.sf,'string'));
time=0:1/f:((size(myRecording,1)-1)/f);
set(handles.d,'string',size(myRecording,1)/f);
axes(handles.axes1)
plot(time,myRecording/m)
xlim([0 ((size(myRecording,1)-1)/f)])
title('Original Signal');
xlabel('Time (Seconds)'); ylabel('amplitude');
axes(handles.axes2);
%specgram(myRecording/m, 1024, f);
%spectrogram(myRecording/m,1024,0,1024,f);
[S,F,T,P] = spectrogram(myRecording/m,str2num(get(handles.window,'string')),str2num(get(handles.overlap,'string')),1024,f);
surf(T,F,10*log10(P),'edgecolor','none'); axis tight;
view(0,90);
xlim([0 ((size(myRecording,1)-1)/f)])
xlabel('Time (Seconds)'); ylabel('Hz');
title('Spectrogram of Original Signal');
%save myVoice myVoice
% --- Executes on button press in pause.
function pause_Callback(hObject, eventdata, handles)
% hObject handle to pause (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global myVoice
pause(myVoice);
% --- Executes on button press in resume.
function resume_Callback(hObject, eventdata, handles)
% hObject handle to resume (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global myVoice
resume(myVoice);
% --- Executes on selection change in number_of_bits.
function number_of_bits_Callback(hObject, eventdata, handles)
% hObject handle to number_of_bits (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns number_of_bits contents as cell array
% contents{get(hObject,'Value')} returns selected item from number_of_bits
% --- Executes during object creation, after setting all properties.
function number_of_bits_CreateFcn(hObject, eventdata, handles)
% hObject handle to number_of_bits (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% 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
function sf_Callback(hObject, eventdata, handles)
% hObject handle to sf (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 sf as text
% str2double(get(hObject,'String')) returns contents of sf as a double
% --- Executes during object creation, after setting all properties.
function sf_CreateFcn(hObject, eventdata, handles)
% hObject handle to sf (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 button press in save.
function save_Callback(hObject, eventdata, handles)
% hObject handle to save (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global myVoice
y=cd;
[filename,pathname] = uiputfile;
cd(pathname)
audiowrite([filename(1:end-4),'.wav'],getaudiodata(myVoice),str2num(get(handles.sf,'string')),'BitsPerSample',8*get(handles.number_of_bits,'value'));
cd(y);
% --- Executes on button press in new.
function new_Callback(hObject, eventdata, handles)
% hObject handle to new (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global myVoice
myVoice=[];
cla(handles.axes1,'reset')
cla(handles.axes2,'reset')
% --- Executes on button press in open.
functi
没有合适的资源?快使用搜索试试~ 我知道了~
record-voice.rar_record_audio
共2个文件
fig:1个
m:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 89 浏览量
2022-09-23
02:55:01
上传
评论
收藏 16KB RAR 举报
温馨提示
record audio from microphone and analyze
资源推荐
资源详情
资源评论
收起资源包目录
record-voice.rar (2个子文件)
record-voice
HM.m 20KB
HMNINH.fig 14KB
共 2 条
- 1
资源评论
寒泊
- 粉丝: 75
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功