gui para grabar
Publicado por Israel (28 intervenciones) el 30/10/2015 04:37:37
Hola amigos, soy nuevo en este foro y les ruego me ayuden. Mi problema es el siguiente, deseo hacer un programa con una gui de matlab que me permita introducir el tiempo de grabación.
Copié el script de un miembro de este foro para grabar audio que resulto muy bien, el problema es que al hacer el GUI me crea otro script, y no puedo pasar la variable del intervalo de tiempo que quiero grabar al otro script, no se si me entienden. Dejo el código del script del GUI primero, y luego del script que realiza la grabacion de audio.
Gracias de antemano.
function varargout = pruebagui(varargin)
% PRUEBAGUI MATLAB code for pruebagui.fig
% PRUEBAGUI, by itself, creates a new PRUEBAGUI or raises the existing
% singleton*.
%
% H = PRUEBAGUI returns the handle to a new PRUEBAGUI or the handle to
% the existing singleton*.
%
% PRUEBAGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PRUEBAGUI.M with the given input arguments.
%
% PRUEBAGUI('Property','Value',...) creates a new PRUEBAGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before pruebagui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to pruebagui_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 pruebagui
% Last Modified by GUIDE v2.5 29-Oct-2015 21:44:51
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @pruebagui_OpeningFcn, ...
'gui_OutputFcn', @pruebagui_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 pruebagui is made visible.
function pruebagui_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 pruebagui (see VARARGIN)
% Choose default command line output for pruebagui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes pruebagui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = pruebagui_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 tiempo_Callback(hObject, eventdata, handles)
% hObject handle to tiempo (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 tiempo as text
% str2double(get(hObject,'String')) returns contents of tiempo as a double
global A;
A=str2double(get(hObject,'String'));
% --- Executes on button press in rec.
function rec_Callback(hObject, eventdata, handles)
global A;
% hObject handle to rec (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
grabacion;
% --- Executes during object creation, after setting all properties.
function tiempo_CreateFcn(hObject, eventdata, handles)
% hObject handle to tiempo (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 [senal_salida,senal_grabada] = grabacion(duracion)
Global A;
%Parametros de salida; senal_salida->objeto
%senal_grabada -> señal de de audio
%Parametros de entrada; duracion-> tiempo para grabar en segundos
fs=44100; %f. muestreo
senal_salida=audiorecorder(fs,16,1);%Creacion del objeto de grabacion
msgbox('Empezando Grabacion',' Grabadora '); %Mensaje de informacion
recordblocking(senal_salida,A);%Grabacion del sonido
msgbox('Terminando Grabacion',' Grabadora ');%Mensaje de informacion
%Paso los valores del objeto a una señal
senal_grabada=getaudiodata(senal_salida, 'single');
%Grabamos y guardamos la señal
wavwrite(senal_grabada,fs,uiputfile({'*.wav'},'Guardar como'));
end
Copié el script de un miembro de este foro para grabar audio que resulto muy bien, el problema es que al hacer el GUI me crea otro script, y no puedo pasar la variable del intervalo de tiempo que quiero grabar al otro script, no se si me entienden. Dejo el código del script del GUI primero, y luego del script que realiza la grabacion de audio.
Gracias de antemano.
function varargout = pruebagui(varargin)
% PRUEBAGUI MATLAB code for pruebagui.fig
% PRUEBAGUI, by itself, creates a new PRUEBAGUI or raises the existing
% singleton*.
%
% H = PRUEBAGUI returns the handle to a new PRUEBAGUI or the handle to
% the existing singleton*.
%
% PRUEBAGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PRUEBAGUI.M with the given input arguments.
%
% PRUEBAGUI('Property','Value',...) creates a new PRUEBAGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before pruebagui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to pruebagui_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 pruebagui
% Last Modified by GUIDE v2.5 29-Oct-2015 21:44:51
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @pruebagui_OpeningFcn, ...
'gui_OutputFcn', @pruebagui_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 pruebagui is made visible.
function pruebagui_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 pruebagui (see VARARGIN)
% Choose default command line output for pruebagui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes pruebagui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = pruebagui_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 tiempo_Callback(hObject, eventdata, handles)
% hObject handle to tiempo (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 tiempo as text
% str2double(get(hObject,'String')) returns contents of tiempo as a double
global A;
A=str2double(get(hObject,'String'));
% --- Executes on button press in rec.
function rec_Callback(hObject, eventdata, handles)
global A;
% hObject handle to rec (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
grabacion;
% --- Executes during object creation, after setting all properties.
function tiempo_CreateFcn(hObject, eventdata, handles)
% hObject handle to tiempo (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 [senal_salida,senal_grabada] = grabacion(duracion)
Global A;
%Parametros de salida; senal_salida->objeto
%senal_grabada -> señal de de audio
%Parametros de entrada; duracion-> tiempo para grabar en segundos
fs=44100; %f. muestreo
senal_salida=audiorecorder(fs,16,1);%Creacion del objeto de grabacion
msgbox('Empezando Grabacion',' Grabadora '); %Mensaje de informacion
recordblocking(senal_salida,A);%Grabacion del sonido
msgbox('Terminando Grabacion',' Grabadora ');%Mensaje de informacion
%Paso los valores del objeto a una señal
senal_grabada=getaudiodata(senal_salida, 'single');
%Grabamos y guardamos la señal
wavwrite(senal_grabada,fs,uiputfile({'*.wav'},'Guardar como'));
end
Valora esta pregunta
0