librosa.util.valid_audio¶
- librosa.util.valid_audio(y, *, mono=<DEPRECATED parameter>)[source]¶
Determine whether a variable contains valid audio data.
The following conditions must be satisfied:
type(y)
isnp.ndarray
y.dtype
is floating-pointy.ndim != 0
(must have at least one dimension)np.isfinite(y).all()
samples must be all finite values
If
mono
is specified, then we additionally require -y.ndim == 1
- Parameters
- ynp.ndarray
The input data to validate
- monobool
Whether or not to require monophonic audio
Warning
The
mono
parameter is deprecated in version 0.9 and will be removed in 0.10.
- Returns
- validbool
True if all tests pass
- Raises
- ParameterError
In any of the conditions specified above fails
See also
Notes
This function caches at level 20.
Examples
>>> # By default, valid_audio allows only mono signals >>> filepath = librosa.ex('trumpet', hq=True) >>> y_mono, sr = librosa.load(filepath, mono=True) >>> y_stereo, _ = librosa.load(filepath, mono=False) >>> librosa.util.valid_audio(y_mono), librosa.util.valid_audio(y_stereo) True, False
>>> # To allow stereo signals, set mono=False >>> librosa.util.valid_audio(y_stereo, mono=False) True