Skip to content

audiobusio.PDMIn.record() documentation incorrect #10782

@tekktrik

Description

@tekktrik

Happened to be looking at the docs, and noticed that the docstring and type annotation do not match. Looking at shared-bindings, it looks like it could be EITHER int or None depending on the input buffer (and whether it is actually a writable buffer):

import board
import audiobusio
mic = audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA)
buffer = bytearray(100)
print(mic.record(buffer, 10))  # prints 10
print(mic.record(123, 10))  # prints None

Is this intended behavior, or should it return a TypeError here? If this is intended behavior to silent ignore this and return None, I'll update the docstring - otherwise I can update to return an error.

On the topic of the documentation, the docstring also mentions IOError which I believe should be updated to OSError now.

For reference:

//| def record(self, destination: WriteableBuffer, destination_length: int) -> None:
//| """Records destination_length bytes of samples to destination. This is
//| blocking.
//|
//| An IOError may be raised when the destination is too slow to record the
//| audio at the given rate. For internal flash, writing all 1s to the file
//| before recording is recommended to speed up writes.
//|
//| :return: The number of samples recorded. If this is less than ``destination_length``,
//| some samples were missed due to processing time."""
//| ...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions