Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Playing a sound during keypress in sequence

edited April 2016 in OpenSesame

Hello,

This is my first thread in the forum. I am working on a time perception experiment. I want the subject group to be able to reproduce an alarm like sound pattern, consisting of 900 ms. long sound samples and intervals between them by pressing and releasing a key. Also i need to keep record of the keypress durations. I figured out that using an uninterrupted sound sample that is a little longer than the duration of the whole pattern and activating it only by pressing and holding a key can work. I have overviewed related threads, but since I don't have experience with python nor OS I couldn't find a way to implement my experiment. Any comment is appreciated.

Çağdaş

Comments

  • edited 1:33PM

    Hi,

    Using a long sound sample is a good idea. I think you will need to make a while-loop in an inline_script run-phase that looks something like this:

      from openexp.keyboard import keyboard   
      your_keyboard = keyboard(exp)  # just so you can use the keyboard
    
      done = False
      key,time = your_keyboard.get_key()
      your_sound.play()  
      start_time = self.time()
      while done == False:
             key1,time = your_keyboard.get_key(timeout=10)
             if key1 != key:
                   your_sound.stop()
                   final_time = self.time() - start_time   # this is the duration of the button press
                   break
    

    Hope this helps.

    Cheers,

    Josh

  • edited 1:33PM

    Thank you very much for the quick reply. When I run the script it tells me your_sound item is not defined. I tried to wirte the name of ogg file in qutation marks, this time i get the error 'str' object has no attribute 'play'. How can I define the item to be played?

  • edited 1:33PM

    Hi Çağdaş,

    Yes, the sound item is something you'll have to define yourself beforehand - typically in the prepare-phase of your inline_script. Have a look here: http://osdoc.cogsci.nl/python/sampler/

    Beware that I just gave an example; it'll probably have to be tuned to your specific needs. In the current state, for example, one can only press the button once, and the loop will end upon release.

    Cheers,

    Josh

Sign In or Register to comment.