audiblelight.ambience.Ambience#
- class audiblelight.ambience.Ambience(channels, duration, alias, filepath=None, noise=None, ref_db=-65, sample_rate=44100, **kwargs)#
Bases:
object
Represents persistent background noise for a Scene.
- Parameters:
channels (int)
duration (int | float | complex | integer | floating)
alias (str)
filepath (str | Path | None)
noise (str | int | float | complex | integer | floating | None)
ref_db (int | float | complex | integer | floating | None)
sample_rate (int | float | complex | integer | floating | None)
- __init__(channels, duration, alias, filepath=None, noise=None, ref_db=-65, sample_rate=44100, **kwargs)#
Initialises persistent, invariant background noise for a Scene object.
The audio used for ambience can be either a “colored” form of noise (e.g., white, blue, red, etc.), or a mono audio file. When an audio file is provided (by setting filepath=…), it will be tiled in both the horizontal and vertical directions to match the given number of channels and duration. Otherwise, the color of the noise must be specified (by setting color=…).
- Parameters:
channels (int) – the number of channels to use when generating ambience
duration (Numeric) – the duration (in seconds) for background ambience
sample_rate (Numeric) – the sample rate to use for generated ambience
alias (str) – Label to refer to this Ambience by inside the Scene
filepath (str or Path) – a path to an audio file on the disk. Must be provided when noise is None.
noise (str) – either the type of noise to generate, e.g. “white”, “red”, or an arbitrary numeric exponent to use when generating noise with powerlaw_psd_gaussian. Must be provided if filepath is None.
ref_db (Numeric) – the noise floor for the ambience
kwargs – additional values passed to powerlaw_psd_gaussian when noise is not None.
Methods
__init__
(channels, duration, alias[, ...])Initialises persistent, invariant background noise for a Scene object.
from_dict
(input_dict)Instantiate Ambience from a dictionary
load_ambience
([ignore_cache])Load the background ambience as an array with shape (channels, samples).
to_dict
()Returns metadata for this object as a dictionary
Attributes
Returns True if noise is loaded and is valid (see librosa.util.valid_audio for more detail)
- __eq__(other)#
Compare two Ambience objects for equality.
- Returns:
True if two Ambience objects are equal, False otherwise
- Return type:
bool
- Parameters:
other (Any)
- __repr__()#
Returns representation of the scene as a JSON
- Return type:
str
- __str__()#
Returns a string representation of the scene
- Return type:
str
- classmethod from_dict(input_dict)#
Instantiate Ambience from a dictionary
- Parameters:
input_dict (dict[str, Any]) – the dictionary to instantiate from
- Returns:
Ambience instance
- property is_audio_loaded: bool#
Returns True if noise is loaded and is valid (see librosa.util.valid_audio for more detail)
- load_ambience(ignore_cache=False)#
Load the background ambience as an array with shape (channels, samples).
- Parameters:
ignore_cache (bool | None)
- Return type:
ndarray
- to_dict()#
Returns metadata for this object as a dictionary
- Return type:
dict