Audio¶
soundscapy.audio
¶
Provides tools for working with audio signals, particularly binaural recordings.
Key Components:
- Binaural: A class for processing and analyzing binaural audio signals.
- Various metric calculation functions for audio analysis.
The module integrates with external libraries such as mosqito, maad, and acoustic_toolbox to provide a comprehensive suite of audio analysis tools.
Examples:
>>>
>>> from soundscapy.audio import Binaural
>>> signal = Binaural.from_wav("audio.wav")
>>> results = signal.process_all_metrics(analysis_settings)
See Also
soundscapy.audio.binaural: For detailed Binaural class documentation.soundscapy.audio.metrics: For individual metric calculation functions.
Notes
This module requires the soundscapy[audio] optional dependencies.
| MODULE | DESCRIPTION |
|---|---|
analysis_settings |
Module for managing audio analysis settings using Pydantic models. |
audio_analysis |
Audio analysis module for psychoacoustic analysis of audio files. |
binaural |
Provides tools for working with binaural audio signals. |
metrics |
Functions for calculating various acoustic and psychoacoustic metrics for audio signals. |
parallel_processing |
Functions for parallel processing of binaural audio files. |
soundscapy.audio.analysis_settings
¶
Module for managing audio analysis settings using Pydantic models.
This module defines Pydantic models for configuring analysis settings for different audio processing libraries (AcousticToolbox, MoSQITo, scikit-maad). It includes classes for individual metric settings, library settings, and overall analysis settings. It also provides a ConfigManager class for loading, saving, merging, and managing configurations from YAML files or dictionaries.
| CLASS | DESCRIPTION |
|---|---|
MetricSettings |
Settings for an individual metric. |
LibrarySettings |
Settings for a library of metrics. |
AnalysisSettings |
Settings for audio analysis methods. |
ConfigManager |
Manage configuration settings for audio analysis. |
MetricSettings
¶
Bases: BaseModel
Settings for an individual metric.
| ATTRIBUTE | DESCRIPTION |
|---|---|
run |
Whether to run this metric.
TYPE:
|
main |
The main statistic to calculate. |
statistics |
List of statistics to calculate. |
channel |
List of channels to analyze. |
label |
Label for the metric.
TYPE:
|
parallel |
Whether to run the metric in parallel.
TYPE:
|
func_args |
Additional arguments for the metric function. |
| METHOD | DESCRIPTION |
|---|---|
check_main_in_statistics |
Check that the main statistic is in the statistics list. |
check_main_in_statistics
classmethod
¶
Check that the main statistic is in the statistics list.
Source code in src/soundscapy/audio/analysis_settings.py
LibrarySettings
¶
Bases: RootModel
Settings for a library of metrics.
| METHOD | DESCRIPTION |
|---|---|
get_metric_settings |
Get the settings for a specific metric. |
get_metric_settings
¶
Get the settings for a specific metric.
| PARAMETER | DESCRIPTION |
|---|---|
metric
|
The name of the metric.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MetricSettings
|
The settings for the specified metric. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the specified metric is not found. |
Source code in src/soundscapy/audio/analysis_settings.py
AnalysisSettings
¶
Bases: BaseModel
Settings for audio analysis methods.
| ATTRIBUTE | DESCRIPTION |
|---|---|
version |
Version of the configuration.
TYPE:
|
AcousticToolbox |
Settings for AcousticToolbox metrics.
TYPE:
|
MoSQITo |
Settings for MoSQITo metrics.
TYPE:
|
scikit_maad |
Settings for scikit-maad metrics.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
validate_library_settings |
Validate library settings. |
from_yaml |
Create an AnalysisSettings object from a YAML file. |
default |
Create a default AnalysisSettings using the package default configuration file. |
from_dict |
Create an AnalysisSettings object from a dictionary. |
to_yaml |
Save the current settings to a YAML file. |
update_setting |
Update the settings for a specific metric. |
get_metric_settings |
Get the settings for a specific metric. |
get_enabled_metrics |
Get a dictionary of enabled metrics. |
validate_library_settings
classmethod
¶
Validate library settings.
Source code in src/soundscapy/audio/analysis_settings.py
from_yaml
classmethod
¶
Create an AnalysisSettings object from a YAML file.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to the YAML configuration file. |
| RETURNS | DESCRIPTION |
|---|---|
AnalysisSettings
|
An instance of AnalysisSettings. |
Source code in src/soundscapy/audio/analysis_settings.py
default
classmethod
¶
Create a default AnalysisSettings using the package default configuration file.
| RETURNS | DESCRIPTION |
|---|---|
AnalysisSettings
|
An instance of AnalysisSettings with default settings. |
Source code in src/soundscapy/audio/analysis_settings.py
from_dict
classmethod
¶
Create an AnalysisSettings object from a dictionary.
| PARAMETER | DESCRIPTION |
|---|---|
d
|
Dictionary containing the configuration settings.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisSettings
|
An instance of AnalysisSettings. |
Source code in src/soundscapy/audio/analysis_settings.py
to_yaml
¶
Save the current settings to a YAML file.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to save the YAML file. |
Source code in src/soundscapy/audio/analysis_settings.py
update_setting
¶
Update the settings for a specific metric.
| PARAMETER | DESCRIPTION |
|---|---|
library
|
The name of the library.
TYPE:
|
metric
|
The name of the metric.
TYPE:
|
**kwargs
|
Keyword arguments to update the metric settings.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the specified library or metric is not found. |
Source code in src/soundscapy/audio/analysis_settings.py
get_metric_settings
¶
Get the settings for a specific metric.
| PARAMETER | DESCRIPTION |
|---|---|
library
|
The name of the library.
TYPE:
|
metric
|
The name of the metric.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MetricSettings
|
The settings for the specified metric. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the specified library or metric is not found. |
Source code in src/soundscapy/audio/analysis_settings.py
get_enabled_metrics
¶
Get a dictionary of enabled metrics.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, dict[str, MetricSettings]]
|
A dictionary of enabled metrics grouped by library. |
Source code in src/soundscapy/audio/analysis_settings.py
ConfigManager
¶
Manage configuration settings for audio analysis.
| PARAMETER | DESCRIPTION |
|---|---|
config_path
|
Path to the default configuration file. |
| METHOD | DESCRIPTION |
|---|---|
load_config |
Load a configuration file or use the default configuration. |
save_config |
Save the current configuration to a file. |
merge_configs |
Merge the current config with override values and update the current_config. |
generate_minimal_config |
Generate a minimal configuration containing only changes from the default. |
Source code in src/soundscapy/audio/analysis_settings.py
load_config
¶
Load a configuration file or use the default configuration.
| PARAMETER | DESCRIPTION |
|---|---|
config_path
|
Path to the configuration file. If None, uses the default configuration. |
| RETURNS | DESCRIPTION |
|---|---|
AnalysisSettings
|
The loaded configuration. |
Source code in src/soundscapy/audio/analysis_settings.py
save_config
¶
Save the current configuration to a file.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to save the configuration file. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If no current configuration is loaded. |
Source code in src/soundscapy/audio/analysis_settings.py
merge_configs
¶
Merge the current config with override values and update the current_config.
| PARAMETER | DESCRIPTION |
|---|---|
override_config
|
Dictionary containing override configuration values.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisSettings
|
The merged configuration. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If no base configuration is loaded. |
Source code in src/soundscapy/audio/analysis_settings.py
generate_minimal_config
¶
Generate a minimal configuration containing only changes from the default.
| RETURNS | DESCRIPTION |
|---|---|
dict
|
A dictionary containing the minimal configuration. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If no current configuration is loaded. |
Source code in src/soundscapy/audio/analysis_settings.py
The main audio analysis surface is split across the focused pages below: