Howdy, Stranger!

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

Supported by

[solved] How to use a sound sample during a reaction time task

edited March 2014 in OpenSesame

Hi everybody,

We have just made a reaction time task but we want to add a sound sample to the task. Our experiment looks as followed:

image

We want the sound to start at "experimentloop_1" and it must continu troughout the experiment. We're not sure how to do this because we've added several loops. The reason for adding all those loops is that we have added breaks to the experiment but we want the sound sample to continu during the breaks and also during the task.

Our sound sample is a .wav format and the duration is 6 minutes, our experiment lasts for about 20 minutes and the sample must sound fluently troughout the experiment..

Please help :(

For the Dutch moderators:

Hoi,

Wij hebben een reactietijd taak gemaakt en zouden hier graag een geluidsbestand (.wav, 6 minuten) aan toe willen voegen. Zoals je in het plaatje kan zien, is er voorafgaand aan het echte experiment nog een vragenlijst, oefenblok, baseline meting etc. Wij willen dat het geluid pas vanaf "experimentloop_1" begint te spelen en dat hij pas aan het eind van het experiment uit gaat. Omdat een reactietijd taak van 20 minuten nogal lang is voor een participant hebben we pauzes ingelast van ongeveer 3 minuten, maar we willen dat het geluid ook tijdens de pauzes te horen is. Voor de pauzes en reactietijdtaken hebben we verschillende loops aangemaakt dus we weten niet zo goed of we in iedere loop een geluidsbestand moeten zetten of niet, want het geluid moet wel onafgebroken te horen zijn. Hopelijk is dit verhaal een beetje duidelijk en kan iemand ons helpen :)

Comments

  • edited March 2014

    Hi guys,

    The solution is actually very simple, if you employ a bit of inline scripting. Add the following code to the Run phase of an inline_script item directly before "experimentloop1".

    EDIT 24 March 2014, 17:19 GMT: corrected a silly mistake in the code.

    # we will need to import the library that
    # we will use to play the sound
    import pygame
    
    # first, we check if it is initialized; if it is
    # not, we initialize it
    if not pygame.mixer.get_init():
        pygame.mixer.init()
    
    # next, we will need to specify the sound
    # file (NOTE: this has to be added to your
    # file pool!
    sound_name = "example.ogg" # change to your own filename
    sound_path = exp.get_file(sound_name)
    
    # now we initialize the sound; this means
    # we prepare it so that it can be played
    exp.sound = pygame.mixer.Sound(sound_path)
    
    # finally, play the sound! (the -1 indicates
    # that it should play infinitely)
    exp.sound.play(-1)
    

    If you want the sound to pause at some point, insert the following code into an inline_script item at the point where you want it to pause:

    import pygame
    pygame.mixer.pause()
    

    And add the following to an inline_script item at the point where you want the sound to resume playing after a pause:

    import pygame
    pygame.mixer.unpause()
    

    If you want the sound to stop completely, insert the following code into an inline_script item at the point where you want it to stop:

    exp.sound.stop()
    

    As a general note: make sure that your sound is either in WAVE (.wav) or OGG (.ogg) format. If you have a different format, you can convert the sound to either WAVE or OGG via a converter (you can search for one online, there are tons).

    Good luck!

  • edited March 2014

    Hi Edwin,

    I've entered the code in the Run phase of the inline script. However, I get this error:

    Error: Inline script error
    In: inline_script (run phase)
    Line: 7

    Python traceback:
    AttributeError: 'module' object has no attribute 'get_init'

    Full traceback in debug window

    I have no idea what I'm doing wrong. I've literally copied and pasted your code, ive also added the file to the filepool and inserted the file name in your code. Help :(

  • edited March 2014

    Btw, this is the code as it is in our experiment right now:

    # we will need to import the library that
    # we will use to play the sound
    import pygame
    
    # first, we check if it is initialized; if it is
    # not, we initialize it
    if not pygame.get_init():
        pygame.init()
    
    # next, we will need to specify the sound
    # file (NOTE: this has to be added to your
    # file pool!
    sound_name = "5-0.wav" # change to your own filename
    sound_path = exp.get_file(sound_name)
    
    # now we initialize the sound; this means
    # we prepare it so that it can be played
    exp.sound = pygame.mixer.Sound(sound_path)
    
    # finally, play the sound! (the -1 indicates
    # that it should play infinitely)
    exp.sound.play(-1)
    
  • edited 4:32PM

    Hi guys,

    Terribly sorry, that's my mistake! The code below should work:

    # we will need to import the library that
    # we will use to play the sound
    import pygame
    
    # first, we check if it is initialized; if it is
    # not, we initialize it
    if not pygame.mixer.get_init():
        pygame.mixer.init()
    
    # next, we will need to specify the sound
    # file (NOTE: this has to be added to your
    # file pool!
    sound_name = "5-0.wav" # change to your own filename
    sound_path = exp.get_file(sound_name)
    
    # now we initialize the sound; this means
    # we prepare it so that it can be played
    exp.sound = pygame.mixer.Sound(sound_path)
    
    # finally, play the sound! (the -1 indicates
    # that it should play infinitely)
    exp.sound.play(-1)
    

    Simply forgot to add the .mixer in the initialization bit. I've updated my previous post as well, for future reference.

    Good luck!

  • edited 4:32PM

    Hi Edwin,

    IT WORKS! Thank you so much!

  • edited 4:32PM

    No problem, glad that it works! Marking this as solved.

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