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

    Buy Me A Coffee

  • 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 22

    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 .

    Buy Me A Coffee

  • 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 22

    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:


    Buy Me A Coffee

  • edited June 29

    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

    Buy Me A Coffee

  • 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

    Buy Me A Coffee

  • 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!

    Buy Me A Coffee

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games