How can I ask a user to compare two different audio files many consecutive times while using a GUI?

4 ビュー (過去 30 日間)
I will be asking users to listen to two short audio files and want them to tell me which file they prefer. I would also like users to be able to listen to each file as many times as they would like before answering.
In addition to another .m file, I created the following GUI (which is where I am struggling the most - I'm new to coding/MATLAB in general however):
I realize the following code is incomplete given my ultimate goal, but it's a starting point for the main script. In the end this will loop back to the start after the user makes a choice (and the choice is stored), with two new audio files in the GUI:
%Using a matrix for all possible comparisons, round robin style. Hopefully
%useful for playing files from the computer.
%(change the contents of the array to match the range of cues, e.g.
%cueOrder = nchoosek([50:71],2);
cueOrder = nchoosek([0.0, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5],2);
randomOrder = randperm(size(cueOrder,1)); %random order of 1 - 21
cueOrder = cueOrder(randomOrder,:); %randomly organizes rows together
%attempt at a loop to call files and possibly associate them with a figure
i = 1;
while i<=21
%name reverberation time
reverbTime1 = num2str(cueOrder(i,1));
reverbTime2 = num2str(cueOrder(i,2));
i = i+1;
% zero pad if necessary to get the proper name
if length(reverbTime1)==1
reverbTime1 = [reverbTime1,'.0'];
end
if length(reverbTime2)==1
reverbTime2 = [reverbTime2,'.0'];
end
%create file names
stimulusFile1 = ['\Andrew\Music Stim Example\Stimuli\Beet_',reverbTime1,'.wav'];
stimulusFile2 = ['\Andrew\Music Stim Example\Stimuli\Beet_',reverbTime2,'.wav'];
% play files - plays, but not surprisingly plays all 21 loops. Need help with GUI etc
[stimulus1,fs1] = audioread(stimulusFile1);
[stimulus2,fs2] = audioread(stimulusFile2);
sound(stimulus1,fs1);
sound(stimulus2,fs2);
%trash ideas that aren't working
%global response;
%response = stimulusFile1;
end
My thought was I could just throw a variable created in this file into the GUI's code and it would work, but that's clearly not the case. I'm not sure how to pass information over to the GUI from this little script and everything I've tried (aside from things like disp('hello')) gives errors with the GUI. These errors are thrown when I put sound(stimulus1,fs1) under PlayButton1 (the left play button). I'm not too surprised, since I'm sure it isn't that simple - but just about anything I write under there causes problems:
Error in cuepreference>PlayButton1_Callback (line 84)
sound(stimulus1,fs1)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in cuepreference (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)cuepreference('PlayButton1_Callback',hObject,eventdata,guidata(hObject))
Ultimately, I'd probably like to pass some information back from the GUI too where it can then be stored (i.e. the user's choice or preference). In the meantime, the GUI script is pretty empty because I can't figure out how to get anything happening without breaking it! (It doesn't work right now because of the sound(stimulus1,fs1) in there under PlayButton1.
function varargout = cuepreference(varargin)
%CUEPREFERENCE MATLAB code file for cuepreference.fig
% CUEPREFERENCE, by itself, creates a new CUEPREFERENCE or raises the existing
% singleton*.
%
% H = CUEPREFERENCE returns the handle to a new CUEPREFERENCE or the handle to
% the existing singleton*.
%
% CUEPREFERENCE('Property','Value',...) creates a new CUEPREFERENCE using the
% given property value pairs. Unrecognized properties are passed via
% varargin to cuepreference_OpeningFcn. This calling syntax produces a
% warning when there is an existing singleton*.
%
% CUEPREFERENCE('CALLBACK') and CUEPREFERENCE('CALLBACK',hObject,...) call the
% local function named CALLBACK in CUEPREFERENCE.M with the given input
% arguments.
%
% *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 cuepreference
% Last Modified by GUIDE v2.5 17-Jul-2018 13:29:37
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @cuepreference_OpeningFcn, ...
'gui_OutputFcn', @cuepreference_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 cuepreference is made visible.
function cuepreference_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 unrecognized PropertyName/PropertyValue pairs from the
% command line (see VARARGIN)
% Choose default command line output for cuepreference
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes cuepreference wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = cuepreference_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 PlayButton1.
function PlayButton1_Callback(hObject, eventdata, handles)
% hObject handle to PlayButton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
sound(stimulus1,fs1)
% --- Executes on button press in PreferButton1.
function PreferButton1_Callback(hObject, eventdata, handles)
% hObject handle to PreferButton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in PlayButton2.
function PlayButton2_Callback(hObject, eventdata, handles)
% hObject handle to PlayButton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in StartButton.
function StartButton_Callback(hObject, eventdata, handles)
% hObject handle to StartButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in QuitButton.
function QuitButton_Callback(hObject, eventdata, handles)
% hObject handle to QuitButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in PreferButton2.
function PreferButton2_Callback(hObject, eventdata, handles)
% hObject handle to PreferButton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I hope this isn't too stupid - all of my coding experience up to this point has been pretty limited and it's been a while. I've tried to figure this out on my own for quite a while and haven't had any luck - maybe I'm using all the wrong search terms! If someone could help me with just one of the push buttons (and passing info back and forth) I'm sure I could figure the rest out!

回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by