pyquist.device

Sounddevice integration — persistent default-device selection, play(), and record().

Sounddevice integration: device selection, play, and record.

The user’s chosen input/output devices are persisted as JSON under CACHE_DIR / "device_defaults.json" and applied to sounddevice.default once at module import time.

pyquist.device.set_input_device(device_id_or_name=None, *, update_default=False)[source]

Selects the input device for the current Python session.

Parameters:
  • device_id_or_name (Union[int, str, None]) – Device index, or a substring of the device name. If None, prompts the user interactively.

  • update_default (bool) – If False (default), the change applies only to this Python session. If True, the choice is also persisted to the cache and reapplied next time pyquist is imported. The pyquist devices CLI command is the usual way to update the persistent default.

Return type:

None

pyquist.device.set_output_device(device_id_or_name=None, *, update_default=False)[source]

Selects the output device for the current Python session.

Parameters:
  • device_id_or_name (Union[int, str, None]) – Device index, or a substring of the device name. If None, prompts the user interactively.

  • update_default (bool) – If False (default), the change applies only to this Python session. If True, the choice is also persisted to the cache and reapplied next time pyquist is imported. The pyquist devices CLI command is the usual way to update the persistent default.

Return type:

None

pyquist.device.play(audio, *, safe=True, normalize=False, force_sounddevice=False)[source]

Plays an Audio.

In a Jupyter / IPython notebook this renders an inline player widget via IPython.display.Audio. Outside a notebook (or when force_sounddevice=True) it plays through the default output device via sounddevice.

Parameters:
  • audio (Audio) – The audio to play. Must have a sample_rate.

  • safe (bool) – If True (default), attenuates the audio to -18 dBFS before playback to protect ears against accidentally hot signals.

  • normalize (bool) – If True, normalizes the audio to 0 dBFS before playback.

  • force_sounddevice (bool) – If True, always use sounddevice playback, even when called from a notebook. Useful when you want the audio played through the OS audio output rather than as an inline player widget.

Return type:

None

pyquist.device.record(duration, *, progress_bar=True, **kwargs)[source]

Records audio from the default input device.

Parameters:
  • duration (float) – Recording length in seconds.

  • progress_bar (bool) – Whether to display a tqdm progress bar.

  • kwargs (Any)

Return type:

Audio

Returns:

The recorded Audio at the input device’s native sample rate.