Howdy, Stranger!

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

Supported by

[open] Stop Sampler playing music (using key e.g. ENTER)

edited January 2016 in OpenSesame

Currently doing a project where sentences are presented alongside background music. The background music is presented 3000 ms before the sentence is presented and then continued as long as the participant reads the sentence. This is all working, but when you push ENTER to go to the question paired with the sentence, the music keeps on playing.
The music files are around 30 - 40 seconds so what also happens when you go to trial 2, 3 and 4 is that new music files are simply added to the already playing music, so that you have 3-4 music items playing at once.

How do I get the music to stop playing alongside the sentence, by using ENTER or similar.
Atm i'm using the sampler item and not an incline code.

Ola

Comments

  • edited 7:43PM

    It would actually be nice to be able to include a white screen/ canvas during the 3 seconds of music playing without the sentence.

  • edited January 2016

    Hi Ola,

    What Josh suggested in the other thread is a good way to solve your issue. So, basically, instead of using the sampler item, you should play the files from within an inline_script, actually, two inline_scripts.

    First, you replace the sampler with the first inline_script and put this code into it:

    import pygame # import modul
    pygame.mixer.init() # initialize mixer (doing this once might be enough)
    sound_file = exp.get_file(filename) # load the sound file of a single trial
    sound = pygame.mixer.Sound(sound_file) # create an instance of the sound
    sound.play() # play the sound
    
    cv = canvas()
    cv.background_color = 'white'
    cv.show()
    clock.sleep(3000)
    

    Then, you do the other stuff you intended to present, as soon as subjects pressed a key (specify with the allowed_response argument, whichever you want). After your keyboard_response , e.g. as last thing to be executed before you start the next trial, in which you place the single line: sound.stop(). Et voila, there you go.

    Let us know, if this worked out for you.

    Good luck,

    Eduard

    Buy Me A Coffee

  • edited January 2016

    NO it doesn't work. Have three inline scripts at the moment. None of them are doing what they are supposed to do.
    script one RUN

    cv = canvas(exp)
    cv.background_color = 'white'
    sound.play() 
    
    cv.show()
    clock.sleep(3000) ... this doesn't work as it is not defined. 
    

    script one prepare

    import pygame 
    
    pygame.mixer.init() 
    sound_file = exp.get_file("300bpm.wav") 
    #... THIS is also a problem as when I used the sampler I could call my variable # [Noise] which included FOUR sound files. 
    sound = pygame.mixer.Sound(sound_file) 
    
    
    from openexp.canvas import canvas
    

    script two Prepare

    import csv 
    import random 
    list()
    
    image_path = exp.get_file('ops.csv')
    with open(image_path, 'rU') as csvfile:
        reader = csv.DictReader(csvfile, delimiter=',')
        full_list = list(reader)
        random.shuffle(full_list)
        trial_info = full_list.pop(0)
    
        sentence = trial_info['sentences'] 
        question = (trial_info['question'] +"\n \nYES (Y)             NO (N)"+'\n')
        answer = trial_info['answer']
        item = trial_info['item']
    
    
        print(item)
        print(answer) 
        print(sentence) 
        print(question) 
    

    script two run

    from openexp.canvas import canvas
    my_canvas = canvas(exp)
    my_canvas.text(sentence, center=True, x=None, y=None, max_width=None, color=None, bidi=None, html=True)
    my_canvas.show() 
    
    allowed_response = "ENTER"
    keybord_response = "ENTER"
    sound.stop()
    

    not working.. the music stops playing after 3 ms so no music here and keyboard response doesn't work.

    Sorry. Just getting slightly frustrated as nothing is working at the moment.

  • edited 7:43PM

    clock.sleep(3000) ... this doesn't work as it is not defined.

    I suppose you are running Opensesame 2.9.x? In this case clock.time() is not defined, right. Instead, you can use self.time(3000); it will have the same effect.

    sound_file = exp.get_file("300bpm.wav") ... Thisis also a problem as when I used the sampler I could call my variable # [Noise]

    Why? You can still do exact same thing. The only difference is, that you have retrieve your [Noise] variable (I suppose you define it in the loop_table):

    noise = exp.get(Noise)

    sound_file = exp.get_file(noise)

    allowed_response = "ENTER"
    keybord_response = "ENTER"
    sound.stop()

    This won't work. I either you go entirely for the option of doing this with inline_scripts. Then, I highly recommend you checking out the documentation of how to do things with inline_scripts.

    Basically, something like this will do the trick:

    from openexp.keyboard import keyboard
    kb = keyboard(exp,keylist= ['ENTER'],timeout = 27000) # waits for 27 seconds
    kb.get_key()
    
    sound.stop()
    

    Alternatively, you just use the keyboard item as you did before, and add another inline_script later on.

    I hope things make more sense now. No reason to despair.

    Eduard

    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