class Feedback(): NEGATIVE_FEEDBACK_SOUND = stimuli.Audio('wrong-answer.ogg') POSITIVE_FEEDBACK_SOUND = stimuli.Audio('right-answer.ogg') def positive(self): self.POSITIVE_FEEDBACK_SOUND.play() exp.clock.wait(200) def negative(self): self.NEGATIVE_FEEDBACK_SOUND.play() exp.clock.wait(1000)
# load stimuli mapsounds = dict() mapspeech = dict() maptext = dict() mappictures = dict() mapvideos = dict() for listfile in sys.argv[1:]: stimlist = csv.reader(io.open(listfile, 'r', encoding='utf-8')) bp = op.dirname(listfile) for row in stimlist: onset, stype, f = int(row[0]), row[1], row[2] if stype == 'sound': if not f in mapsounds: mapsounds[f] = stimuli.Audio(op.join(bp, f)) mapsounds[f].preload() events.put((onset, 'sound', f, mapsounds[f])) elif stype == 'picture': if not f in mappictures: mappictures[f] = stimuli.Picture(op.join(bp, f)) mappictures[f].preload() events.put((onset, 'picture', f, mappictures[f])) events.put((onset + PICTURE_DURATION, 'blank', 'blank', bs)) elif stype == 'video': if not f in mapvideos: mapvideos[f] = stimuli.Video(op.join(bp, f)) mapvideos[f].preload() event.put((onset, 'video', f, mapvideos[f])) elif stype == 'text': if not f in maptext:
from expyriment import design, control, stimuli WORD_RESPONSE_KEY = 'f' NONW_RESPONSE_KEY = 'j' MAX_RESPONSE_DELAY = 2000 exp = design.Experiment(name="Lexical Decision", text_size=40) control.initialize(exp) # prepare the stimuli words = ['bonjour.wav', 'chien.wav', 'président.wav'] pseudos = ['lopadol.wav', 'mirance.wav', 'clapour.wav' ] trials = [] for item in words: trials.append(("W", item, stimuli.Audio(item))) for item in pseudos: trials.append(("P", item, stimuli.Audio(item))) random.shuffle(trials) cue = stimuli.FixCross(size=(50, 50), line_width=4) blankscreen = stimuli.BlankScreen() instructions = stimuli.TextScreen("Instructions", f"""When you hear a stimulus, your task to decide, as quickly as possible, whether it is a word or not. if it is a word, press '{WORD_RESPONSE_KEY.upper()}' if it is a non-word, press '{NONW_RESPONSE_KEY.upper()}' Press the space bar to start.""")
exp.clock.wait(800) #CALIBRATION if not (calibration is None): calibrage = "Nous allons faire un calibrage" calibration = stimuli.TextLine(calibrage, text_font=TEXT_FONT, text_size=TEXT_SIZE, text_colour=TEXT_COLOR, background_colour=BACKGROUND_COLOR) calibration.present() exp.clock.wait(1500) calibration_sound = op.join(STIM_DIR, 'ph10.wav') #instruction = stimuli.Audio(op.join(bp, test_sound)) instruction = stimuli.Audio(calibration_sound) instruction.preload() instruction.present() fs.present() exp.clock.wait(2100) #INSTRUCTIONS elif not (splash_screen is None): if op.splitext(splash_screen)[1] == '.csv': instructions = csv.reader(io.open(splash_screen, 'r', encoding='utf-8'), delimiter='\t') for instruction_line in instructions: instruction_duration, stype, instruction_line = instruction_line[ 0], instruction_line[1], instruction_line[2] if stype == 'box':
SCAN_TRIGGER_LTP_ADDRESS = None # None = USB (keyboard emulation) # DESIGN exp = design.Experiment("Motor Imagery (Swimming)") control.initialize(exp) protocol = StimulationProtocol("time") fixcross = stimuli.FixCross() fixcross.preload() blocks = { "rest": [ stimuli.TextLine("REST", text_size=70, text_colour=misc.constants.C_RED, text_font="monospace"), stimuli.Audio("stimuli/rest.wav") ], "swim": [ stimuli.TextLine("SWIM", text_size=70, text_colour=misc.constants.C_GREEN, text_font="monospace"), stimuli.Audio("stimuli/swim.wav") ] } for condition in blocks: protocol.add_condition(condition) blocks[condition][0].preload() blocks[condition][1].preload()
import sys from expyriment import design, control, stimuli, io, misc AUDIO = sys.argv[1] exp = design.Experiment(name="Le_Petit_Prince") control.set_develop_mode(False) control.defaults.open_gl = 2 control.defaults.window_mode = True control.defaults.window_size = (1920, 1080) ## control.initialize(exp) stim = stimuli.Audio(AUDIO) stim.preload() fixcrossGreen = stimuli.FixCross(size=(45, 45), line_width=5, colour=(0, 255, 0)) fixcrossGreen.preload() fixcrossGrey = stimuli.FixCross(size=(45, 45), line_width=3, colour=(192, 192, 192)) fixcrossGrey.preload() def clear_screen(): exp.screen.clear() exp.screen.update()
def run_experiment(self): game1 = io.GamePad(0, True, True) #init joystick # define headers for expyriment log file output table (we currently don't use it, # but if we want - we can improve it and use it if we want self.exp.data_variable_names = ["time", "digit", "position", "targetType", "response", "rt",\ "responseType", "is success", "n", "order", "is practice"] self.trials_number = len(self.positions_list_text) if len( self.positions_list_text) > 0 else len(self.digit_list) # create grid grid = Grid(len(self.positions_list_text))\ for trial in range(self.trials_number): target = None if self.with_audio_stimuli: # we have auditory stimuli in this block # so we initialize the auditory stimulus self.digit = self.digit_list[trial] audio = stimuli.Audio(self.sounds_folder + str(int(self.digit)) + self.sound_files_suffix) canvas = stimuli.BlankScreen() time_delay_for_isi = 0 if self.with_visual_stimuli: # we have visual stimuli in this block # so we initialize the visual stimuus self.position_text = self.positions_list_text[trial] self.position = Grid.positions_locations[self.position_text] target = stimuli.Rectangle((30, 30), misc.constants.C_BLACK, 0, None, None, self.position) time_delay_for_isi += target.preload() time_delay_for_isi += target.plot(canvas) #prepare grid on canvas time_delay_for_isi += grid.paint_grid(canvas) #show canvas time_delay_for_isi += canvas.present() if self.with_audio_stimuli: audio.play( ) # we have auditory stimuli so we play the letter now utils.push_sample_current_time(self.outlet,\ ["stimulus_task_nBack_type_letter_letter_" + str(self.digit)]) if self.with_visual_stimuli: utils.push_sample_current_time(self.outlet, \ ["stimulus_task_nBack_type_vis_location_" + self.position_text]) # wait for subject's response. Wait only for "duration" time key, rt = game1.wait_press(self.possible_joystick_buttons, self.stimuli_duration, process_control_events=False) if key is None: # we have now waited stimuliDuration so we can remove stimulus canvas = stimuli.BlankScreen() time_delay_for_isi += grid.paint_grid(canvas) time_delay_for_isi += canvas.present() time_delay_after_stimuli = 0 time_delay_after_stimuli += grid.paint_grid(canvas) time_delay_after_stimuli += canvas.present() if target != None: time_delay_after_stimuli += target.unload() # we wait for subject to respond (but only for the ISI duration) key, rt = game1.wait_press(self.possible_joystick_buttons, self.ISI\ - time_delay_after_stimuli- time_delay_for_isi) if key != None: # we get here if subject has responded - so we need to wait for the rest of # the ISI utils.push_sample_current_time( self.outlet, ["keyPressed_task_nBack_key_" + str(key)]) # wait the rest of the ISI before going on self.exp.clock.wait( self.ISI - rt - time_delay_for_isi - time_delay_after_stimuli ) # wait the rest of the ISI before going on rt = rt + self.stimuli_duration + time_delay_after_stimuli else: # subject responded and stimulus duration hasn't ended utils.push_sample_current_time( self.outlet, ["keyPressed_task_nBack_key_" + str(key)]) # wait the rest of the stimulus duration before going on self.exp.clock.wait( self.stimuli_duration - rt) # wait the rest of the stimuliDuration before removing # we have now waited stimuliDuration so we can remove stimulus canvas = stimuli.BlankScreen() time_delay_for_isi += grid.paint_grid(canvas) time_delay_for_isi += canvas.present() if target != None: time_delay_for_isi += target.unload() # wait for the ISI before going on self.exp.clock.wait(self.ISI - time_delay_for_isi) self.save_trial_data(key, rt, trial) self.show_feedback_if_needed()
At each trial, a brief sound is played and the participant must press a key as quickly as possible. """ import random from expyriment import design, control, stimuli N_TRIALS = 50 MIN_WAIT_TIME = 1000 MAX_WAIT_TIME = 2000 MAX_RESPONSE_DELAY = 2000 exp = design.Experiment(name="Visual Detection", text_size=40) control.initialize(exp) target = stimuli.Audio('click.wav') blankscreen = stimuli.BlankScreen() instructions = stimuli.TextScreen( "Instructions", f"""Your task is to detect a sound Press a key as quickly as possible when you hear any sound. There will be {N_TRIALS} trials """ ) exp.add_data_variable_names(['trial', 'wait', 'respkey', 'RT']) control.start(skip_ready_screen=True) instructions.present() exp.keyboard.wait() for i_trial in range(N_TRIALS): blankscreen.present()
control.initialize(exp) ## preparation block = design.Block() for number in (TARGETS * N_TRIALS_PER_TARGET): t = design.Trial() t.set_factor('number', number) t.set_factor('is_even', number % 2 == 0) t.add_stimulus(stimuli.TextLine(str(number))) block.add_trial(t) block.shuffle_trials(max_repetitions=1) cue = stimuli.FixCross(size=(50, 50), line_width=4) blankscreen = stimuli.BlankScreen() feedback = stimuli.Audio(BUZZER_SOUND) instructions = stimuli.TextScreen( "Instructions", f"""When you'll see a number, your task to decide, as quickly as possible, whether it is even or odd. if it is even, press '{EVEN_RESPONSE_KEY}' if it is odd, press '{ODD_RESPONSE_KEY}' There will be {N_TRIALS_PER_TARGET * len(TARGETS)} trials in total. Press the space bar to start.""") exp.add_data_variable_names( ['number', 'is_even', 'respkey', 'RT', 'is_correct'])
NTRIALS = 20 ITI = 1000 # inter trial interval MAX_RESPONSE_TIME = 2000 AUDIO_STIMULUS = 'click.wav' exp = design.Experiment(name="AudioVisual Detection") control.initialize(exp) blankscreen = stimuli.BlankScreen() visual_trial = design.Trial() visual_trial.add_stimulus(stimuli.FixCross(size=(50, 50), line_width=4)) audio_trial = design.Trial() audio_trial.add_stimulus(stimuli.Audio(AUDIO_STIMULUS)) visual_block = design.Block("visual") for i in range(NTRIALS): visual_block.add_trial(visual_trial) exp.add_block(visual_block) audio_block = design.Block("audio") for i in range(NTRIALS): audio_block.add_trial(audio_trial) exp.add_block(audio_block) audiovisual_block = design.Block("audiovisual") for i in range(NTRIALS // 2): audiovisual_block.add_trial(audio_trial) audiovisual_block.add_trial(visual_trial)
for colname in ['Category', 'Frequency', 'Item'] ]) # randomize the rows of trial_stims so that the stimuli are presented in a random order trial_stims = trial_stims.sample(frac=1).reset_index(drop=True) ####################################################################### # Prepare the experiment exp = design.Experiment(name="Lexical Decision Task", text_size=40) control.initialize(exp) exp.add_data_variable_names( list(trial_stims.columns) + ['response_key', 'rt', 'is_correct']) negative_feedback = stimuli.Audio(AUDIO_FEEDBACK_FILE_PATH) ########################################################################### # Run the experiment control.start(skip_ready_screen=True) stimuli.TextScreen("Instructions", INSTRUCTIONS).present() exp.keyboard.wait_char(' ') for _, t in trial_stims.iterrows(): exp.screen.clear() exp.screen.update() stim = stimuli.TextLine(t.Item) exp.clock.wait(INTER_TRIAL_INTERVAL - stim.preload()) stim.present()