Skip to content

support loading audio as float16 #496

Description

@sammlapp

Hi, it would be great to support loading in float16 dtype. Many autonomous audio recorders used for wildlife monitoring record very long, float16 files, and loading them as float32 doubles the memory usage unnecessarily. Currently, only ['float32', 'float64', 'int16', 'int32'] are supported by sf.load()

It seems like the crux is that ctypes does not have float16

_ffi_types: Final[dict[str, str]] = {

the audio frame loading happens in

def _cdata_io(self, action, data, ctype, frames):

which is called by SoundFile.read() via :

def _array_io(self, action, array, frames):

Perhaps it would be possible to cast frames to float16 immediately when loading into python, to avoid the memory overhead of creating the entire array as float32?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions