title: How to create a Python program that plays a random sound every x seconds with overlay
body: <p>I'm trying to create a program which will select and play a random wav from folder a every x seconds, folder b every y seconds, folder c every z seconds... and which doesn't interrupt what is already playing when a new sound is brought in (ie each sound is allowed to play until completion whilst others from other functions and the same function are overlayed). Ideally it should display the names of the files being played at any time as well.</p>
  <p>My first inclination was to use nested loops which pick and play a random sound 'if seconds = x / y / z' but I couldn't find the information needed to make this work.</p>
  <p>I have found the response <a href="https://stackoverflow.com/questions/39298928/play-multiple-sounds-at-the-same-time-in-python">here</a> to be useful in getting me started - specifying wav files and overlaying them and I've created the following which works, but doesn't overlay, select files at random or play anything until after the first delay. It also appears to wait until the first function is complete before implementing the next, rather than starting all at the same time (playFrom_b and playFrom_a should be called 5 seconds after the first iteration of playFrom_a etc):</p>
  <pre><code>import sched, time
  from pydub import AudioSegment
  from pydub.playback import play
  
  s = sched.scheduler(time.time, time.sleep)
  sound1_a = AudioSegment.from_file('/.../sound1_a.wav')
  sound1_b = AudioSegment.from_file('/.../sound1_b.wav')
  sound1_c = AudioSegment.from_file('/.../sound1_c.wav')
  
  def playFrom_a(sc): #plays something every 5 seconds
      play(sound1_a)
      s.enter(5, 1, playFrom_a, (sc,))
  
  def playFrom_b(sc): #plays something every 10 seconds
      play(sound1_b)
      s.enter(10, 1, playFrom_b, (sc,))
      
  def playFrom_c(sc): #plays something every 15 seconds
      play(sound1_c)
      s.enter(15, 1, playFrom_c, (sc,))
  
  s.enter(5, 1, playFrom_a, (s,))
  s.enter(10, 1, playFrom_b, (s,))
  s.enter(15, 1, playFrom_c, (s,))
  s.run()
  </code></pre>
  <p>I have tried the following to test random selection from a nominated directory and have received an 'AttributeError: 'str' object has no attribute 'overlay'':</p>
  <pre><code>from pydub import AudioSegment
  from pydub.playback import play
  import random, glob
  
  soundFolder = glob.glob('/.../*.wav')
  sound1_a = random.choice(soundFolder)
  sound1_b = random.choice(soundFolder)
  sound1_c = random.choice(soundFolder)
  
  mixed = sound1.overlay(sound2)
  mixed1  = mixed.overlay(sound3)
  
  play(mixed1)
  </code></pre>
  <p>and find myself at the point now where I need to ask for help please.</p>