def present_fb(self, win, score, objects): """Display the feeback for the game. Requires the window, the score, and a list of the objects already on the screen to be presented with the feedback.""" #determine feedback picture and audio based on score if score: fb = self.green_check sound = self.ding else: fb = self.red_x sound = self.honk #check if objects is a list if type(objects)!=list: print 'objects passed to feedback must be a list; instead got {}'.format(type(objects)) core.quit() #display objects and feedback for object in objects: object.draw() fb.draw() win.flip() sound.play() #wait 2 seconds start_time=self.trialClock.getTime() timer=0 while timer<1: timer= self.trialClock.getTime() - start_time these_keys=event.getKeys(keyList=['escape']) if 'escape' in these_keys: core.quit()
def present_fb(self, win, score, objects): """Display the feeback for the game. Requires the window, the score, and a list of the objects already on the screen to be presented with the feedback.""" #determine fb if score: fb = self.green_check sound = self.ding else: fb = self.red_x sound = self.honk #check if objects is a list if type(objects) != list: print 'objects passed to feedback must be a list; instead got {}'.format( type(objects)) core.quit() #display objects and feedback for object in objects: object.draw() fb.draw() win.flip() sound.play() #wait 2 seconds start_time = self.trialClock.getTime() timer = 0 while timer < 1: timer = self.trialClock.getTime() - start_time these_keys = event.getKeys(keyList=['escape']) if 'escape' in these_keys: core.quit()
def display_stimulus(stimuli, recordtime=None, waittime=None, sound=None, feedback=False): '''This presents stimuli and records relevant experiment times. stimuli = Name of stimulus object created in the setup section recordtime (optional) = Label for the time being recorded waittime (optional) = Amount of time to hold stimulus (i.e., stimulusname) on the screen (s) sound (optional) = Sound to play when stimulus becomes visible feedback = True if feedback is to be provided to user ''' if feedback == True: if trial['CorrectResponse'][presentation] == '1': stimuli[0] = option1_waves #stimuli[0].color = 'green' else: stimuli[1] = option2_waves #stimuli[1].color = 'green' for stim in stimuli: stim.draw() win.flip() if recordtime: times[recordtime] = clock.getTime() if sound: sound.play() if waittime: core.wait(waittime)
def playAndWait(sound, soundPath='', winSound=False, waitFor=-1): """Sound (other than winSound) runs on a separate thread. Waitfor controls how long to pause before resuming. -1 for length of sound""" if not winSoundLoaded: winSound = False if prefs.general['audioLib'] == ['pygame']: #default to using winsound winSound = True if winSound: print 'using winsound to play sound' if waitFor != 0: winsound.PlaySound(sound, winsound.SND_MEMORY) else: #playing asynchronously - need to load the path. if soundPath: winsound.PlaySound(soundPath, winsound.SND_FILENAME | winsound.SND_ASYNC) else: sys.exit("sound path not provided to playAndWait") return else: if waitFor < 0: waitDurationInSecs = sound.getDuration() elif waitFor > 0: waitDurationInSecs = waitFor else: waitDurationInSecs = 0 if waitDurationInSecs > 0: sound.play() core.wait(waitDurationInSecs) sound.stop() return else: sound.play() print 'returning right away' return
def displayInstruction(win, string_instruction, sound, string_time=2, break_flag=True): timer_string = core.CountdownTimer(string_time) sound.play() while (timer_string.getTime() > 0 and break_flag == True): subject_instructions.text = string_instruction subject_instructions.draw() win.flip() # Update screen break_flag = escapeCondition() return break_flag
def break_window(pic,sound): stim.setImage(pic) stim.draw() expwin.flip() sound.play() core.wait(20) textstim.text='Press Enter to continue' textstim.draw() expwin.flip() responsecomplete=False while not responsecomplete: for key in event.getKeys(): if key in ['return']: responsecomplete=True elif key in ['escape']: expwin.close() core.quit() event.clearEvents()
def displayStimulus(stimulusname, recordtime=None, waittime=None, secondstim=None, sound=None): '''Basic function for presenting stimuli. stimulusname = The name of the stimulus created in the setup section recordtime (optional) = The name of the time you are recording (e.g., time image is presented is imgTime) waittime (optional) = Time to hold stimulus (i.e., stimulusname) on screen sound (optional) = Sound to play after stimulus becomes visible''' stimulusname.draw() if secondstim: secondstim.draw() win.flip() if recordtime: times[recordtime] = clock.getTime() if sound: sound.play() if waittime: core.wait(waittime)
def check_keys(self, sound=None): event.clearEvents() repeatTimer = core.CountdownTimer(1.5) keymap = { 'left': self.previous, 'right': self.next, 'up': self.increase, 'down': self.decrease, 'i': self.toggleinc, 'm': self.mark, 'escape': self.cleanQuit } sound.play() while True: theseKeys = event.getKeys(keyList=keymap.keys()) if len(theseKeys) > 0: # at least one key was pressed # grab just the first key pressed key = theseKeys[0] # return action return keymap[key] if repeatTimer.getTime() < 0: sound.play() repeatTimer.reset()
""" # ---------------------- # SOUNDS # ... are continuous so now we can use core.wait(). # ---------------------- # Psychopy sounds from psychopy import sound, core clock = core.Clock() sound_pygame = sound.SoundPygame('beep.wav', secs=0.1) sound = sound.Sound('beep.wav', secs=0.1) sound.play() core.wait(0.5) #playing sound_pygame.play() core.wait(0.5) # winsound sound_winsound = ppc.Sound('beep.wav') sound_winsound.play() core.wait(0.5) """ Exercise:
def waitValidMove( board, sourceSide, sourceConfig, targetConfig, block, blockTimeref, configNum, configTimeref, mN, nError, referenceDuration=None, ): """ wrapper for waitMove that gives feedback in case of invalid moves """ state = board.state.copy() tTime = time.time() sBoard, s, t, movetime, thinkTime = board.waitMove(sourceSide, tTime) # save data for any (invalid) move if sBoard != sourceSide or sourceConfig[s] != targetConfig[t]: wrongSound.play() logging.info( "WRONG MOVE put it back: {} {} {} -> {} {}".format( colorNames[sourceConfig[s]], sideNames[not sBoard], positionNames[t], sideNames[sBoard], positionNames[s], ) ) if debug: showMessage( "put it back: {} {} {} -> {} {}".format( colorNames[sourceConfig[s]], sideNames[not sBoard], positionNames[t], sideNames[sBoard], positionNames[s], ) ) else: message.color = "red" showMessage("X") # wait for correcting error e1 = time.time() while np.any(state != board.state): board.waitEvent() movetime = time.time() - e1 message.color = "white" showMessage("") logging.info("Wrong move corrected") correctSound.play() # this just indicates a correct correction, not a correct move mN = mN + 1 data = open("data/" + ID + "_data.txt", "a") saveList = [ ID, str(block), str(time.time() - blockTimeref), str(configNum), str(mN), str(time.time() - configTimeref), colorNames[sourceConfig[s]], positionNames[s], positionNames[t], "FALSE", str(thinkTime), str(movetime), "\n", ] saves = "\t".join(saveList) data.write(saves) data.close() nError += 1 return waitValidMove( board, sourceSide, sourceConfig, targetConfig, block, blockTimeref, configNum, configTimeref, mN, nError, referenceDuration=referenceDuration, ) else: mN = mN + 1 configTime = time.time() - configTimeref if referenceDuration is None: bNoise = False dt = 0 else: dt = configTime - referenceDuration * mN / 16 pNoise = np.clip(pNoiseMin + dt / dtNoise, pNoiseMin, pNoiseMax) # chance of noise bNoise = pNoise > np.random.uniform() # pNoise chance of True, 1-pNoise chance of False logging.info(" dt={:.3f}, pNoise={:.3f}, noise={}".format(dt, pNoise, bNoise)) logging.info( "CORRECT MOVE: {} {} ({})-> {} {}".format( sideNames[sBoard], positionNames[s], colorNames[sourceConfig[s]], sideNames[not sBoard], positionNames[t], ) ) sound = (correctSound, noiseSound)[bNoise] # choose sound time.time() - blockTimeref data = open("data/" + ID + "_data.txt", "a") saveList = [ ID, str(block), str(time.time() - blockTimeref), str(configNum), str(mN), str(configTime), colorNames[sourceConfig[s]], positionNames[s], positionNames[t], "TRUE", str(thinkTime), str(movetime), ("FALSE", "TRUE")[bNoise], "\n", ] saves = "\t".join(saveList) data.write(saves) data.close() sound.play() # return sBoard, s, t, mN, str(round(time.time()-configTimeref, 2)), nError #insane return sBoard, s, t, mN, configTime, nError
def play_trial_two(sound): textstim.text='2' textstim.draw() expwin.flip() sound.play() core.wait(0.75)
def play_trial_one(sound): textstim.text = '1' textstim.draw() expwin.flip() sound.play() core.wait(1.25)