music.play_audio

music.play_audio(sonic_vector, sample_rate=None, normalize=True)[source]

Play a sonic vector using the sounddevice library.

Parameters:
sonic_vectorarray_like

Samples to be played. Mono arrays should have shape (n,) and stereo arrays (2, n).

sample_rateint or None, optional

Playback sample rate. None, the default, is the rate music.get_sample_rate() returns.

normalizebool, optional

If True (default), normalize sonic_vector before playback using normalize_mono() or normalize_stereo().

Raises:
ImportError

If sounddevice is not installed: pip install 'music[play]'.

RuntimeError

If it is, but cannot find the PortAudio library it plays through, which Linux distributions package separately.

Parameters:
  • sonic_vector (ArrayLike)

  • sample_rate (int | None)

  • normalize (bool)

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))