def __init__(self, sr=22050, backend='sounddevice'):
"""
:param int sr: samplerate used - all sounds added to the sampler will automatically be resampled if needed (- his can be a CPU consumming task, try to use sound with all identical sampling rate if possible.
:param str backend: backend used for playing sound. Can be either 'sounddevice' or 'dummy'.
"""
self.sr = sr
self.sounds = []
self.chunks = Queue(1)
self.chunk_available = Condition()
if backend == 'dummy':
from .dummy_stream import DummyStream
self.BackendStream = DummyStream
elif backend == 'sounddevice':
from sounddevice import OutputStream
self.BackendStream = OutputStream
else:
raise ValueError("Backend can either be 'sounddevice' or 'dummy'")
# TODO: use a process instead?
self.play_thread = Thread(target=self.run)
self.play_thread.daemon = True
self.play_thread.start()
评论列表
文章目录