taped.audio_pokes

taped.audio_pokes.live_audio_chks(input_device_index=None, sr=44100, sample_width=2, n_channels=1, chk_size=4096, stream_buffer_size_s=60)[source]

A generator of live chunks of audio bytes taken from a stream sourced from specified microphone.

Parameters
  • input_device_index – Index of Input Device to use. Unspecified (or None) uses default device.

  • sr – Specifies the desired sample rate (in Hz)

  • sample_bytes – Sample width in bytes (1, 2, 3, or 4)

  • n_channels – The desired number of input channels. Ignored if input_device is not specified (or None).

  • sample_width – Specifies the number of frames per buffer.

  • stream_buffer_size_s – How many seconds of data to keep in the buffer (i.e. how far in the past you can see)

taped.audio_pokes.live_wf(input_device_index=None, sr=44100, sample_width=2, n_channels=1, chk_size=4096, stream_buffer_size_s=60)[source]

A generator of live waveform sample values taken from a stream sourced from specified microphone.

Parameters
  • input_device_index – Index of Input Device to use. Unspecified (or None) uses default device.

  • sr – Specifies the desired sample rate (in Hz)

  • sample_width – Sample width in bytes (1, 2, 3, or 4)

  • n_channels – The desired number of input channels. Ignored if input_device is not specified (or None).

  • stream_buffer_size_s – How many seconds of data to keep in the buffer (i.e. how far in the past you can see)

>>> from time import sleep
>>> from itertools import islice
>>> # enter the id of your microphone and get a live waveform source!
>>> # (if None, will try to figure it out)
>>> wf_gen = live_wf(input_device_index=None)
>>>
>>> # Now wait a bit, say some silly things, then ask for a few samples...
>>> sleep(1.2)
>>> wf = list(islice(wf_gen, 0, 44100 * 1))
>>> # and now listen to that wf and be embarrassed...
>>> # ... or just look at the size (less fun though)
>>> len(wf)
44100

Don’t forget to close! (or use live_wf_ctx context manager). >>> wf_gen.close()

After wf_gen is closed, you can still ask it for data. It just won’t give you any. >>> wf = list(islice(wf_gen, 0, 44100 * 1)) >>> len(wf) 0

Here wf_gen is a generator, so closing means: https://docs.python.org/2.5/whatsnew/pep-342.html

taped.audio_pokes.live_wf_ctx(input_device_index=None, sr=44100, sample_width=2, n_channels=1, chk_size=4096, stream_buffer_size_s=60)[source]

A context manager providing a generator of live waveform sample values taken from a stream sourced from specified microphone.

Parameters
  • input_device_index – Index of Input Device to use. Unspecified (or None) uses default device.

  • sr – Specifies the desired sample rate (in Hz)

  • sample_width – Sample width in bytes (1, 2, 3, or 4)

  • n_channels – The desired number of input channels. Ignored if input_device is not specified (or None).

  • stream_buffer_size_s – How many seconds of data to keep in the buffer (i.e. how far in the past you can see)

>>> from time import sleep
>>> from itertools import islice
>>> # enter the id of your microphone and get a live waveform source!
>>> # (if None, will try to figure it out)
>>> with live_wf_ctx(input_device_index=None) as wf_gen:
...
...     # Now wait a bit, say some silly things, then ask for a few samples...
...     sleep(1.1)
...     wf = list(islice(wf_gen, 0, 44100 * 1))
>>> # and now listen to that wf and be embarrassed...
>>> # ... or just look at the size (less fun though)
>>> len(wf)
44100
taped.audio_pokes.rechunker(chks: Iterable[Iterable], chunker: Union[Callable, int])[source]

Generate fixed sized non-overlapping chunks of an iterable of chunks. That is, the rechunker applies a chunker to an unraveled stream of chunks, or more generally of iterables since they can be of varied sizes and types.

>>> from functools import partial
>>> chunker = partial(simple_chunker, chk_size=3)
>>> chks = [[0], (1, 2, 3), [4, 5], iter((6, 7))]  # iterable of (different types of) iterables
>>> list(rechunker(chks, chunker))
[(0, 1, 2), (3, 4, 5)]
taped.audio_pokes.simple_chunker(a: Iterable, chk_size: int)[source]

Generate fixed sized non-overlapping chunks of an iterable a.

>>> list(simple_chunker(range(7), 3))
[(0, 1, 2), (3, 4, 5)]

Most of the time, you’ll want to fix the parameters of the chunker like this:

>>> from functools import partial
>>> chunker = partial(simple_chunker, chk_size=3)
>>> list(chunker(range(7)))
[(0, 1, 2), (3, 4, 5)]

Note, the type of the chunks is always tuples, but you can easily change that using map. For example, to change the type to be list:

>>> list(map(list, chunker(range(7))))
[[0, 1, 2], [3, 4, 5]]
>>> a = range(6)
>>> list(simple_chunker(a, 3))
[(0, 1, 2), (3, 4, 5)]
>>> list(simple_chunker(a, 2))
[(0, 1), (2, 3), (4, 5)]
>>> list(simple_chunker(a, 1))
[(0,), (1,), (2,), (3,), (4,), (5,)]