Exemple #1
0
class Audio(Stimulus):
    '''A simple audio stimulus.'''
    def __init__(self, window, sound, text=None, *args, **kwargs):
        '''Constructor for the Audio stimulus.

        Arguments:
        sound - A number (pitch in Hz), string for a note,
                or string for a filename.
                For more info, see:
                http://www.psychopy.org/api/sound.html
        text - Text to display on screen (Optional).

        Additional args and kwargs are passed to the 
        sound.Sound constructor.
        '''
        super(Audio, self).__init__(window)
        self.sound = Sound(sound, *args, **kwargs)
        self.text = text

    def show(self):
        self.display_text(self.text)
        self.play_sound()
        return super(Audio, self).show()

    def play_sound(self):
        self.sound.play()
        core.wait(self.sound.getDuration())
        return None
Exemple #2
0
class Audio(Stimulus):
    """A simple audio stimulus."""

    def __init__(self, window, sound, text=None, *args, **kwargs):
        """Constructor for the Audio stimulus.

        Arguments:
        sound - A number (pitch in Hz), string for a note,
                or string for a filename.
                For more info, see:
                http://www.psychopy.org/api/sound.html
        text - Text to display on screen (Optional).

        Additional args and kwargs are passed to the 
        sound.Sound constructor.
        """
        super(Audio, self).__init__(window)
        self.sound = Sound(sound, *args, **kwargs)
        self.text = text

    def show(self):
        self.display_text(self.text)
        self.play_sound()
        return super(Audio, self).show()

    def play_sound(self):
        self.sound.play()
        core.wait(self.sound.getDuration())
        return None
Exemple #3
0
def play_file(path, msg, trigger_port, trigger_twice=False):
    all_events.append({
        'what': "audio played",
        'when': core.getTime() - experiment_start,
        'content': path,
        'message': msg,
        'response': None
    })
    msg = visual.TextStim(win, text=msg)
    msg.draw()
    win.flip()
    mySound = Sound(path)
    if (trigger_port):
        sendTrigger(trigger_port, duration=0.01)
    mySound.play()
    core.wait(mySound.getDuration())
    if (trigger_port and trigger_twice):
        sendTrigger(trigger_port, duration=0.01)
Exemple #4
0
class AudioScene(object):
    def __init__(self, win, manager, soundFile, fixationCross):
        self.win = win
        self.manager = manager
        self.sound = Sound(soundFile)
        self.fixationCross = fixationCross
        self.max_frame = math.ceil(
            self.sound.getDuration() * constants.FRAME_RATE +
            constants.AUDIO_DELAY * constants.FRAME_RATE)
        self.delay_frames = math.ceil(constants.AUDIO_DELAY *
                                      constants.FRAME_RATE)
        self.current_frame = 0

    def update(self):
        self.current_frame += 1
        if self.current_frame == self.delay_frames:
            self.sound.play()
            self.manager.eyeTracker.sound_start()
        if self.current_frame >= self.max_frame:
            self.manager.set_response_scene()
        self.draw()

    def draw(self):
        self.fixationCross.draw()