Caution

You're reading the documentation for a development version. For the latest released version, please have a look at 0.10.2.

librosa.util.valid_audio

librosa.util.valid_audio(y)[source]

Determine whether a variable contains valid audio data.

The following conditions must be satisfied:

  • type(y) is np.ndarray

  • y.dtype is floating-point

  • y.ndim != 0 (must have at least one dimension)

  • np.isfinite(y).all() samples must be all finite values

Parameters:
ynp.ndarray

The input data to validate

Returns:
validbool

True if all tests pass

Raises:
ParameterError

In any of the conditions specified above fails

See also

numpy.float32

Notes

This function caches at level 20.

Examples

We can make an array that can be interpreted as an audio signal

>>> y = np.random.randn(5000)
>>> librosa.util.valid_audio(y)
True

If we insert a non-finite sample value somewhere, it will fail

>>> y[5] = np.nan
>>> librosa.util.valid_audio(y)
...
ParameterError: Audio buffer is not finite everywhere