Caution
You're reading an old version of this documentation. If you want up-to-date information, please have a look at 0.9.1.
librosa.util.valid_audio¶
- librosa.util.valid_audio(y, mono=True)[source]¶
Validate whether a variable contains valid, mono audio data.
- Parameters
- ynp.ndarray
The input data to validate
- monobool
Whether or not to force monophonic audio
- Returns
- validbool
True if all tests pass
- Raises
- ParameterError
- In any of these cases:
type(y) is not np.ndarray
y.dtype is not 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 False
y.flags[“F_CONTIGUOUS”] is False
See also
Notes
This function caches at level 20.
Examples
>>> # By default, valid_audio allows only mono signals >>> filepath = librosa.util.example_audio_file() >>> 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