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

<hr>

<p>A while ago, I wrote a (music) <a href="http://askubuntu.com/a/814889/72216">metronome for Ubuntu</a>. The metronome is written in <code>python3/Gtk</code> </p>

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

<pre><code>subprocess.Popen(["ogg123", soundfile])
</code></pre>

<p>This works fine, I can easily run up to 240 beats per minute.</p>

<h3>On WIndows</h3>

<p>I decided to rewrite the project on Windows (<code>python3/tkinter/ttk</code>). 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.</p>

<p>Is there a way, in <code>python3</code> on Windows, I can start playing the next beat while the sample is still playing?</p>

<p>Currently, I am using <code>winsound</code>: </p>

<pre><code>winsound.Playsound()
</code></pre>

<p>Running this in a loop has, as mentioned issues.</p>

<p>You can use <a href="https://github.com/jiaaro/pydub" rel="nofollow">pydub</a> for audio manipulation , including playing repetedly.</p>

<p>Here is an example. You can develop this further using examples from <a href="http://pydub.com/" rel="nofollow">pydub site.</a></p>

<pre><code>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
</code></pre>

<p>Change <code>n</code> above to the number that you need.</p>

python windows python-3.x audio