def stream(length, numsegments, freq): out = [] seglength = dsp.randint(100, 300) points = [ dsp.rand(-1, 1) for _ in range(dsp.randint(10, 20)) ] for _ in range(numsegments): seglength = dsp.cap(seglength + dsp.randint(-5, 5), 1000, 100) points = [ dsp.cap(p + dsp.randint(-0.1, 0.1), 1, -1) for p in points ] out += dsp.breakpoint([0] + points + [0], seglength) print len(out), freq, length out = dsp.ctone(freq, dsp.stf(length), out, dsp.rand(0.1, 0.5)) #out = dsp.env(out, 'random') return out
def rb(snd, length=None, speed=None, hz=None, interval=None, ratios=None, crisp=0, formant=False): pid = os.getpid() cmd = ['rubberband'] # Time stretching if length is not None and dsp.flen(snd) != length and length > 0: cmd += [ '--duration %s' % dsp.fts(length) ] # crisp setting cmd += [ '--crisp %s' % dsp.cap(crisp, 6, 0) ] # preserve formants if formant: cmd += [ '--formant' ] # pitch shift by speed if speed is not None: cmd += [ '--frequency %s' % speed ] # pitch shift by semitones if interval is not None: # TODO use pippi.tune ratios and calc frequency args cmd += [ '--pitch %s' % interval ] vpid = pid + random.randint(1, 10000) cmd = ' '.join(cmd) + ' /tmp/infile%s.wav /tmp/outfile%s.wav' % (vpid, vpid) dsp.write(snd, '/tmp/infile%s' % vpid, cwd=False) with open(os.devnull, 'w') as devnull: p = subprocess.Popen(cmd, stdout=devnull, stderr=devnull, shell=True) p.wait() out = dsp.read('/tmp/outfile%s.wav' % vpid).data os.remove('/tmp/outfile%s.wav' % vpid) os.remove('/tmp/infile%s.wav' % vpid) return out