Howdy, Stranger!

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

Supported by

How to stop sounds after keypress using Javascript

Hi,

I want to conduct a reaction time task where participants have to respond to a sound. This sound should stop playing after keyboard response. I have already solved the problem adding an inline python scrip, following this discussion: https://forum.cogsci.nl/discussion/6429/is-it-possible-to-stop-sound-played-by-sampler-at-keypress

However, I need to perform the task online, so I need to use an inline_javascript. Is that possible?  Does anyone know how to solve it?

Thanks a lot,

Carlotta

Comments

  • Hi Carlotta, I think your question fits better in the OSWeb forum. I'll move it there. Best, Kristian

  • FabFab
    edited April 7

    Hi @carlotta,

    There may be other options but the only way I know to achieve what you're after in Javascript requires that you handle sounds from Javascript instead of using the sampler object. Note that the method I'm describing below will only work when you run the task in the navigator.

    instead of using sounds from the file pool, you'll need to load them up in memory from an external URL. that is, you'll need to host your sound files on a server. Furthermore, that server must support Cross-Origin Resource Sharing or CORS (otherwise your navigator will be denied access when trying to access the sound files). One option is for you to get an account on Github (free) and use it to store your sounds (you'll then need to use raw links to your sound files). If you have many heavy sound files, your task may become heavy in terms of memory management. Sound files in .ogg format take less room and maybe a better option than .wav files (note that with the method I'm describing below, you'd also be able to use .mp3 files which are not supported by the sampler object in Open Sesame).

    Here's the basic method:

    Sounds need to be loaded into memory from a URL. We do this with Javascript code in an inline_javascript object.


    The code to load up a sound is:

    vars.mysound = new Audio('https://www.bensound.com/bensound-music/bensound-moose.mp3')
    

    You'd have to replace the URL by the raw Github link where you're hosting your sound file. Note that this code must be place in the "Prepare" section of the inline_javascript object.

    In the "Run" section, we play it with:

    vars.mysound.play()
    

    The sound will start playing while the task will move on to the next object.

    To stop the sound, we execute the following Javascript code:

    vars.mysound.pause()
    

    This will stop the sound.

    In your task, you'd want to run this code when the subject response has been registered.

    Hope fully this method can be adapted to your task.

    You can download my basic example here:

    Good luck!

    Fabrice.

    PS: Note that a memory leak was detected in OSWeb 1.4.4.0 (see https://forum.cogsci.nl/discussion/7623/memory-leaks-in-osweb-1-4-sketchpad-feedback-sampler). If you're using many trials and many sounds, my recommendation would be to update your OSWeb component to the latest prerelease package (https://forum.cogsci.nl/discussion/comment/25205/#Comment_25205)

    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