# Playing a repeating sound in a random time interval

**URL:** <https://discourse.psychopy.org/t/playing-a-repeating-sound-in-a-random-time-interval/27045>\
**Category:** Builder\
**Tags:** timing, sound, multithreading, python3\
**Created:** [January 26, 2022, 10:25pm UTC](https://discourse.psychopy.org/t/playing-a-repeating-sound-in-a-random-time-interval/27045 "2022-01-26T22:25:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JDavid17](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jdavid17/32/32527_2.png) [@JDavid17](https://discourse.psychopy.org/u/JDavid17)\
**Post date:** [January 26, 2022, 10:25pm UTC](https://discourse.psychopy.org/t/playing-a-repeating-sound-in-a-random-time-interval/27045/1 "2022-01-26T22:25:37Z")

</div>

If this template helps then use it. If not then just delete and start from scratch.

**OS** (e.g. Win10): Windows 10  
**PsychoPy version** (e.g. 1.84.x): v2021.2.3  
**Standard Standalone? (y/n)** If not then what?:y  
**What are you trying to achieve?:** I am trying to run a test that shows a series of videos (loaded from disk) and along with the videos have a sound playing that is triggered every 1-1.5 seconds and lasts around 0.7 seconds.

**What did you try to make it work?:** I’ve created a Flow with all the videos loaded in different routines, the videos are displaying correctly. But for the sound i did a python script that uses winsound.beep() to trigger the beeping sound. I try running this method using

- multiprocessing
- threading

**What specifically went wrong when you tried that?:**  
for the first the flow didn’t even display correctly, just freezes on loading and crashes soon after. When using threading the flow is started but the videos are been display at 1-2 fps and skipping all the missing frames.

So basically thats what i’m trying to do. play a beeping sound along side the videos that triggers in a random time between 1-1.5 seconds? any ideas that could help me? much appreciated.

Include pasted full error message if possible. “That didn’t work” is not enough information.

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [January 28, 2022, 10:02pm UTC](https://discourse.psychopy.org/t/playing-a-repeating-sound-in-a-random-time-interval/27045/2 "2022-01-28T22:02:40Z")

</div>

Hi There,

Perhaps this solution might help? [Presenting stimuli and randomising interstimulus interval for a duration of 40 seconds - #2 by Becca](https://discourse.psychopy.org/t/presenting-stimuli-and-randomising-interstimulus-interval-for-a-duration-of-40-seconds/19726/2)

---

<div class="post-metadata">

**Author:** ![JDavid17](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jdavid17/32/32527_2.png) [@JDavid17](https://discourse.psychopy.org/u/JDavid17)\
**Post date:** [February 9, 2022, 4:06pm UTC](https://discourse.psychopy.org/t/playing-a-repeating-sound-in-a-random-time-interval/27045/3 "2022-02-09T16:06:05Z")

</div>

Thank you so much!

---

<div class="post-metadata">

**Author:** ![Marta3](https://avatars.discourse-cdn.com/v4/letter/m/839c29/32.png) [@Marta3](https://discourse.psychopy.org/u/Marta3)\
**Post date:** [June 12, 2023, 12:19pm UTC](https://discourse.psychopy.org/t/playing-a-repeating-sound-in-a-random-time-interval/27045/4 "2023-06-12T12:19:27Z")

</div>

Hi Becca,

I’m trying to use your solution to present an auditory stimulus with an interstimulus interval that varies randomly between 8 and 10 seconds.

I’ll leave the code and the builder here:

 ![code](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/f/4/f48ee5ff7fde67d44284649176708968ba186b8e.png)  
 ![Builder](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/4/c/4c79fb72ef1e2838900f46b8390cd4ea317002b4.png)  
 ![stimulus](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/1/21fa85f4de12ea4b47ddf3130582573ff38d14a9.png)

The problem is that the stimulus is delivered within a time range different from the interstimulus interval selected. For example, the first stimulus is delivered 18 sec after the beginning and the second stimulus at 20 sec (2 sec after the first stimulus).

Thank you in advance for your help!

Marta
