Exemple #1
0
    def run(self):
        # set up presentation window color, and size
        bgcolor = 'black'
        txtcolor = 'white'
        self.win = visual.Window(fullscr=True, color=bgcolor)
        #self.win = visual.Window((1200, 900), color=bgcolor)  # temporary presentation window setup, exchange for line above when running actual experiment
        self.text = visual.TextStim(self.win, color=txtcolor)

        words = [
            audio.read(self.stimuli_prefix + str(i + 1) + '.wav')
            for i in range(24)
        ]
        recordings = []

        self.text.text = '||'
        self.text.draw()
        self.win.flip()
        audio.play(audio.read(self.instructions_folder + self.mode + '.wav'),
                   wait=True)
        key = event.waitKeys(keyList=['return'])

        for word in words:
            self.text.text = '+'
            self.text.draw()
            self.win.flip()
            audio.play(word, wait=True)
            self.text.text = '-'
            self.text.draw()
            self.win.flip()
            recordings += [audio.record(((len(word) / 44100) + 1), wait=True)]

        for i in range(len(words)):
            audio.write(self.log_prefix + str(i + 1) + '.wav', recordings[i])

        self.win.close()
Exemple #2
0
def run_net():
    while True:
        cfinished.clear()
        _globals.nn.on_timer()
        _globals.t += 1
        max = 0.0
        _id = -1
        avg=0
        data=read(exception_on_overflow = False)
        for s in data:
            #print(s)
            _globals.nn.neurons[96+1+s].activate(0,1.0)
            _globals.nn.on_timer()
        cnt=0
        #for c in np.ndarray.flatten(get_video()):
        #    _globals.nn.neurons[96+256+cnt].activate(0,c/255.0)
        #   cnt+=1
        _globals.nn.on_timer()
        for i, n in enumerate(_globals.nn.neurons[:96]):
            if n.out > max:
                max = n.out
                _id = i
                avg=avg+n.cur
        if _id != -1:
            print(chr(_id+ord(' ')), end="")
        avg/=96.0
        line.set_ydata(avg)
        line.set_xdata(_globals.t)
        ax.relim()
        ax.autoscale_view(True, True, True)
        plt.draw()
        cfinished.set()
Exemple #3
0
def samp(n):
       savegain = audio.getoutgain()
       try:
               audio.setoutgain(0)
               x = raw_input('Hit Enter to sample ' + `n` + ' seconds: ')
               return audio.read(n*RATE)
       finally:
               audio.setoutgain(savegain)
Exemple #4
0
 def record(a):
     p = a.back
     size = int(10.0 * 8192.0 * p.recordsize.val)
     a.val = 1.0
     a.fixact()
     panel.drawpanel()
     audio.setoutgain(0)
     p.sample = audio.read(size)
     a.val = 0.0
     a.fixact()
Exemple #5
0
    def run(self):
        # set up presentation window color, and size
        bgcolor = 'black'
        txtcolor = 'white'
        self.win = visual.Window(fullscr=True, color=bgcolor)
        #self.win = visual.Window((1200, 900), color=bgcolor)  # temporary presentation window setup, exchange for line above when running actual experiment
        self.text = visual.TextStim(self.win, color=txtcolor)

        with open(self.trials_fname, 'rU') as trial_file:
            # read trial structure
            trials = list(csv.DictReader(trial_file, delimiter='\t'))

            # preload stimuli
            stimuli = [audio.read(self.stimuli_folder + trial['stimulus']) for trial in trials]

            recordings = []

            self.text.text = '||'
            self.text.draw()
            self.win.flip()
            audio.play(audio.read(self.instructions_folder + self.mode + '.wav'), wait=True)
            key = event.waitKeys(keyList=['return'])
            self.win.flip()

            for stimulus in stimuli:
                self.text.text = '+'
                self.text.draw()
                self.win.flip()
                audio.play(stimulus, wait=True)
                self.text.text = '-'
                self.text.draw()
                self.win.flip()
                recordings += [audio.record((len(stimulus) / 44100.0) + 1, wait=True)]
                keys = event.getKeys(['escape'])
                if 'escape' in keys:
                    break

            for i in range(len(recordings)):
                audio.write(self.log_prefix + trials[i]['stimulus'], recordings[i])

            self.win.close()
Exemple #6
0
 def message_trial(self, trial):
     # present instruction trial
     self.title.text = trial['title']
     self.title.draw()
     self.win.callOnFlip(self.clock.reset)
     self.win.flip()
     audio.play(audio.read(self.instructions_folder + 'ravens.wav'),
                wait=True)
     keys = event.waitKeys(keyList=['escape'] +
                           trial['keyboard'].split(','),
                           timeStamped=self.clock)
     trial['keypress'], trial['RT'] = keys[0]
     if trial['keypress'] == 'escape':
         core.quit()
     self.expclock.reset()
     return trial
Exemple #7
0
    def run(self):
        # set up presentation window color, and size
        bgcolor = 'white'
        txtcolor = 'black'
        self.win = visual.Window(fullscr=True, color=bgcolor)
        #self.win = visual.Window((1200, 900), color=bgcolor)  # temporary presentation window setup, exchange for line above when running actual experiment

        # set up timing related stuff
        self.frame_dur = 1.0 / self.fps
        self.clock = core.Clock()  # trial timer
        self.expclock = core.Clock()  # whole experiment timer
        # inter trial interval setup
        self.isi = core.StaticPeriod()
        self.isi.start(.5)

        # various stimulus presentation boxes for text and images
        self.text = visual.TextStim(self.win, color=txtcolor)
        self.message = visual.TextStim(self.win, color=txtcolor)
        self.message.wrapWidth = 1.5
        self.title = visual.TextStim(self.win, pos=(0, .8), color=txtcolor)
        self.title.wrapWidth = 1.5
        self.image = visual.ImageStim(self.win)

        # actually run the experiment routines
        with open(self.trials_fname,
                  'rU') as trial_file, open(self.log_fname, 'w',
                                            newline='') as log_file:
            # read trial structure
            trials = csv.DictReader(trial_file, delimiter='\t')

            # set up log file
            log_fields = trials.fieldnames + ['keypress', 'RT', 'ACC', 't'
                                              ] + list(self.pp_info.keys())
            log = csv.DictWriter(log_file,
                                 fieldnames=log_fields,
                                 delimiter='\t')
            log.writeheader()

            # preload block and instructions
            blocks = {}
            self.instructions = {}
            for trial in trials:
                trial.update(self.pp_info)
                if (trial['trialAudio'] != '') and (
                        trial['trialAudio'] not in self.instructions.keys()):
                    self.instructions[trial['trialAudio']] = audio.read(
                        self.instructions_folder + trial['trialAudio'])
                if trial['block'] not in blocks.keys():
                    blocks[trial['block']] = [trial]
                else:
                    blocks[trial['block']].append(trial)

            for i in range(5, 0, -1):
                self.text.text = '+' * (2 * i - 1)
                self.text.draw()
                self.win.flip()
                core.wait(1)

            # present the trials
            random.seed(self.pp_info['number'])
            for block_number in sorted(blocks.keys()):
                trials = blocks[block_number]
                if trials[0]['randomize'] == 'yes':
                    random.shuffle(trials)
                for trial in trials:
                    self.clock.reset()  # reset trial clock
                    trial = self.present_trial(trial)  # present the trial
                    log.writerow(trial)  # log the trial data

            self.win.close()
Exemple #8
0
def run():
    while True:
        data = analyzer.analyze(audio.read())
        pretty.update_heights(data)
        led_controller.update(pretty.columns, pretty.spacers)