music.play_audio¶
- music.play_audio(sonic_vector, sample_rate=None, normalize=True)[source]¶
Play a sonic vector using the
sounddevicelibrary.- Parameters:
- sonic_vectorarray_like
Samples to be played. Mono arrays should have shape
(n,)and stereo arrays(2, n).- sample_rate
intorNone,optional Playback sample rate. None, the default, is the rate
music.get_sample_rate()returns.- normalizebool,
optional If
True(default), normalizesonic_vectorbefore playback usingnormalize_mono()ornormalize_stereo().
- Raises:
ImportErrorIf sounddevice is not installed:
pip install 'music[play]'.RuntimeErrorIf it is, but cannot find the PortAudio library it plays through, which Linux distributions package separately.
- Parameters:
- Return type:
None
Notes
This used to log a warning and return when sounddevice was missing, which no extra declared and no install instruction named, so on a fresh install the routine the README offers for listening played nothing and went on. It now says what to install, as
render_oversampled()does for SciPy.Examples
>>> play_audio(note(freq=440, duration=0.5))