Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to create an AudioFrame of a specific size #193

Open
microbit-carlos opened this issue Apr 10, 2024 · 1 comment
Open

A way to create an AudioFrame of a specific size #193

microbit-carlos opened this issue Apr 10, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@microbit-carlos
Copy link
Contributor

microbit-carlos commented Apr 10, 2024

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 as duration 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 from AudioFrame, but still have it for microphone.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:

DURATION = 4000
RATE = 7812
af1 = audio.AudioFrame(size=DURATION*RATE, rate=RATE)
af2 = microphone.record(DURATION)

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:

af = AudioFrame(duration=1000, rate=128)
af.set_rate(7812)
@microbit-carlos
Copy link
Contributor Author

microbit-carlos commented Apr 29, 2024

Let's try AudioFrame(duration=None, *, rate=7812, size=None), where providing 3 of these arguments raises an exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants