Pyo - How to Play two Sound Files read from RAM Sequentially?

624 views Asked by At

I have two sound files of the same length that I want to play sequentially. Specifically, I want the first file to play three times, and the second file to play once.

I can achieve this through a SfPlayer and a TrigFunc, but I'm under the impression that this will read the sound file from disk each time I switch sounds. Is there a way I can accomplish this through a SndTable, which holds the sounds in RAM ?

Here is the solution with using a SfPlayer and TrigFunc, using this example as inspiration.

from pyo import *
s = Server().boot()
DOWNLOADS = 'C:\\Users\\mmoisen\\Downloads\\'
first = DOWNLOADS + 'first.wav'
second = DOWNLOADS + 'second.wav'
sf = SfPlayer(first, speed=100/135.0, loop=True, mul=0.5).out()

count = 0

def foo():
    global count
    count += 1
    print count
    if count == 3:
        sf.path = second
    if count == 4:
        sf.path = forst
        count = 0

trig = TrigFunc(sf['trig'][0], foo)

s.start()
1

There are 1 answers

0
Matthew Moisen On

To play sound files sequentially from RAM, I just needed to call append on the SndTable, like this:

from pyo import *
s = Server().boot()
DOWNLOADS = 'C:\\Users\\mmoisen\\Downloads\\'
first = DOWNLOADS + 'first.wav'
second = DOWNLOADS + 'second.wav'

# Using an array like this didn't work; it just played the first clip
# t = SndTable([first,first,first,second])
t = SndTable(first)
t.append(first)
t.append(first)
t.append(second)
a = Osc(table=t, freq=t.getRate(), mul=.4).out()

s.start()

Using a list of the sound files didn't work; it just played the first sound repeatedly.