Closed microbit-carlos closed 2 months ago
Let's try AudioFrame(duration=None, *, rate=7812, size=None)
, where providing 3 of these arguments raises an exception.
A different class has been created that can be initialised from an external buffer, which can be set to a specific size in bytes, as described in:
When working on an example to send recorded data via radio like walkie-talkie, one idea is to record AudioFrames of the same size than the packet size for radio.
With the current API is not straightforward at all to work out how to create an AudioFrame of say 64 bytes. We need to use a sample rate that is easily divisible by the packet size, and a packet size that is a multiple of 32 bytes. Initial attempts using the default rate (which is not a multiple of 32 bytes either) ended up with floats as the
duration
, which doesn't work asduration
has to be an integer. So you end up setting a non-default rate.We originally discarded a
size
arguments (AudioFrame(size, duration, rate)
), as size is directly related to the other two parameters, so providing all three options would have to raise an error or similar.We could replace the
duration
parameter fromAudioFrame
, but still have it formicrophone.record(duration, rate)
, as that is the simplest way to create an audio sample. In this case we would end up with code like this:Not too sure what other simple options we might have, or if there is a better way to implement a
size
parameter. Any suggestions are very welcomed.As a workaround, I've been creating AudioFrames with the size as the rate and 1s duration, but then we need to set the rate back to the value we'd like. For example, for 128 bytes: