Ejemplo n.º 1
0
class Recorder(object):
	def __init__(self, settings):
		self.buffer = SampleBuffer(channels=settings.input.channels)
                self.settings = settings
		self.stream = create_stream(
			settings=settings,
			output=False,
			callback=lambda *args: self._recording(*args)
		)

	def _recording(self, input, *rest):
		self.buffer.put(input)

	def sample(self):
		while not self.buffer.has():
			pass
		return self.buffer.get_chunk()

	def start(self):
		self.stream.start()

	def stop(self):
		self.stream.stop()

	def rate(self):
		return int(self.stream.samplerate)
Ejemplo n.º 2
0
Archivo: emit.py Proyecto: idreyn/robin
class Emitter(object):
	def __init__(self, settings):
		self.buffer = SampleBuffer(channels=settings.output.channels)
		self.stream = create_stream(
			settings=settings,
			output=True,
			callback=lambda *args: self.playback(*args)
		)

	def playback(self, output, *rest):
		output[:] = self.buffer.get_samples(len(output))

	def emit(self, arr):
		self.buffer.put(arr)

	def start(self):
		self.stream.start()

	def stop(self):
		self.stream.stop()

	def rate(self):
		return int(self.stream.samplerate)