# Repeat the sound component only in a routine

**URL:** <https://discourse.psychopy.org/t/repeat-the-sound-component-only-in-a-routine/33784>\
**Category:** Builder\
**Created:** [March 12, 2023, 8:47pm UTC](https://discourse.psychopy.org/t/repeat-the-sound-component-only-in-a-routine/33784 "2023-03-12T20:47:16Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Chen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/chen/32/38825_2.png) [@Chen](https://discourse.psychopy.org/u/Chen)\
**Post date:** [March 12, 2023, 10:19pm UTC](https://discourse.psychopy.org/t/repeat-the-sound-component-only-in-a-routine/33784/2 "2023-03-12T22:19:30Z")

</div>

Correct me if I am wrong, but it looks like you tried to take the following approach:

> [@How to repeat an audio stimuli when pressing certain key](https://discourse.psychopy.org/t/how-to-repeat-an-audio-stimuli-when-pressing-certain-key/5437):
>
> System version: masOS Mojave Version:10.14 Hi all, I’m using PsychoPy builder to build up an experiment like this: By pressing space, the participant can listen to the next audio stimuli. By pressing “r”, the participant can repeat the audio stimuli like as many as they like. My question is how to repeat the stimuli as described. I think this may require some coding, so if you could tell me put what codes at which position that will be great. Thank you so much!!! Best, …

This approach creates a loop to repeat the sound. If you press the slider, you want the loop to be finished. If the `r` key was pressed, you want the loop to start iterating.  
As long as the participant presses the `r` key, the loop won’t be over. It will repeat the routine repeatedly until the participant presses the slider to finish the experiment.

Everything in your code seems to be fine except one thing. You need to set the keyboard component to end the routine as well. So, the routine will be over whenever the participant presses `r`, and the loop will start its iteration.

![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/4/8/480081208eb0d89ee6c9a3f46eda9b8ecf787dce.png)

I created a simplistic example demonstrating this approach:  
[Repeat Sound.zip](https://discourse.psychopy.org/uploads/short-url/qSBRGFyXVK992DAnxS0IfPsxpbz.zip) (20.3 KB)

Let me know if it fixed your inquiry and if you need any help 🙂

---

_[View the full topic](https://discourse.psychopy.org/t/repeat-the-sound-component-only-in-a-routine/33784)._
