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()
To play sound files sequentially from RAM, I just needed to call
append
on theSndTable
, like this:Using a list of the sound files didn't work; it just played the first sound repeatedly.