import random
from pyo import *
from time import sleep
from threading import Thread
s = Server().boot().start()
# some frequenicies
f_in = [random.randint(100, 300) for x in range(20000)]
out_length = 10 # in secs
# since the accurancy of time.sleep depends on OS and
# python's implementation and internal runtimes - play with it
sleep_correction = .66
beat_time = out_length/len(f_in) * sleep_correction
f_sig = SigTo(value=0, time=beat_time/2, init=0)
# only to avoid play and stop cracks
fader = Fader(.05, .05, mul=.5)
a = Sine(freq=f_sig, mul=fader).out()
def run():
for f in f_in:
f_sig.setValue(f)
sleep(beat_time)
fader.stop()
sleep(.1)
a.stop()
def start():
fader.play()
thread = Thread(target=run)
thread.start()
# start audio in 2 secs
x = CallAfter(start, 2)
s.gui(locals())