community
community copied to clipboard
Add static method `from_bytes` to `SoundSDL2` to initialize an instance from audio sample in memory
Kivy allows loading audio samples from filesystem by filename using the source
property of Sound
object, but sometimes the audio samples are generated in the memory, for example it happens when using text to speech engines like Picovoice's Orca or Piper and in environments like RPi running on a SD-card, writing the samples from memory to filesystem in a temporary file and then asking Kivy to instruct SDL to read that file again into memory may cause some unwanted side effects like delay or exhaustion of the SD-card.
from_bytes
static method added in this pull request, lets the user instantiate SoundSDL2
with data coming directly from memory.
I considered re-using the source
property by adding a "mem:" prefix or something like that as a signal for load
method, but it's a StringProperty
and only accepts str
, not bytes
.
Maintainer merge checklist
- [ ] Title is descriptive/clear for inclusion in release notes.
- [ ] Applied a
Component: xxx
label. - [ ] Applied the
api-deprecation
orapi-break
label. - [ ] Applied the
release-highlight
label to be highlighted in release notes. - [ ] Added to the milestone version it was merged into.
- [ ] Unittests are included in PR.
- [ ] Properly documented, including
versionadded
,versionchanged
as needed.