Hi I this is my first time using psychopy. I am loving the program but have come across a problem I cant figure out a solution to and was hoping someone could help.
I thought maybe there might be some way of reworking the microphone response component so that it is looking at the sound being played rather than looking for a microphone (which I don't have) but couldn't work out how to do that.
Any help that anyone can offer would be hugely appreciated.
from __future__ import division # so that 1/3=0.333 instead of 1/3=0
from psychopy import visual, core, data, event, logging, sound, gui
from psychopy.constants import * # things like STARTED, FINISHED
import numpy as np # whole numpy lib is available, prepend 'np.'
from numpy import sin, cos, tan, log, log10, pi, average, sqrt, std, deg2rad, rad2deg, linspace, asarray
from numpy.random import random, randint, normal, shuffle
import os # handy system and path functions
# Store info about the experiment session
expName = 'Working_running_adding_sound_measurer' # from the Builder filename that created this script
expInfo = {u'session': u'001', u'participant': u''}
dlg = gui.DlgFromDict(dictionary=expInfo, title=expName)
if dlg.OK == False: core.quit() # user pressed cancel
expInfo['date'] = data.getDateStr() # add a simple timestamp
expInfo['expName'] = expName
# Setup filename for saving
filename = 'data/%s_%s_%s' %(expInfo['participant'], expName, expInfo['date'])
# An ExperimentHandler isn't essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName, version='',
extraInfo=expInfo, runtimeInfo=None,
originPath=None,
savePickle=True, saveWideText=True,
dataFileName=filename)
#save a log file for detail verbose info
logFile = logging.LogFile(filename+'.log', level=logging.EXP)
logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file
endExpNow = False # flag for 'escape' or other condition => quit the exp
# Start Code - component code to be run before the window creation
# Setup the Window
win = visual.Window(size=(1280, 1024), fullscr=True, screen=0, allowGUI=True, allowStencil=False,
monitor='testMonitor', color='black', colorSpace='rgb',
blendMode='avg', useFBO=True,
units='pix')
# store frame rate of monitor if we can measure it successfully
expInfo['frameRate']=win.getActualFrameRate()
if expInfo['frameRate']!=None:
frameDur = 1.0/round(expInfo['frameRate'])
else:
frameDur = 1.0/60.0 # couldn't get a reliable measure so guess
# Initialize components for Routine "TargetSound"
TargetSoundClock = core.Clock()
Words = sound.Sound(u'LIST1 with 1 sec words.wav')
polygon = visual.Polygon(win=win, name='polygon',units='pix',
edges = 100, size=[3, 3],
ori=0, pos=[0,0],
lineWidth=.1, lineColor=[1,1,1], lineColorSpace='rgb',
fillColor='red', fillColorSpace='rgb',
opacity=1,interpolate=True)
mouse = event.Mouse(win=win)
x, y = [None, None]
# Create some handy timers
globalClock = core.Clock() # to track the time since experiment started
routineTimer = core.CountdownTimer() # to track time remaining of each (non-slip) routine
# set up handler to look after randomisation of conditions etc
trials = data.TrialHandler(nReps=1, method='sequential',
extraInfo=expInfo, originPath=None,
trialList=data.importConditions('workedXY20sec.xlsx'),
seed=None, name='trials')
thisExp.addLoop(trials) # add the loop to the experiment
thisTrial = trials.trialList[0] # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb=thisTrial.rgb)
if thisTrial != None:
for paramName in thisTrial.keys():
exec(paramName + '= thisTrial.' + paramName)
for thisTrial in trials:
currentLoop = trials
# abbreviate parameter names if possible (e.g. rgb = thisTrial.rgb)
if thisTrial != None:
for paramName in thisTrial.keys():
exec(paramName + '= thisTrial.' + paramName)
#------Prepare to start Routine "TargetSound"-------
t = 0
TargetSoundClock.reset() # clock
frameN = -1
routineTimer.add(0.010000)
# update component parameters for each repeat
if trials.thisTrialN == 1: Words.play()
# i.e. only on the very first trial, start the sound,
# which will keep playing in the background for 90 s.
polygon.setPos(TargetXY)
# setup some python lists for storing info about the mouse
# keep track of which components have finished
TargetSoundComponents = []
TargetSoundComponents.append(polygon)
TargetSoundComponents.append(mouse)
for thisComponent in TargetSoundComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
#-------Start Routine "TargetSound"-------
continueRoutine = True
while continueRoutine and routineTimer.getTime() > 0:
# get current time
t = TargetSoundClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *polygon* updates
if t >= 0.0 and polygon.status == NOT_STARTED:
# keep track of start time/frame for later
polygon.tStart = t # underestimates by a little under one frame
polygon.frameNStart = frameN # exact frame index
polygon.setAutoDraw(True)
elif polygon.status == STARTED and t >= (0.0 + (.01-win.monitorFramePeriod*0.75)): #most of one frame period left
polygon.setAutoDraw(False)
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
routineTimer.reset() # if we abort early the non-slip timer needs reset
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in TargetSoundComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
#-------Ending Routine "TargetSound"-------
for thisComponent in TargetSoundComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
currentT = globalClock.getTime()
WrdVol = Words.getVolume()
# store data for trials (TrialHandler)
x, y = mouse.getPos()
buttons = mouse.getPressed()
trials.addData('mouse.x', x)
trials.addData('mouse.y', y)
trials.addData('Timer',currentT)
trials.addData('Sound',WrdVol)
thisExp.nextEntry()
# completed 1 repeats of 'trials'
win.close()
core.quit()