【语音处理】基于matlab GUI实时录音时域频域图【含Matlab源码 064期 】

158 阅读3分钟

一、简介

基于matlab GUI实时录音时域频域图

二、源代码

function varargout = music_show1(varargin)
% MUSIC_SHOW1 MATLAB code for music_show1.fig
%      MUSIC_SHOW1, by itself, creates a new MUSIC_SHOW1 or raises the existing
%      singleton*.
%
%      H = MUSIC_SHOW1 returns the handle to a new MUSIC_SHOW1 or the handle to
%      the existing singleton*.
%
%      MUSIC_SHOW1('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in MUSIC_SHOW1.M with the given input arguments.
%
%      MUSIC_SHOW1('Property','Value',...) creates a new MUSIC_SHOW1 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before music_show1_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to music_show1_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 music_show1

% Last Modified by GUIDE v2.5 11-May-2021 12:02:06

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @music_show1_OpeningFcn, ...
                   'gui_OutputFcn',  @music_show1_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 music_show1 is made visible.
function music_show1_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 music_show1 (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes music_show1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
clear global variables
global hm
warning off
 
A=linspace(0,6.3,1000);
xk=9*cos(pi/2);
yk=9*sin(pi/2);
plot([xk/9*8 xk/9*7],[yk/9*8 yk/9*7],'k')
hold on
text(xk-0.3,yk,'0')
for k=1:5;
xk=9*cos(-pi/20*(2*k-1)+pi/2);
yk=9*sin(-pi/20*(2*k-1)+pi/2);
plot([xk/9*7.5 xk/9*7],[yk/9*7.5 yk/9*7],'k')
xk=9*cos(-pi/20*(2*k)+pi/2);
yk=9*sin(-pi/20*(2*k)+pi/2);
plot([xk/9*8 xk/9*7],[yk/9*8 yk/9*7],'k')
text(xk,yk,num2str(2*k))
end
for k=1:5;
xk=9*cos(pi/20*(2*k-1)+pi/2);
yk=9*sin(pi/20*(2*k-1)+pi/2);
plot([xk/9*7.5 xk/9*7],[yk/9*7.5 yk/9*7],'k')
xk=9*cos(pi/20*(2*k)+pi/2);
yk=9*sin(pi/20*(2*k)+pi/2);
plot([xk/9*8 xk/9*7],[yk/9*8 yk/9*7],'k')
if k<5
text(xk-1,yk,num2str(-2*k))
else
    text(xk-1,yk,num2str(-2*k))
end
end

tm=pi/2;
xm3=6.0*cos(tm);
ym3=6.0*sin(tm);
xm2=xm3/2+0.5*cos(tm-pi/2);
ym2=ym3/2+0.5*sin(tm-pi/2);
xm4=xm3/2-0.5*cos(tm-pi/2);
ym4=ym3/2-0.5*sin(tm-pi/2);
hm=fill([0 xm2 xm3 xm4 0],[0 ym2 ym3 ym4 0],'k');
axis off
axis([-10 10 -8 10])
axis equal
% --- Outputs from this function are returned to the command line.
function varargout = music_show1_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 edit6_Callback(hObject, eventdata, handles)
% hObject    handle to edit6 (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 edit6 as text
%        str2double(get(hObject,'String')) returns contents of edit6 as a double


% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (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 pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%% 进行播放
global music_path
if isempty(music_path)
    warndlg('请进行声音的录入,再进行播放');
    return;
end
[h, Fs] = audioread(music_path);
h = h * 10;
sound(h,Fs);


% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton11 (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 music_path

myvoice=getaudiodata(R);
audiowrite('myvoice.wav',myvoice,44100); % 保存相关音频数据
set(handles.edit1,'String','myvoice.wav');
music_path = 'myvoice.wav';
set(handles.edit1,'enable','off')


% --- Executes during object creation, after setting all properties.
function axes4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to axes4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: place code in OpeningFcn to populate axes4

三、运行结果

在这里插入图片描述

四、备注

版本:2014a