Binaural Analysis
This section provides an overview of the binaural analysis tools available in Soundscapy. It includes a brief description of each tool, as well as information on how to access and use them.
AnalysisSettings
Bases: BaseModel
Settings for audio analysis methods.
PARAMETER | DESCRIPTION |
---|---|
version |
Version of the configuration.
TYPE:
|
PythonAcoustics |
Settings for PythonAcoustics metrics.
TYPE:
|
MoSQITo |
Settings for MoSQITo metrics.
TYPE:
|
scikit_maad |
Settings for scikit-maad metrics.
TYPE:
|
default
classmethod
default()
Create a default AnalysisSettings object using the package's default configuration file.
RETURNS | DESCRIPTION |
---|---|
AnalysisSettings
|
An instance of AnalysisSettings with default settings. |
Source code in soundscapy/audio/analysis_settings.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
from_dict
classmethod
from_dict(d)
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 soundscapy/audio/analysis_settings.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
from_yaml
classmethod
from_yaml(filepath)
Create an AnalysisSettings object from a YAML file.
PARAMETER | DESCRIPTION |
---|---|
filepath |
Path to the YAML configuration file.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
AnalysisSettings
|
An instance of AnalysisSettings. |
Source code in soundscapy/audio/analysis_settings.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
get_enabled_metrics
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 soundscapy/audio/analysis_settings.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
|
get_metric_settings
get_metric_settings(library, metric)
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 soundscapy/audio/analysis_settings.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|
to_yaml
to_yaml(filepath)
Save the current settings to a YAML file.
PARAMETER | DESCRIPTION |
---|---|
filepath |
Path to save the YAML file.
TYPE:
|
Source code in soundscapy/audio/analysis_settings.py
176 177 178 179 180 181 182 183 184 185 186 187 |
|
update_setting
update_setting(library, metric, **kwargs)
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.
DEFAULT:
|
RAISES | DESCRIPTION |
---|---|
KeyError
|
If the specified library or metric is not found. |
Source code in soundscapy/audio/analysis_settings.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
|
validate_library_settings
classmethod
validate_library_settings(v)
Validate library settings.
Source code in soundscapy/audio/analysis_settings.py
114 115 116 117 118 119 120 |
|
ConfigManager
ConfigManager(config_path=None)
Manage configuration settings for audio analysis.
PARAMETER | DESCRIPTION |
---|---|
default_config_path |
Path to the default configuration file.
TYPE:
|
Source code in soundscapy/audio/analysis_settings.py
278 279 280 |
|
generate_minimal_config
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 soundscapy/audio/analysis_settings.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
|
load_config
load_config(config_path=None)
Load a configuration file or use the default configuration.
PARAMETER | DESCRIPTION |
---|---|
config_path |
Path to the configuration file. If None, uses the default configuration.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
AnalysisSettings
|
The loaded configuration. |
Source code in soundscapy/audio/analysis_settings.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|
merge_configs
merge_configs(override_config)
Merge the current configuration 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 soundscapy/audio/analysis_settings.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
|
save_config
save_config(filepath)
Save the current configuration to a file.
PARAMETER | DESCRIPTION |
---|---|
filepath |
Path to save the configuration file.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If no current configuration is loaded. |
Source code in soundscapy/audio/analysis_settings.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
|
LibrarySettings
Bases: RootModel
Settings for a library of metrics.
get_metric_settings
get_metric_settings(metric)
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 soundscapy/audio/analysis_settings.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
MetricSettings
Bases: BaseModel
Settings for an individual metric.
PARAMETER | DESCRIPTION |
---|---|
run |
Whether to run this metric.
TYPE:
|
main |
The main statistic to calculate.
TYPE:
|
statistics |
List of statistics to calculate.
TYPE:
|
channel |
List of channels to analyze.
TYPE:
|
label |
Label for the metric.
TYPE:
|
parallel |
Whether to run the metric in parallel.
TYPE:
|
func_args |
Additional arguments for the metric function.
TYPE:
|
check_main_in_statistics
classmethod
check_main_in_statistics(values)
Check that the main statistic is in the statistics list.
Source code in soundscapy/audio/analysis_settings.py
49 50 51 52 53 54 55 56 57 58 |
|
Binaural Metrics
soundscapy.audio.binaural
This module provides tools for working with binaural audio signals.
The main class, Binaural, extends the Signal class from the acoustics library to provide specialized functionality for binaural recordings. It supports various psychoacoustic metrics and analysis techniques using libraries such as mosqito, maad, and python-acoustics.
CLASS | DESCRIPTION |
---|---|
Binaural : A class for processing and analyzing binaural audio signals. |
|
Notes
This module requires the following external libraries: - acoustics - mosqito - maad - python-acoustics
Examples:
>>> # xdoctest: +SKIP
>>> from soundscapy.audio import Binaural
>>> signal = Binaural.from_wav("audio.wav")
>>> results = signal.process_all_metrics(analysis_settings)
Binaural
Bases: Signal
A class for processing and analyzing binaural audio signals.
This class extends the Signal class from the acoustics library to provide specialized functionality for binaural recordings. It supports various psychoacoustic metrics and analysis techniques using libraries such as mosqito, maad, and python-acoustics.
ATTRIBUTE | DESCRIPTION |
---|---|
fs |
Sampling frequency of the signal.
TYPE:
|
recording |
Name or identifier of the recording.
TYPE:
|
Notes
This class only supports 2-channel (stereo) audio signals.
__array_finalize__
__array_finalize__(obj)
Finalize the new Binaural object.
This method is called for all new Binaural objects.
PARAMETER | DESCRIPTION |
---|---|
obj |
The object from which the new object was created.
TYPE:
|
Source code in soundscapy/audio/binaural.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
__new__
__new__(data, fs, recording='Rec')
Create a new Binaural object.
PARAMETER | DESCRIPTION |
---|---|
data |
The audio data.
TYPE:
|
fs |
Sampling frequency of the signal.
TYPE:
|
recording |
Name or identifier of the recording. Default is "Rec".
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Binaural
|
A new Binaural object. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the input signal is not 2-channel. |
Source code in soundscapy/audio/binaural.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
calibrate_to
calibrate_to(decibel, inplace=False)
Calibrate the binaural signal to predefined Leq/dB levels.
This method allows calibration of both channels either to the same level or to different levels for each channel.
PARAMETER | DESCRIPTION |
---|---|
decibel |
Target calibration value(s) in dB (Leq). If a single value is provided, both channels will be calibrated to this level. If two values are provided, they will be applied to the left and right channels respectively.
TYPE:
|
inplace |
If True, modify the signal in place. If False, return a new calibrated signal. Default is False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Binaural
|
Calibrated Binaural signal. If inplace is True, returns self. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If decibel is not a float, or a list/tuple of two floats. |
Examples:
>>> # xdoctest: +SKIP
>>> signal = Binaural.from_wav("audio.wav")
>>> calibrated_signal = signal.calibrate_to([60, 62]) # Calibrate left channel to 60 dB and right to 62 dB
Source code in soundscapy/audio/binaural.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
from_wav
classmethod
from_wav(filename, calibrate_to=None, normalize=False, resample=None)
Load a wav file and return a Binaural object.
Overrides the Signal.from_wav method to return a Binaural object instead of a Signal object.
PARAMETER | DESCRIPTION |
---|---|
filename |
Filename of wav file to load.
TYPE:
|
calibrate_to |
Value(s) to calibrate to in dB (Leq). Can also handle np.ndarray and pd.Series of length 2. If only one value is passed, will calibrate both channels to the same value.
TYPE:
|
normalize |
Whether to normalize the signal. Default is False.
TYPE:
|
resample |
New sampling frequency to resample the signal to. Default is None
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Binaural
|
Binaural signal object of wav recording. |
See Also
acoustics.Signal.from_wav : Base method for loading wav files.
Source code in soundscapy/audio/binaural.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|
fs_resample
fs_resample(fs)
Resample the signal to a new sampling frequency.
PARAMETER | DESCRIPTION |
---|---|
fs |
New sampling frequency.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Binaural
|
Resampled Binaural signal. If inplace is True, returns self. |
See Also
acoustics.Signal.resample : Base method for resampling signals.
Source code in soundscapy/audio/binaural.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
|
maad_metric
maad_metric(metric, channel=('Left', 'Right'), as_df=True, metric_settings=None, func_args={})
Run a metric from the scikit-maad library.
Currently only supports running all of the alpha indices at once.
PARAMETER | DESCRIPTION |
---|---|
metric |
The metric to run.
TYPE:
|
channel |
Which channels to process. Default is ("Left", "Right").
TYPE:
|
as_df |
Whether to return a dataframe or not. Default is True. If True, returns a MultiIndex Dataframe with ("Recording", "Channel") as the index.
TYPE:
|
metric_settings |
Settings for metric analysis. Default is None.
TYPE:
|
func_args |
Additional arguments to pass to the underlying scikit-maad method.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict or DataFrame
|
Dictionary of results if as_df is False, otherwise a pandas DataFrame. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If metric name is not recognised. |
See Also
metrics.maad_metric_1ch metrics.maad_metric_2ch
Source code in soundscapy/audio/binaural.py
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 |
|
mosqito_metric
mosqito_metric(metric, statistics=(5, 10, 50, 90, 95, 'avg', 'max', 'min', 'kurt', 'skew'), label=None, channel=('Left', 'Right'), as_df=True, return_time_series=False, parallel=True, metric_settings=None, func_args={})
Run a metric from the mosqito library.
PARAMETER | DESCRIPTION |
---|---|
metric |
Metric to run from mosqito library.
TYPE:
|
statistics |
List of level statistics to calculate (e.g. L_5, L_90, etc.). Default is (5, 10, 50, 90, 95, "avg", "max", "min", "kurt", "skew").
TYPE:
|
label |
Label to use for the metric. If None, will pull from default label for that metric.
TYPE:
|
channel |
Which channels to process. Default is ("Left", "Right").
TYPE:
|
as_df |
Whether to return a dataframe or not. Default is True. If True, returns a MultiIndex Dataframe with ("Recording", "Channel") as the index.
TYPE:
|
return_time_series |
Whether to return the time series of the metric. Default is False. Cannot return time series if as_df is True.
TYPE:
|
parallel |
Whether to run the channels in parallel. Default is True. If False, will run each channel sequentially.
TYPE:
|
metric_settings |
Settings for metric analysis. Default is None.
TYPE:
|
func_args |
Any settings given here will override those in the other options. Can pass any args or *kwargs to the underlying python acoustics method.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict or DataFrame
|
Dictionary of results if as_df is False, otherwise a pandas DataFrame. |
See Also
binaural.mosqito_metric_2ch : Method for running metrics on 2 channels. binaural.mosqito_metric_1ch : Method for running metrics on 1 channel.
Source code in soundscapy/audio/binaural.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
|
process_all_metrics
process_all_metrics(analysis_settings, parallel=True)
Process all metrics specified in the analysis settings.
This method runs all enabled metrics from the provided AnalysisSettings object and compiles the results into a single DataFrame.
PARAMETER | DESCRIPTION |
---|---|
analysis_settings |
Configuration object specifying which metrics to run and their parameters.
TYPE:
|
parallel |
Whether to run calculations in parallel where possible. Default is True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
A MultiIndex DataFrame containing the results of all processed metrics. The index includes "Recording" and "Channel" levels. |
Notes
The parallel option primarily affects the MoSQITo metrics. Other metrics may not benefit from parallelization.
Examples:
>>> # xdoctest: +SKIP
>>> signal = Binaural.from_wav("audio.wav")
>>> settings = AnalysisSettings.from_yaml("settings.yaml")
>>> results = signal.process_all_metrics(settings)
Source code in soundscapy/audio/binaural.py
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 |
|
pyacoustics_metric
pyacoustics_metric(metric, statistics=(5, 10, 50, 90, 95, 'avg', 'max', 'min', 'kurt', 'skew'), label=None, channel=('Left', 'Right'), as_df=True, return_time_series=False, metric_settings=None, func_args={})
Run a metric from the python acoustics library.
PARAMETER | DESCRIPTION |
---|---|
metric |
The metric to run.
TYPE:
|
statistics |
List of level statistics to calculate (e.g. L_5, L_90, etc.). Default is (5, 10, 50, 90, 95, "avg", "max", "min", "kurt", "skew").
TYPE:
|
label |
Label to use for the metric. If None, will pull from default label for that metric.
TYPE:
|
channel |
Which channels to process. Default is ("Left", "Right").
TYPE:
|
as_df |
Whether to return a dataframe or not. Default is True. If True, returns a MultiIndex Dataframe with ("Recording", "Channel") as the index.
TYPE:
|
return_time_series |
Whether to return the time series of the metric. Default is False. Cannot return time series if as_df is True.
TYPE:
|
metric_settings |
Settings for metric analysis. Default is None.
TYPE:
|
func_args |
Any settings given here will override those in the other options. Can pass any args or *kwargs to the underlying python acoustics method.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict or DataFrame
|
Dictionary of results if as_df is False, otherwise a pandas DataFrame. |
See Also
metrics.pyacoustics_metric acoustics.standards_iso_tr_25417_2007.equivalent_sound_pressure_level : Base method for Leq calculation. acoustics.standards.iec_61672_1_2013.sound_exposure_level : Base method for SEL calculation. acoustics.standards.iec_61672_1_2013.time_weighted_sound_level : Base method for Leq level time series calculation.
Source code in soundscapy/audio/binaural.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
|
soundscapy.audio.metrics
This module provides functions for calculating various acoustic and psychoacoustic metrics for audio signals. It includes implementations for single-channel and two-channel signals, as well as wrapper functions for different libraries such as python-acoustics, MoSQITo, and scikit-maad.
FUNCTION | DESCRIPTION |
---|---|
_stat_calcs : Calculate various statistics for a time series array. |
|
mosqito_metric_1ch : Calculate a MoSQITo psychoacoustic metric for a single channel signal. |
|
maad_metric_1ch : Run a metric from the scikit-maad library on a single channel signal. |
|
pyacoustics_metric_1ch : Run a metric from the pyacoustics library on a single channel object. |
|
pyacoustics_metric_2ch : Run a metric from the python acoustics library on a Binaural object. |
|
mosqito_metric_2ch : Calculate metrics from MoSQITo for a two-channel signal. |
|
maad_metric_2ch : Run a metric from the scikit-maad library on a binaural signal. |
|
prep_multiindex_df : Prepare a MultiIndex dataframe from a dictionary of results. |
|
add_results : Add results to a MultiIndex dataframe. |
|
process_all_metrics : Process all metrics specified in the analysis settings for a binaural signal. |
|
Notes
This module relies on external libraries such as numpy, pandas, maad, mosqito, and scipy. Ensure these dependencies are installed before using this module.
add_results
add_results(results_df, metric_results)
Add results to MultiIndex dataframe.
PARAMETER | DESCRIPTION |
---|---|
results_df |
MultiIndex dataframe to add results to.
TYPE:
|
metric_results |
MultiIndex dataframe of results to add.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
Index includes "Recording" and "Channel" with a column for each index. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the input DataFrames are not in the expected format. |
Source code in soundscapy/audio/metrics.py
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 |
|
maad_metric_1ch
maad_metric_1ch(s, metric, as_df=False, func_args={})
Run a metric from the scikit-maad library (or suite of indices) on a single channel signal.
Currently only supports running all of the alpha indices at once.
PARAMETER | DESCRIPTION |
---|---|
s |
Single channel signal to calculate the alpha indices for.
TYPE:
|
metric |
Metric to calculate.
TYPE:
|
as_df |
Whether to return a pandas DataFrame, by default False. If True, returns a MultiIndex Dataframe with ("Recording", "Channel") as the index.
TYPE:
|
func_args |
Additional keyword arguments to pass to the metric function, by default {}.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict or DataFrame
|
Dictionary of results if as_df is False, otherwise a pandas DataFrame. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the signal is not single-channel or if an unrecognized metric is specified. |
See Also
maad.features.all_spectral_alpha_indices maad.features.all_temporal_alpha_indices
Source code in soundscapy/audio/metrics.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
|
maad_metric_2ch
maad_metric_2ch(b, metric, channel_names=('Left', 'Right'), as_df=False, func_args={})
Run a metric from the scikit-maad library (or suite of indices) on a binaural signal.
Currently only supports running all the alpha indices at once.
PARAMETER | DESCRIPTION |
---|---|
b |
Binaural signal to calculate the alpha indices for.
TYPE:
|
metric |
Metric to calculate.
TYPE:
|
channel_names |
Custom names for the channels, by default ("Left", "Right").
TYPE:
|
as_df |
Whether to return a pandas DataFrame, by default False. If True, returns a MultiIndex Dataframe with ("Recording", "Channel") as the index.
TYPE:
|
func_args |
Additional arguments to pass to the metric function, by default {}.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict or DataFrame
|
Dictionary of results if as_df is False, otherwise a pandas DataFrame. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the input signal is not 2-channel or if an unrecognized metric is specified. |
See Also
scikit-maad library maad_metric_1ch
Source code in soundscapy/audio/metrics.py
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 |
|
mosqito_metric_1ch
mosqito_metric_1ch(s, metric, statistics=(5, 10, 50, 90, 95, 'avg', 'max', 'min', 'kurt', 'skew'), label=None, as_df=False, return_time_series=False, func_args={})
Calculate a MoSQITo psychoacoustic metric for a single channel signal.
PARAMETER | DESCRIPTION |
---|---|
s |
Single channel signal object to analyze.
TYPE:
|
metric |
Name of the metric to calculate. Options are "loudness_zwtv", "roughness_dw", "sharpness_din_from_loudness", "sharpness_din_perseg", or "sharpness_din_tv".
TYPE:
|
statistics |
Statistics to calculate on the metric results.
TYPE:
|
label |
Label to use for the metric in the results. If None, uses a default label.
TYPE:
|
as_df |
If True, return results as a pandas DataFrame. Otherwise, return a dictionary.
TYPE:
|
return_time_series |
If True, include the full time series in the results.
TYPE:
|
func_args |
Additional arguments to pass to the underlying MoSQITo function.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[dict, DataFrame]
|
Results of the metric calculation and statistics. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the input signal is not single-channel or if an unrecognized metric is specified. |
Examples:
>>> # xdoctest: +SKIP
>>> from soundscapy.audio import Binaural
>>> signal = Binaural.from_wav("audio.wav", resample=480000)
>>> results = mosqito_metric_1ch(signal[0], "loudness_zwtv", as_df=True)
Source code in soundscapy/audio/metrics.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|
mosqito_metric_2ch
mosqito_metric_2ch(b, metric, statistics=(5, 10, 50, 90, 95, 'avg', 'max', 'min', 'kurt', 'skew'), label=None, channel_names=('Left', 'Right'), as_df=False, return_time_series=False, parallel=True, func_args={})
Calculate metrics from MoSQITo for a two-channel signal with optional parallel processing.
PARAMETER | DESCRIPTION |
---|---|
b |
Binaural signal to calculate the sound quality indices for.
TYPE:
|
metric |
TYPE:
|
statistics |
List of level statistics to calculate (e.g. L_5, L_90, etc.).
TYPE:
|
label |
Label to use for the metric in the results dictionary. If None, will pull from default label for that metric given in DEFAULT_LABELS.
TYPE:
|
channel_names |
Custom names for the channels, by default ("Left", "Right").
TYPE:
|
as_df |
Whether to return a pandas DataFrame, by default False. If True, returns a MultiIndex Dataframe with ("Recording", "Channel") as the index.
TYPE:
|
return_time_series |
Whether to return the time series of the metric, by default False. Only works for metrics that return a time series array. Cannot be returned in a dataframe.
TYPE:
|
parallel |
Whether to process channels in parallel, by default True.
TYPE:
|
func_args |
Additional arguments to pass to the metric function, by default {}.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict or DataFrame
|
Dictionary of results if as_df is False, otherwise a pandas DataFrame. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the input signal is not 2-channel. |
Source code in soundscapy/audio/metrics.py
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 |
|
prep_multiindex_df
prep_multiindex_df(dictionary, label='Leq', incl_metric=True)
Prepare a MultiIndex dataframe from a dictionary of results.
PARAMETER | DESCRIPTION |
---|---|
dictionary |
Dict of results with recording name as key, channels {"Left", "Right"} as second key, and Leq metric as value.
TYPE:
|
label |
Name of metric included, by default "Leq".
TYPE:
|
incl_metric |
Whether to include the metric value in the resulting dataframe, by default True. If False, will only set up the DataFrame with the proper MultiIndex.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
Index includes "Recording" and "Channel" with a column for each index if |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the input dictionary is not in the expected format. |
Source code in soundscapy/audio/metrics.py
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 |
|
process_all_metrics
process_all_metrics(b, analysis_settings, parallel=True)
Process all metrics specified in the analysis settings for a binaural signal.
This function runs through all enabled metrics in the provided analysis settings, computes them for the given binaural signal, and compiles the results into a single DataFrame.
PARAMETER | DESCRIPTION |
---|---|
b |
Binaural signal object to process.
TYPE:
|
analysis_settings |
Configuration object specifying which metrics to run and their parameters.
TYPE:
|
parallel |
If True, run applicable calculations in parallel. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
A MultiIndex DataFrame containing results from all processed metrics. The index includes "Recording" and "Channel" levels. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If there's an error processing any of the metrics. |
Notes
The parallel option primarily affects the MoSQITo metrics. Other metrics may not benefit from parallelization.
Examples:
>>> # xdoctest: +SKIP
>>> from soundscapy.audio import Binaural
>>> from soundscapy import AnalysisSettings
>>> signal = Binaural.from_wav("audio.wav", resample=480000)
>>> settings = AnalysisSettings.from_yaml("settings.yaml")
>>> results = process_all_metrics(signal,settings)
Source code in soundscapy/audio/metrics.py
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 |
|
pyacoustics_metric_1ch
pyacoustics_metric_1ch(s, metric, statistics=(5, 10, 50, 90, 95, 'avg', 'max', 'min', 'kurt', 'skew'), label=None, as_df=False, return_time_series=False, func_args={})
Run a metric from the pyacoustics library on a single channel object.
PARAMETER | DESCRIPTION |
---|---|
s |
Single channel signal to calculate the metric for.
TYPE:
|
metric |
The metric to run.
TYPE:
|
statistics |
List of level statistics to calculate (e.g. L_5, L_90, etc).
TYPE:
|
label |
Label to use for the metric in the results dictionary. If None, will pull from default label for that metric given in DEFAULT_LABELS.
TYPE:
|
as_df |
Whether to return a pandas DataFrame, by default False. If True, returns a MultiIndex Dataframe with ("Recording", "Channel") as the index.
TYPE:
|
return_time_series |
Whether to return the time series of the metric, by default False. Cannot return time series if as_df is True.
TYPE:
|
func_args |
Additional keyword arguments to pass to the metric function, by default {}.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict or DataFrame
|
Dictionary of the calculated statistics or a pandas DataFrame. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the signal is not single-channel or if an unrecognized metric is specified. |
See Also
acoustics
Source code in soundscapy/audio/metrics.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
|
pyacoustics_metric_2ch
pyacoustics_metric_2ch(b, metric, statistics=(5, 10, 50, 90, 95, 'avg', 'max', 'min', 'kurt', 'skew'), label=None, channel_names=('Left', 'Right'), as_df=False, return_time_series=False, func_args={})
Run a metric from the python acoustics library on a Binaural object.
PARAMETER | DESCRIPTION |
---|---|
b |
Binaural signal to calculate the metric for.
TYPE:
|
metric |
The metric to run.
TYPE:
|
statistics |
List of level statistics to calculate (e.g. L_5, L_90, etc).
TYPE:
|
label |
Label to use for the metric in the results dictionary. If None, will pull from default label for that metric given in DEFAULT_LABELS.
TYPE:
|
channel_names |
Custom names for the channels, by default ("Left", "Right").
TYPE:
|
as_df |
Whether to return a pandas DataFrame, by default False. If True, returns a MultiIndex Dataframe with ("Recording", "Channel") as the index.
TYPE:
|
return_time_series |
Whether to return the time series of the metric, by default False. Cannot return time series if as_df is True.
TYPE:
|
func_args |
Arguments to pass to the metric function, by default {}.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict or DataFrame
|
Dictionary of results if as_df is False, otherwise a pandas DataFrame. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the input signal is not 2-channel. |
See Also
pyacoustics_metric_1ch
Source code in soundscapy/audio/metrics.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
|
Parallel Processing
soundscapy.audio.parallel_processing
This module provides functions for parallel processing of binaural audio files.
It includes functions to load and analyze binaural files, as well as to process multiple files in parallel using concurrent.futures.
Functions: load_analyse_binaural: Load and analyze a single binaural file. parallel_process: Process multiple binaural files in parallel.
Note: This module requires the tqdm library for progress bars and concurrent.futures for parallel processing. It uses loguru for logging.
load_analyse_binaural
load_analyse_binaural(wav_file, levels, analysis_settings, parallel_mosqito=True, resample=None)
Load and analyze a single binaural audio file.
PARAMETER | DESCRIPTION |
---|---|
resample |
TYPE:
|
wav_file |
Path to the WAV file.
TYPE:
|
levels |
Dictionary with calibration levels for each channel.
TYPE:
|
analysis_settings |
Analysis settings object.
TYPE:
|
parallel_mosqito |
Whether to process MoSQITo metrics in parallel. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
DataFrame with analysis results. |
Source code in soundscapy/audio/parallel_processing.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
parallel_process
parallel_process(wav_files, results_df, levels, analysis_settings, max_workers=None, parallel_mosqito=True, resample=None)
Process multiple binaural files in parallel.
PARAMETER | DESCRIPTION |
---|---|
resample |
TYPE:
|
wav_files |
List of WAV files to process.
TYPE:
|
results_df |
Initial results DataFrame to update.
TYPE:
|
levels |
Dictionary with calibration levels for each file.
TYPE:
|
analysis_settings |
Analysis settings object.
TYPE:
|
max_workers |
Maximum number of worker processes. If None, it will default to the number of processors on the machine.
TYPE:
|
parallel_mosqito |
Whether to process MoSQITo metrics in parallel within each file. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
Updated results DataFrame with analysis results for all files. |
Source code in soundscapy/audio/parallel_processing.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
tqdm_write_sink
tqdm_write_sink(message)
A custom sink for loguru that writes messages using tqdm.write().
This ensures that log messages don't interfere with tqdm progress bars.
Source code in soundscapy/audio/parallel_processing.py
38 39 40 41 42 43 44 |
|