View Source NxAudio.IO behaviour (nx_audio v0.1.0)
Defines a behaviour for audio backend operations
Summary
Types
A 2D tensor representing audio data. By default, the first dimension is the amount of channels and the second dimension is the amount of samples.
Defines the input for the load function, which can be a binary audio or a valid file path
Defines the possible errors that can occur when loading an audio file
Audio sample rate in Hz
Callbacks
Returns the audio metadata for a given file.
Loads an audio file from a given URI and returns a tuple with the audio tensor and the sample rate.
Saves an audio tensor to a given URI.
Types
@type audio_tensor() :: Nx.Tensor.t()
A 2D tensor representing audio data. By default, the first dimension is the amount of channels and the second dimension is the amount of samples.
Defines the input for the load function, which can be a binary audio or a valid file path
@type io_errors() :: NxAudio.IO.Errors.FailedToExecuteBackend.t() | NxAudio.IO.Errors.InvalidMetadata.t()
Defines the possible errors that can occur when loading an audio file
@type sample_rate() :: non_neg_integer()
Audio sample rate in Hz
Callbacks
@callback info(uri :: file_uri()) :: {:ok, NxAudio.IO.AudioMetadata.t()} | {:error, io_errors()}
Returns the audio metadata for a given file.
@callback load(uri :: file_uri(), config :: NxAudio.IO.BackendReadConfig.t()) :: {:ok, {audio_tensor(), sample_rate()}} | {:error, io_errors()}
Loads an audio file from a given URI and returns a tuple with the audio tensor and the sample rate.
@callback save( uri :: file_uri(), tensor :: audio_tensor(), config :: NxAudio.IO.BackendSaveConfig.t() ) :: :ok | {:error, io_errors()}
Saves an audio tensor to a given URI.