How to use the sounddevice.OutputStream function in sounddevice

To help you get started, we’ve selected a few sounddevice examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github spatialaudio / python-sounddevice / examples / play_sine.py View on Github external
start_idx = 0

try:
    samplerate = sd.query_devices(args.device, 'output')['default_samplerate']

    def callback(outdata, frames, time, status):
        if status:
            print(status, file=sys.stderr)
        global start_idx
        t = (start_idx + np.arange(frames)) / samplerate
        t = t.reshape(-1, 1)
        outdata[:] = args.amplitude * np.sin(2 * np.pi * args.frequency * t)
        start_idx += frames

    with sd.OutputStream(device=args.device, channels=1, callback=callback,
                         samplerate=samplerate):
        print('#' * 80)
        print('press Return to quit')
        print('#' * 80)
        input()
except KeyboardInterrupt:
    parser.exit('')
except Exception as e:
    parser.exit(type(e).__name__ + ': ' + str(e))
github spatialaudio / python-sounddevice / sounddevice.py View on Github external
See Also
    --------
    rec, playrec

    """
    ctx = _CallbackContext(loop=loop)
    ctx.frames = ctx.check_data(data, mapping, kwargs.get('device'))

    def callback(outdata, frames, time, status):
        assert len(outdata) == frames
        ctx.callback_enter(status, outdata)
        ctx.write_outdata(outdata)
        ctx.callback_exit()

    ctx.start_stream(OutputStream, samplerate, ctx.output_channels,
                     ctx.output_dtype, callback, blocking,
                     prime_output_buffers_using_stream_callback=False,
                     **kwargs)
github tlecomte / friture / friture / audiobackend.py View on Github external
def open_output_stream(self, device, callback):
        # by default we open the device stream with all the channels
        # (interleaved in the data buffer)
        stream = sounddevice.OutputStream(
            samplerate=SAMPLING_RATE,
            blocksize=FRAMES_PER_BUFFER,
            device=device['index'],
            channels=device['max_output_channels'],
            dtype=int16,
            callback=callback)

        return stream
github kitao / pyxel / pyxel / audio_player.py View on Github external
def __init__(self):
        try:
            self._output_stream = sd.OutputStream(
                samplerate=AUDIO_SAMPLE_RATE,
                blocksize=AUDIO_BLOCK_SIZE,
                channels=1,
                dtype="int16",
                callback=self._output_stream_callback,
            )
        except sd.PortAudioError:
            self._output_stream = None

        self._channel_list = [Channel() for _ in range(AUDIO_CHANNEL_COUNT)]
        self._sound_list = [Sound() for _ in range(AUDIO_SOUND_COUNT)]
        self._music_list = [Music() for _ in range(AUDIO_MUSIC_COUNT)]
github Muges / audiotsm / audiotsm / io / stream.py View on Github external
def __init__(self, channels, samplerate, **attrs):
        self._channels = channels

        self._stream = OutputStream(samplerate=samplerate, channels=channels,
                                    **attrs)
        self._stream.start()
github dschreij / python-mediadecoder / mediadecoder / soundrenderers / sounddevicerenderer.py View on Github external
Parameters
		----------
		audioformat : dict
			A dictionary containing the properties of the audiostream
		queue : Queue.queue
			A queue object which serves as a buffer on which the individual
			audio frames are placed by the decoder.
		"""
		global sd
		import sounddevice as sd

		if not queue is None:
			self.queue = queue

		self.stream = sd.OutputStream(
			channels  	= audioformat["nchannels"],
			samplerate 	= audioformat["fps"],
			dtype = 'int{}'.format(audioformat['nbytes']*8),
			blocksize 	= audioformat["buffersize"],
			callback 	= self.get_frame
		)
		self.keep_listening = True