Caution
You're reading an old version of this documentation. If you want up-to-date information, please have a look at 0.10.2.
librosa.util.valid_audio
- librosa.util.valid_audio(y, mono=True)[source]
Determine whether a variable contains valid audio data.
If
mono=True
, theny
is only considered valid if it has shape(N,)
(number of samples).If
mono=False
, theny
may be either monophonic, or have shape(2, N)
(stereo) or(K, N)
forK>=2
for general multi-channel.- Parameters:
- ynp.ndarray
The input data to validate
- monobool
Whether or not to require monophonic audio
- Returns:
- validbool
True if all tests pass
- Raises:
- ParameterError
- In any of these cases:
type(y)
is notnp.ndarray
y.dtype
is not floating-pointmono == True
andy.ndim
is not 1mono == False
andy.ndim
is not 1 or 2mono == False
andy.ndim == 2
buty.shape[0] == 1
np.isfinite(y).all()
is False
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