def feedback(name, needs_text, **kwargs): f = FF.AudStim() # audio stim name already updated with '_aud' if text-based study # remove it for now for consistency (gets returned later) name = name.replace('_aud', '') f.name = name + '_feedback' f.content = name + '.mp3' f.delay = 2 # assign any kwargs (special params that deviate from the norm) for key, value in kwargs.items(): setattr(f, key, value) # are text forms required? if needs_text == True: t = FF.TextStim() t.name = name + '_feedback_text' # use spaces to separate words t.content = name.replace('_', ' ') t.size = '2em' t.alignment = 'center' t.delay = 2 # rename audio stim for clarity f.name = name + '_feedback_aud' # assign any kwargs (special params that deviate from the norm) for key, value in kwargs.items(): setattr(t, key, value) stimulus_objects[t.name] = t stimulus_objects[f.name] = f return f.name
def audio(name, needs_text, **kwargs): aud = FF.AudStim() aud.name = name + '_aud' aud.content = name + '.mp3' aud.barrier = False # assign any kwargs (special params that deviate from the norm) for key, value in kwargs.items(): setattr(aud, key, value) # If this study requires text version of audio stims... if needs_text == True: txt = FF.TextStim() txt.name = name + '_text' #txt.content = name.replace('_',' ') txt.content = name.replace('_', ' ') txt.size = '2em' txt.alignment = 'center' # rename the audio stim for clarity # aud.name = name + '_aud' # assign any kwargs (special params that deviate from the norm) for key, value in kwargs.items(): setattr(txt, key, value) stimulus_objects[name] = txt stimulus_objects[aud.name] = aud return aud.name
def exposure(name, stimuli, needs_text, **kwargs): # exposure templates can handle multiple trials if name not in template_objects.keys(): # only create if first occurrence tt = FF.ExpTemplate() tt.name = name tt.stimuli = [] tt.responses = [] if 'Sent' in name: tt.delay = 1 tt.force_response_delay = "passive" else: tt = template_objects[name] # whether or not the template is new, handle text as needed new_stims = [] if needs_text == True: au = stimuli.pop() tx = au.replace('aud', 'text') stimuli.extend([au, tx]) new_stims.append({'which': stimuli, 'location': [2, 1, 5]}) else: new_stims = stimuli tt.stimuli.extend(new_stims) for key, value in kwargs.items(): setattr(tt, key, value) template_objects[name] = tt
def production(name, stimuli, response, needs_text, **kwargs): # production templates can handle multiple trials if name not in template_objects.keys(): # only create if first occurrence tt = FF.ProdTemplate() tt.name = name tt.stimuli = [] tt.responses = [response] if name.startswith('Sent'): tt.replayable = True if 'Noun' in name: tt.order = 'fixed' else: tt.order = 'random' tt.force_response_delay = "passive" else: tt = template_objects[name] # whether or not the template is new, handle text as needed new_stims = [] if len(stimuli) > 1: # sentences provide audio for verb if needs_text == True: au = stimuli.pop() tx = au.replace('aud', 'text') stimuli.extend([au, tx]) new_stims.append({'which': stimuli, 'location': [5, 1, 2]}) else: new_stims = stimuli tt.stimuli.extend(new_stims) else: # not a list, so append rather than extend new_stims = stimuli tt.stimuli.append(new_stims) for key, value in kwargs.items(): setattr(tt, key, value) template_objects[name] = tt
def create_final_comments_response(): # we only need one comment object... if 'comment' in response_objects.keys(): return comment_box = FF.TextResponse() comment_box.name = 'comment' comment_box.instruction = 'If you have any comments you would like to leave about this HIT, please enter them below (limit {:d} characters).'.format( comment_box.max_char) comment_box.required = False response_objects['comment'] = comment_box
def voice(): # we only need one voice object... if 'voice' in response_objects.keys(): return 'voice' # create an audio response object voice = FF.AudResponse() voice.name = 'voice' response_objects['voice'] = voice return 'voice'
def image(name, **kwargs): img = FF.ImgStim() img.name = name + '_img' img.content = name.replace('_img', '') + '.png' # assign any kwargs (special params that deviate from the norm) for key, value in kwargs.items(): setattr(img, key, value) stimulus_objects[img.name] = img return img.name
def video(target, **kwargs): vid = FF.VidStim() vid.name = target + '_vid' vid.content = target + '.mp4' # assign any kwargs (special params that deviate from the norm) for key, value in kwargs.items(): setattr(vid, key, value) stimulus_objects[vid.name] = vid return vid.name
def instruction(name, content, **kwargs): tt = FF.InstrTemplate() # all instructions require unique objects tt.name = name try: tt.stimuli = content except: tt.stimuli = [['Alien', content]] for key, value in kwargs.items(): setattr(tt, key, value) template_objects[name] = tt
def text(name, content, **kwargs): text = FF.TextStim() text.name = name + '_text' text.content = content text.alignment = 'center' # assign any kwargs (special params that deviate from the norm) for key, value in kwargs.items(): setattr(text, key, value) stimulus_objects[text.name] = text return text.name
def create_AFC(choices, stimuli_nature, instruction, **kwargs): afc = FF.ChoiceResponse() afc.name = '_'.join(choices) afc.target = '%s:' + choices[0] afc.instruction = instruction afc.choices = ['%s:' + choice for choice in choices] for key, value in kwargs.items(): setattr(afc, key, value) #response_objects[target] = afc response_objects[afc.name] = afc return afc.name
def textbox(name='textbox', **kwargs): # usually only need one textbox object, but allow for others if name == 'textbox' and 'textbox' in response_objects.keys(): return 'textbox' # create a textbox response object textbox = FF.TextResponse() textbox.name = name # assign any kwargs (special params that deviate from the norm) for key, value in kwargs.items(): setattr(textbox, key, value) response_objects[name] = textbox return name
def create_2AFC(target, foil, **kwargs): afc = FF.ChoiceResponse() afc.name = target t = re.sub(r'\d+$', '', target) # remove digits at end of target afc.target = target.replace('2x', '%s:') afc.choices = [afc.target, '%s:' + foil] afc.instruction = 'Click on the video that matches the sentence I say:' # assign any kwargs (special params that deviate from the norm) for key, value in kwargs.items(): setattr(afc, key, value) response_objects[target] = afc return target
def lumi(): a = FF.ImgStim() a.name = 'Alien' a.content = 'alien_new.png' a.width = '70%' stimulus_objects[a.name] = a fb = FF.TextStim() fb.name = 'Lumi_says' fb.content = '<b>Now listen to how Lumi would say it</b>' fb.size = '1.25em' fb.alignment = 'center' fb.delay = 0.7 stimulus_objects[fb.name] = fb e = FF.ImgStim() e.name = 'empty' e.content = 'whitespace.png' e.width = '5%' stimulus_objects[e.name] = e return [a.name, fb.name, e.name]
def comprehension(name, stimuli, response, needs_text, **kwargs): tt = FF.CompTemplate() tt.name = name tt.stimuli = stimuli tt.responses = [response] tt.force_response_delay = "passive" if needs_text == True: au = stimuli.pop() tx = au.replace('aud', 'text') tt.stimuli = [] tt.stimuli.append({'which': [au, tx], 'location': [1, 2]}) for key, value in kwargs.items(): setattr(tt, key, value) template_objects[name] = tt
def create_4AFC(target, foils, **kwargs): afc = FF.ChoiceResponse() afc.name = target t = re.sub(r'\d+$', '', target) # remove digits at end of target afc.target = t.replace( '4x', '%s:') # replace '4x' with '%s' (clickable stim format) afc.instruction = 'Click on the image below that matches the word I say:' afc.choices = [afc.target] for foil in foils: foil = '%s:' + foil afc.choices.append(foil) # assign any kwargs (special params that deviate from the norm) for key, value in kwargs.items(): setattr(afc, key, value) response_objects[target] = afc return target
def create_survey_trial(name, stimuli, response, **kwargs): if name not in template_objects.keys(): # only create if first occurrence tt = FF.ProdTemplate() tt.name = name tt.stimuli = [] tt.responses = [response] tt.order = 'fixed' tt.force_response_delay = "passive" else: tt = template_objects[name] # stimuli tt.stimuli = stimuli # other settings for key, value in kwargs.items(): setattr(tt, key, value) template_objects[name] = tt
def block(info, covers, templates, ends, **kwargs): #name, repeat, label_info, feedback, needs_text = info name, repeat, ling_unit, feedback, needs_text = info b = FF.Block() b.name = name if repeat and int(repeat) > 1: b.repeat = int(repeat) b.cover_trials = covers b.trial_templates = templates b.end_trials = ends #if 'prod' in label_info and feedback == True: if name.lower().startswith("speak") and feedback == "FB": b.order = 'alternate' else: b.order = 'random' for key, value in kwargs.items(): setattr(b, key, value) block_objects[name] = b return b
def feedback(name, stimuli, needs_text, **kwargs): # feedback templates can handle multiple trials if name not in template_objects.keys(): # only create if first occurrence tt = FF.FeedBackTemplate() tt.name = name tt.stimuli = [] tt.responses = [] else: tt = template_objects[name] # whether or not the template is new... # [img,aud] --> [img,'Lumi_says',aud] stimuli.insert(1, 'Lumi_says') # handle text as needed if needs_text == True: au = stimuli.pop() tx = au.replace('aud', 'text') stimuli.extend([tx, au]) # [img,'Lumi_says',aud] --> [img,'empty','Lumi_says',aud] else: stimuli.insert(1, 'empty') tt.stimuli.append({'which': stimuli, 'location': [2, 5, 8, 1]}) for key, value in kwargs.items(): setattr(tt, key, value) template_objects[name] = tt
def create_final_comments_trial(): tt = FF.TextRespTemplate() tt.name = 'Comments' tt.stimuli = [] tt.responses = ['comment'] template_objects[tt.name] = tt
def create_final_comments_block(): b = FF.Block() b.name = 'Comments' b.trial_templates = ['Comments'] block_objects[b.name] = b return b