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]¶
Determine whether a variable contains valid audio data.
If
mono=True, thenyis only considered valid if it has shape(N,)(number of samples).If
mono=False, thenymay be either monophonic, or have shape(2, N)(stereo) or(K, N)forK>=2for 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.ndarrayy.dtypeis not floating-pointmono == Trueandy.ndimis not 1mono == Falseandy.ndimis not 1 or 2mono == Falseandy.ndim == 2buty.shape[0] == 1np.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