How can I repeatedly play a sound sample, allowing the next loop to overlap the previous
Question: Not sure if this isn't a dupe, but the posts I found so far didn't solve my
issue.

* * *

A while ago, I wrote a (music) [metronome for
Ubuntu](http://askubuntu.com/a/814889/72216). The metronome is written in
`python3/Gtk`

To repeatedly play the metronome- tick (a recorded sound sample), I used
`subprocess.Popen()` to play the sound, using `ogg123` as a cli tool:

    
    
    subprocess.Popen(["ogg123", soundfile])
    

This works fine, I can easily run up to 240 beats per minute.

### On WIndows

I decided to rewrite the project on Windows (`python3/tkinter/ttk`). I am
having a hard time however to play the sound, repeating the beat sample in
higher tempi. The next beat simply won't start while the previous one
(appearantly) hasn't finished yet, playing the beat sample.

Is there a way, in `python3` on Windows, I can start playing the next beat
while the sample is still playing?

Currently, I am using `winsound`:

    
    
    winsound.Playsound()
    

Running this in a loop has, as mentioned issues.


Answer: You can use [pydub](https://github.com/jiaaro/pydub) for audio manipulation ,
including playing repetedly.

Here is an example. You can develop this further using examples from [pydub
site.](http://pydub.com/)

    
    
    from pydub import AudioSegment
    from pydub.playback import play
    
    n = 2
    
    audio = AudioSegment.from_file("sound.wav") #your audio file
    play(audio * n)  #Play audio 2 times
    

Change `n` above to the number that you need.

