Howdy, Stranger!

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

Supported by

vocal response s button press

Hello!

I already asked how to use a voice key, but I still have trouble with this because I was recommended not to use just a normal microphone but a cedrus VP-1 device. I found python library which I think kind of records the vocal response like a button press. But it should be adopted to OpenSesame I think and I have trouble with this. The code goes like this:


import pyxid2
import time

# get a list of all attached XID devices
devices = pyxid2.get_xid_devices()

dev = devices[0] # get the first device to use
print(dev)
dev.reset_base_timer()
dev.reset_rt_timer()

if dev.is_response_device():
    print ("Press a key!")
    while not dev.has_response():
        dev.poll_for_response()

    response = dev.get_next_response()
    print(response)
    dev.clear_response_queue()

dev.set_pulse_duration(300)

sleep_flash = .3
for bm in range(0, 16):
    mask = 2 ** bm
    print("activate_line bitmask: ", mask)
    #dev.activate_line(lines=[1,3,5,7,9,11,13,15])
    dev.activate_line(bitmask=mask)

    time.sleep(sleep_flash)

The response is a python dict with the following keys:

port: Device port the response was from (typically 0)
key: Response pad key pressed by the subject
pressed: True if the key was pressed, False if it was released
time: value of the Response Time timer when the key was pressed/released

Sending a TTL pulse signal via the library can be done via the following methods:

set_pulse_duration()
activate_line()
clear_line()

Can you help me to simplify the code for OpenSesame (backend with Expyrement)? Thousand thanks!

Comments

  • Hi Katharina,

    I don't have this device myself, so I'm blind-coding this. But I think something like the following should work.

    At the very start of the experiment, add the following code to the Prepare phase of an inline_script :

    import pyxid2
    
    devices = pyxid2.get_xid_devices()
    dev = devices[0]  # if you get a TypeError, try device 1, 2, etc.
    if not dev.is_response_device():
        raise TypeError('Device is not a response device')
    dev.reset_base_timer()
    dev.reset_rt_timer()
    

    Then, when you want to collect a response, add the following code to the Run phase of another inline_script :

    # Wait until a response is available
    t0 = clock.time()
    while not dev.has_response():
        dev.poll_for_response()
    t1 = clock.time()
    # Get the response and clear the queue
    response = dev.get_next_response()
    dev.clear_response_queue()
    # Tell OpenSesame about the response
    responses.add(
        response='voicekey',
        response_time=t1 - t0,
        item='custom_inline_script'
    )
    

    Something like this should do the trick, I think, but you may have to tweak the code a bit!

    Cheers,

    Sebastiaan

  • Many thanks, I will try it out!

  • I also have a question: the voice_key script logically starts only AFTER the sound has played - but participants should be able to respond vocally from the sound onset on. How do I overcome this problem?

    Thank you ever so much for your patience!

  • edited June 2020

    And I would also like to save the voice onset time (which is even more important for me as the RT because I want to response-lock the data. can I add this? var.voice_onset = t1

    # Wait until a response is available
    t0 = clock.time()
    while not dev.has_response():
    	dev.poll_for_response()
    t1 = clock.time()
    # Get the response and clear the queue
    response = dev.get_next_response()
    dev.clear_response_queue()
    # Tell OpenSesame about the response
    responses.add(
    	response='voicekey',
    	response_time=t1 - t0,
    	item='custom_inline_script'
    )
    var.voice_onset = t1
    
  • If you set the duration of the sound item to 0, then the sound will keep playing in the background while the experiment advances to thevoice_key_script .

  • Thank you ever so much!

    I am not sure about the timing, because we need to set it to a lower number (like 750 is 745)

    In the sequence above, the sound should come every 2 seconds. So should I set blank and ITI to 995?

  • The sound is 0.05 ms


  • edited June 2020

    I now actually set sound duration to 945

    and added an inline AFTER the voice key script

    if loudness > sound_threshold:
    	self.sleep(945-response_time)
    else:
    	self.sleep(0)
    

    It's just intuition, but seems to work, the lap between sound_onset is about 2025, but never perfectly 2000. Is the perfect 2000 achiavable?

  • It's just intuition, but seems to work, the lap between sound_onset is about 2025, but never perfectly 2000. Is the perfect 2000 achiavable?

    Yes that's possible, but it requires a little scripting to take into account the preparation time, which will vary slightly from trial to trial (as you noticed). See my reply here:


  • edited June 2020

    Many thanks for this great suggestion.

    I added

    run_onset = clock.time()
    prepare_duration = run_onset - prepare_onset
    print('prepare duration: {}'.format(prepare_duration))
    var.duration = prepare_duration
    

    and then

    if loudness > sound_threshold:
    	self.sleep(945-response_time-prepare_duration)
    else:
    	self.sleep(0)
    

    That improved the accuracy of the sound_onset but still with a few variations. I dont have a fixed ITI because they answer verbally and this also lasts.


    Or is there a better way to fix it?

  • Hello me again.


    I can't import pyxid2, I get an error no pyxid2 found

    I have open sesame 3.1.9, python 2.7.12


    Many thanks


  • Hi @Katharina ,

    You can install pyxid2 through Anaconda in OpenSesame 3.3 by running the following in the console:

     %pip install pyxid2
    

    I see in the screenshot that you're running 3.1.9. So this would be a good moment to upgrade :-)

    Cheers,

    Sebastiaan

  • Thanks for your promt reply.


    Unfortunately I have no rights (don't ask why :) to update this very OpenSesame PC. So I will have to work with 3.1.9. is there any way out to install pyxid2?

  • Hi Katharina,

    If you have no admin rights, then you can download the 'no installation required' package. That you can simply unzip and run from any location without requiring admin privileges.

    Cheers!

    Sebastiaan

  • Thanks, but I mean I am not allowed to update anything in any way :) it's not about admit right which I have :) I mus word only with this version

  • You can also try to install the pyxid2 package through pip as described here for your version of OpenSesame:

    I'm not sure whether pyxid2 is compatible with Python 2, which is the version of Python that OpenSesame 3.1 uses by default. It may not be, in which case I would reconsider (or ask the powers that be to reconsider) updating to OpenSesame 3.3!

Sign In or Register to comment.