librosa.util.valid_audio

librosa.util.valid_audio(y, mono=True)[source]

Validate whether a variable contains valid, mono audio data.

Parameters:
y : np.ndarray

The input data to validate

mono : bool

Whether or not to force monophonic audio

Returns:
valid : bool

True if all tests pass

Raises:
ParameterError
If y fails to meet the following criteria:
  • type(y) is np.ndarray
  • y.dtype is floating-point
  • mono == True and y.ndim is not 1
  • mono == False and y.ndim is not 1 or 2
  • np.isfinite(y).all() is not True

Notes

This function caches at level 20.

Examples

>>> # Only allow monophonic signals
>>> y, sr = librosa.load(librosa.util.example_audio_file())
>>> librosa.util.valid_audio(y)
True
>>> # If we want to allow stereo signals
>>> y, sr = librosa.load(librosa.util.example_audio_file(), mono=False)
>>> librosa.util.valid_audio(y, mono=False)
True