denote.util

Audio loading and utility functions for denote.

Functions

ensure_file_path(audio, *[, sr])

Ensure audio is available as a file path.

load_audio(audio, *[, sr, mono, target_sr])

Load audio from a file path or validate an existing array.

denote.util.ensure_file_path(audio, *, sr=None)[source]

Ensure audio is available as a file path.

If audio is already a path, return it as a string. If it’s an array, write to a temporary WAV file and return the path.

Return type:

str

denote.util.load_audio(audio, *, sr=None, mono=True, target_sr=None)[source]

Load audio from a file path or validate an existing array.

Parameters:
  • audio (Union[str, Path, ndarray]) – File path (str/Path) or numpy array of audio samples.

  • sr (Optional[int]) – Sample rate. Required when audio is an array. Ignored for file paths (detected automatically).

  • mono (bool) – If True, convert to mono.

  • target_sr (Optional[int]) – If set, resample to this rate.

Return type:

Tuple[ndarray, int]

Returns:

Tuple of (audio_array, sample_rate).

Raises: