1 .. currentmodule:: aubio
7 This section contains the documentation for two classes:
8 :class:`source`, to read audio samples from files, and :class:`sink`,
9 to write audio samples to disk.
11 .. defined in `python/ext`
14 Note: __call__ docstrings of objects defined in C must be written
15 specifically in RST, since there is no known way to add them to
16 their C implementation.
19 TODO: remove special-members documentation
21 .. defined in py-source.c
25 :special-members: __enter__
28 .. function:: __call__()
30 Read at most `hop_size` new samples from self, return them in
31 a tuple with the number of samples actually read.
33 The returned tuple contains:
35 - a vector of shape `(hop_size,)`, filled with the `read` next
36 samples available, zero-padded if `read < hop_size`
37 - `read`, an integer indicating the number of samples read
39 If opened with more than one channel, the frames will be
40 down-mixed to produce the new samples.
42 :returns: A tuple of one array of samples and one integer.
45 .. seealso:: :meth:`__next__`
49 >>> src = aubio.source('stereo.wav')
51 ... samples, read = src()
52 ... if read < src.hop_size:
55 .. function:: __next__()
57 Read at most `hop_size` new frames from self, return them in
60 If source was opened with one channel, next(self) returns
61 an array of shape `(read,)`, where `read` is the actual
62 number of frames read (`0 <= read <= hop_size`).
64 If `source` was opened with more then one channel, the
65 returned arrays will be of shape `(channels, read)`, where
66 `read` is the actual number of frames read (`0 <= read <=
69 :return: A tuple of one array of frames and one integer.
72 .. seealso:: :meth:`__call__`
76 >>> for frames in aubio.source('song.flac')
77 ... print(samples.shape)
79 .. function:: __iter__()
83 .. seealso:: :meth:`__next__`
85 .. function:: __enter__()
87 Implement context manager interface. The file will be opened
88 upon entering the context. See `with` statement.
92 >>> with aubio.source('loop.ogg') as src:
93 ... src.uri, src.samplerate, src.channels
95 .. function:: __exit__()
97 Implement context manager interface. The file will be closed
98 before exiting the context. See `with` statement.
100 .. seealso:: :meth:`__enter__`
103 TODO: remove special-members documentation
105 .. autoclass:: aubio.sink
108 .. function:: __call__(vec, length)
110 Write `length` samples from `vec`.
112 :param array vec: input vector to write from
113 :param int length: number of samples to write
116 >>> with aubio.sink('foo.wav') as snk:
117 ... snk(aubio.fvec(1025), 1025)