analyzeAudio 0.3.0__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/PKG-INFO +15 -6
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/README.md +13 -4
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/__init__.py +1 -1
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/_beDRY.py +6 -0
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/_theTypes.py +0 -1
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/analyze.py +2 -1
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/analyzersUseFilename/__init__.py +0 -3
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/analyzersUseFilename/_ebur128.py +20 -4
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/analyzersUseFilename/_wideRange.py +11 -6
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/analyzersUseSpectrogram.py +128 -41
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/analyzersUseTensor.py +50 -2
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/contestsSpectrogram.py +45 -7
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/contestsTensor.py +141 -84
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/contestsTensorSpectrogram.py +54 -19
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/registry.py +5 -8
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio.egg-info/PKG-INFO +15 -6
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio.egg-info/SOURCES.txt +4 -1
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio.egg-info/requires.txt +1 -1
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio.egg-info/top_level.txt +0 -1
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/pyproject.toml +2 -2
- analyzeaudio-0.4.0/tests/__init__.py +14 -0
- analyzeaudio-0.4.0/tests/_theSSOT.py +21 -0
- analyzeaudio-0.4.0/tests/_theTypes.py +80 -0
- analyzeaudio-0.4.0/tests/conftest.py +183 -0
- analyzeaudio-0.4.0/tests/dataSamples/SpeakSoftly_BrokenMan60sec/expected.py +313 -0
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/tests/dataSamples/expected.py +100 -1
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/tests/test_analyzersUseFilename.py +46 -46
- analyzeaudio-0.4.0/tests/test_analyzersUseSpectrogram.py +72 -0
- analyzeaudio-0.4.0/tests/test_analyzersUseTensor.py +34 -0
- analyzeaudio-0.4.0/tests/test_analyzersUseWaveform.py +43 -0
- analyzeaudio-0.4.0/tests/test_contestsSpectrogram.py +50 -0
- analyzeaudio-0.4.0/tests/test_contestsTensor.py +113 -0
- analyzeaudio-0.4.0/tests/test_contestsTensorSpectrogram.py +92 -0
- analyzeaudio-0.3.0/analyzeAudio/analyzersUseFilename/_contests.py +0 -235
- analyzeaudio-0.3.0/tests/__init__.py +0 -5
- analyzeaudio-0.3.0/tests/_theTypes.py +0 -27
- analyzeaudio-0.3.0/tests/conftest.py +0 -53
- analyzeaudio-0.3.0/tests/dataSamples/SpeakSoftly_BrokenMan60sec/expected.py +0 -105
- analyzeaudio-0.3.0/tests/test_analyzersUseSpectrogram.py +0 -45
- analyzeaudio-0.3.0/tests/test_analyzersUseTensor.py +0 -3
- analyzeaudio-0.3.0/tests/test_analyzersUseWaveform.py +0 -40
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/LICENSE +0 -0
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/_misfit.py +0 -0
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/_theSSOT.py +0 -0
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/analyzersUseFilename/_aspectralstats.py +0 -0
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/analyzersUseFilename/_astats.py +0 -0
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/analyzersUseFilename/_pythonator.py +0 -0
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/analyzersUseWaveform.py +0 -0
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/ffmpeg.py +0 -0
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio/py.typed +0 -0
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio.egg-info/dependency_links.txt +0 -0
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/analyzeAudio.egg-info/entry_points.txt +0 -0
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/setup.cfg +0 -0
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/tests/dataSamples/SpeakSoftly_BrokenMan60sec/__init__.py +0 -0
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/tests/dataSamples/__init__.py +0 -0
- {analyzeaudio-0.3.0 → analyzeaudio-0.4.0}/tests/test_analyzersUseTensorSpectrogram.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: analyzeAudio
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Measure one or more aspects of one or more audio files.
|
|
5
5
|
Author-email: Hunter Hogan <HunterHogan@pm.me>
|
|
6
6
|
License-Expression: CC-BY-NC-4.0
|
|
@@ -34,7 +34,7 @@ Requires-Python: >=3.10
|
|
|
34
34
|
Description-Content-Type: text/markdown
|
|
35
35
|
License-File: LICENSE
|
|
36
36
|
Requires-Dist: auraloss
|
|
37
|
-
Requires-Dist: hunterHearsPy
|
|
37
|
+
Requires-Dist: hunterHearsPy>=1.0.3
|
|
38
38
|
Requires-Dist: hunterMakesPy>=0.7.0
|
|
39
39
|
Requires-Dist: librosa
|
|
40
40
|
Requires-Dist: numpy
|
|
@@ -198,7 +198,7 @@ If a requested name is unavailable, that value is `"not found"`.
|
|
|
198
198
|
from pathlib import Path
|
|
199
199
|
from analyzeAudio import analyzeAudioListPathFilenames
|
|
200
200
|
|
|
201
|
-
listPathFilenames =
|
|
201
|
+
listPathFilenames = tuple(Path("audio").glob("*.wav"))
|
|
202
202
|
listAspectNames = [
|
|
203
203
|
"LUFS integrated",
|
|
204
204
|
"LUFS loudness range",
|
|
@@ -435,10 +435,20 @@ whatAspects
|
|
|
435
435
|
whatContests
|
|
436
436
|
```
|
|
437
437
|
|
|
438
|
+
## API standardization
|
|
439
|
+
|
|
440
|
+
A top priority for this package is a public API that is as standardized as
|
|
441
|
+
possible across filename, waveform, spectrogram, tensor, and contest analyzers.
|
|
442
|
+
The package wraps libraries with very different calling conventions, but analyzer
|
|
443
|
+
function signatures should model this package's dispatcher inputs, not every
|
|
444
|
+
underlying library option.
|
|
445
|
+
|
|
438
446
|
## Wishlist
|
|
439
447
|
|
|
440
|
-
- []
|
|
441
|
-
- []
|
|
448
|
+
- [ ] Overhaul the semiotic system.
|
|
449
|
+
- [ ] Install FFmpeg in GitHub Actions for testing.
|
|
450
|
+
- [ ] Improve speed
|
|
451
|
+
- [ ] Sophisticated caching of large objects and un-hashable objects.
|
|
442
452
|
|
|
443
453
|
## Reference materials
|
|
444
454
|
|
|
@@ -588,7 +598,6 @@ whatContests
|
|
|
588
598
|
- Free author PDF: [Jonathan Le Roux](https://www.jonathanleroux.org/pdf/LeRoux2019ICASSP05sdr.pdf)
|
|
589
599
|
- Implementations:
|
|
590
600
|
- [Lightning-AI/torchmetrics](https://github.com/Lightning-AI/torchmetrics)
|
|
591
|
-
- [FFprobe `asisdr` filter](https://ffmpeg.org/ffprobe-all.html#asisdr)
|
|
592
601
|
|
|
593
602
|
### Loudness Metering: EBU Mode Metering to Supplement Loudness Normalisation
|
|
594
603
|
|
|
@@ -145,7 +145,7 @@ If a requested name is unavailable, that value is `"not found"`.
|
|
|
145
145
|
from pathlib import Path
|
|
146
146
|
from analyzeAudio import analyzeAudioListPathFilenames
|
|
147
147
|
|
|
148
|
-
listPathFilenames =
|
|
148
|
+
listPathFilenames = tuple(Path("audio").glob("*.wav"))
|
|
149
149
|
listAspectNames = [
|
|
150
150
|
"LUFS integrated",
|
|
151
151
|
"LUFS loudness range",
|
|
@@ -382,10 +382,20 @@ whatAspects
|
|
|
382
382
|
whatContests
|
|
383
383
|
```
|
|
384
384
|
|
|
385
|
+
## API standardization
|
|
386
|
+
|
|
387
|
+
A top priority for this package is a public API that is as standardized as
|
|
388
|
+
possible across filename, waveform, spectrogram, tensor, and contest analyzers.
|
|
389
|
+
The package wraps libraries with very different calling conventions, but analyzer
|
|
390
|
+
function signatures should model this package's dispatcher inputs, not every
|
|
391
|
+
underlying library option.
|
|
392
|
+
|
|
385
393
|
## Wishlist
|
|
386
394
|
|
|
387
|
-
- []
|
|
388
|
-
- []
|
|
395
|
+
- [ ] Overhaul the semiotic system.
|
|
396
|
+
- [ ] Install FFmpeg in GitHub Actions for testing.
|
|
397
|
+
- [ ] Improve speed
|
|
398
|
+
- [ ] Sophisticated caching of large objects and un-hashable objects.
|
|
389
399
|
|
|
390
400
|
## Reference materials
|
|
391
401
|
|
|
@@ -535,7 +545,6 @@ whatContests
|
|
|
535
545
|
- Free author PDF: [Jonathan Le Roux](https://www.jonathanleroux.org/pdf/LeRoux2019ICASSP05sdr.pdf)
|
|
536
546
|
- Implementations:
|
|
537
547
|
- [Lightning-AI/torchmetrics](https://github.com/Lightning-AI/torchmetrics)
|
|
538
|
-
- [FFprobe `asisdr` filter](https://ffmpeg.org/ffprobe-all.html#asisdr)
|
|
539
548
|
|
|
540
549
|
### Loudness Metering: EBU Mode Metering to Supplement Loudness Normalisation
|
|
541
550
|
|
|
@@ -10,7 +10,7 @@ from analyzeAudio._theTypes import (
|
|
|
10
10
|
ArrayAspectSpectrogramFramewise as ArrayAspectSpectrogramFramewise, ArrayAspectWaveformFramewise as ArrayAspectWaveformFramewise,
|
|
11
11
|
ArrayChannelData as ArrayChannelData, ArrayOverallData as ArrayOverallData, Audio as Audio,
|
|
12
12
|
AuralossChromaSTFTLoss as AuralossChromaSTFTLoss, BleedFull as BleedFull, BleedFullArray as BleedFullArray,
|
|
13
|
-
ParametersMelSpectrogram as ParametersMelSpectrogram, parameterSpecifications as parameterSpecifications,
|
|
13
|
+
ParametersMelSpectrogram as ParametersMelSpectrogram, parameterSpecifications as parameterSpecifications,
|
|
14
14
|
SpectrogramMagnitude as SpectrogramMagnitude, SpectrogramPower as SpectrogramPower, typeReturned as typeReturned)
|
|
15
15
|
|
|
16
16
|
# isort: split
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from operator import neg
|
|
3
4
|
from typing import TYPE_CHECKING
|
|
4
5
|
|
|
5
6
|
if TYPE_CHECKING:
|
|
@@ -23,5 +24,10 @@ def truncateTensors(listTensors: Sequence[Tensor]) -> tuple[Tensor, ...]:
|
|
|
23
24
|
truncate: int = min(tensor.shape[-1] for tensor in listTensors)
|
|
24
25
|
return tuple(tensor[..., 0:truncate] for tensor in listTensors)
|
|
25
26
|
|
|
27
|
+
|
|
28
|
+
def KValue(unscaled: float, K: float = 10.0) -> float:
|
|
29
|
+
unscaled = max(min(unscaled, K), neg(K) + 1e-6)
|
|
30
|
+
return 100.0 * math.log1p(unscaled + K) / math.log1p(2 * K)
|
|
31
|
+
|
|
26
32
|
# TODO create DRY `return 20 * numpy.log10(arrayRMS, where=(arrayRMS != 0), out=None)`
|
|
27
33
|
# If possible, one function for in-place and copy variants.
|
|
@@ -41,7 +41,6 @@ class ParametersMelSpectrogram(TypedDict, total=False):
|
|
|
41
41
|
|
|
42
42
|
Audio: TypeAlias = ndarray[tuple[int, ...], dtype[floating[Any]]]
|
|
43
43
|
ArrayAspect: TypeAlias = ndarray[tuple[int, ...], dtype[floating[Any]]]
|
|
44
|
-
Spectrogram: TypeAlias = ndarray[tuple[int, int, int], dtype[complexfloating[Any, Any]]]
|
|
45
44
|
SpectrogramMagnitude: TypeAlias = ndarray[tuple[int, int, int], dtype[floating[Any]]]
|
|
46
45
|
SpectrogramPower: TypeAlias = ndarray[tuple[int, int, int], dtype[floating[Any]]]
|
|
47
46
|
ArrayAspectSpectrogramFramewise: TypeAlias = ndarray[tuple[int, Literal[1], int], dtype[floating[Any]]]
|
|
@@ -31,9 +31,10 @@ import soundfile
|
|
|
31
31
|
import torch
|
|
32
32
|
|
|
33
33
|
if TYPE_CHECKING:
|
|
34
|
-
from analyzeAudio import Audio,
|
|
34
|
+
from analyzeAudio import Audio, SpectrogramMagnitude, SpectrogramPower
|
|
35
35
|
from collections.abc import Sequence
|
|
36
36
|
from concurrent.futures import Future
|
|
37
|
+
from hunterHearsPy import Spectrogram
|
|
37
38
|
from os import PathLike
|
|
38
39
|
from torch import Tensor
|
|
39
40
|
from typing import Any
|
|
@@ -36,9 +36,6 @@ from analyzeAudio.analyzersUseFilename._astats import (
|
|
|
36
36
|
analyzeRMS_trough as analyzeRMS_trough, analyzeRMS_troughOverall as analyzeRMS_troughOverall,
|
|
37
37
|
analyzeZero_crossings as analyzeZero_crossings, analyzeZero_crossings_rate as analyzeZero_crossings_rate,
|
|
38
38
|
analyzeZero_crossings_rateOverall as analyzeZero_crossings_rateOverall, analyzeZero_crossingsTotal as analyzeZero_crossingsTotal)
|
|
39
|
-
from analyzeAudio.analyzersUseFilename._contests import (
|
|
40
|
-
analyzeKPSNRmean as analyzeKPSNRmean, analyzeKSDRmean as analyzeKSDRmean, analyzeKSI_SDRmean as analyzeKSI_SDRmean,
|
|
41
|
-
analyzePSNRmean as analyzePSNRmean, analyzeSDRmean as analyzeSDRmean, analyzeSI_SDRmean as analyzeSI_SDRmean)
|
|
42
39
|
from analyzeAudio.analyzersUseFilename._ebur128 import (
|
|
43
40
|
analyzeLRA as analyzeLRA, analyzeLRAOverall as analyzeLRAOverall, analyzeLUFShigh as analyzeLUFShigh,
|
|
44
41
|
analyzeLUFShighOverall as analyzeLUFShighOverall, analyzeLUFSIntegrated as analyzeLUFSIntegrated,
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pyright: reportArgumentType=false
|
|
2
|
+
# pyright: reportAssignmentType=false
|
|
2
3
|
# pyright: reportReturnType=false
|
|
4
|
+
# ty:ignore[invalid-argument-type]
|
|
5
|
+
# ty:ignore[invalid-assignment]
|
|
6
|
+
# ty:ignore[invalid-return-type]
|
|
3
7
|
"""Analyzers that use the filename of an audio file to analyze its audio data."""
|
|
4
8
|
from __future__ import annotations
|
|
5
9
|
|
|
@@ -9,13 +13,25 @@ from typing import Any, TYPE_CHECKING
|
|
|
9
13
|
import numpy
|
|
10
14
|
|
|
11
15
|
if TYPE_CHECKING:
|
|
12
|
-
from analyzeAudio import ArrayOverallData
|
|
16
|
+
from analyzeAudio import ArrayChannelData, ArrayOverallData
|
|
13
17
|
from os import PathLike
|
|
14
18
|
|
|
15
19
|
arrayOverallDataEmpty: ArrayOverallData = numpy.array([], dtype=numpy.float64).reshape(0)
|
|
16
20
|
|
|
17
|
-
# TODO
|
|
18
|
-
|
|
21
|
+
# TODO one function to return one array with all LUFS aspects.
|
|
22
|
+
|
|
23
|
+
def analyzeTruePeakChannel(pathFilename: str | PathLike[Any]) -> ArrayChannelData:
|
|
24
|
+
keepGoing: bool = True
|
|
25
|
+
channel: int = 0
|
|
26
|
+
listAspectChannels: list[ArrayOverallData] = [ffprobeAllInclusiveCache(pathFilename).get(f'true_peaks_ch{channel}', arrayOverallDataEmpty)]
|
|
27
|
+
while keepGoing:
|
|
28
|
+
channel += 1
|
|
29
|
+
aspectChannel = ffprobeAllInclusiveCache(pathFilename).get(f'true_peaks_ch{channel}', None)
|
|
30
|
+
if aspectChannel is not None:
|
|
31
|
+
listAspectChannels.append(aspectChannel)
|
|
32
|
+
else:
|
|
33
|
+
keepGoing = False
|
|
34
|
+
return numpy.stack(listAspectChannels, axis=0)
|
|
19
35
|
|
|
20
36
|
def analyzeTruePeak(pathFilename: str | PathLike[Any]) -> ArrayOverallData:
|
|
21
37
|
"""Compute the true-peak trajectory of an audio file.
|
|
@@ -12,14 +12,16 @@ if TYPE_CHECKING:
|
|
|
12
12
|
from analyzeAudio import ArrayChannelData, ArrayOverallData
|
|
13
13
|
from os import PathLike
|
|
14
14
|
|
|
15
|
+
# https://ffmpeg.org/ffmpeg-filters.html#drmeter
|
|
16
|
+
# Potential aspect, but it doesn't work.
|
|
17
|
+
# ffmpeg -hide_banner -i /data/MusicDemixingBenchmarks/synthetic/melody_000_mixture.wav -filter_complex "[0]ebur128,drmeter,astats" -map 0 -f null -
|
|
18
|
+
|
|
15
19
|
@cache
|
|
16
20
|
def ffprobeAllInclusiveCache(pathFilename: str | PathLike[Any]) -> dict[str, ArrayChannelData | ArrayOverallData]:
|
|
17
|
-
"""I use this shared extractor to collect
|
|
18
|
-
|
|
19
|
-
(AI generated docstring)
|
|
21
|
+
"""I use this shared extractor to collect audio aspects from one analysis pass.
|
|
20
22
|
|
|
21
|
-
I use this function to convert one structured analysis result into a dictionary of
|
|
22
|
-
|
|
23
|
+
I use this function to convert one structured analysis result into a dictionary of array audio
|
|
24
|
+
aspects.
|
|
23
25
|
|
|
24
26
|
Parameters
|
|
25
27
|
----------
|
|
@@ -81,6 +83,9 @@ def ffprobeAllInclusiveCache(pathFilename: str | PathLike[Any]) -> dict[str, Arr
|
|
|
81
83
|
|
|
82
84
|
# TODO Bit_depth: 'Bit_depth', 'Bit_depth2', 'Bit_depth3', 'Bit_depth4',
|
|
83
85
|
|
|
84
|
-
# If I ran two passes of the filter, I could force per-frame values for all aspects with
|
|
86
|
+
# If I ran two passes of the filter, I could force per-frame values for all aspects with
|
|
87
|
+
# `reset=1`. astats is pretty fast because there are no transformations. But I would need to
|
|
88
|
+
# change pythonator because it will use the same key names for both passes, overwriting the
|
|
89
|
+
# first pass.
|
|
85
90
|
|
|
86
91
|
return dictionaryAspects
|
|
@@ -6,13 +6,13 @@ from numpy import dtype, ndarray
|
|
|
6
6
|
from typing import Any, TYPE_CHECKING
|
|
7
7
|
import librosa
|
|
8
8
|
import numpy
|
|
9
|
+
import sys
|
|
10
|
+
import warnings
|
|
9
11
|
|
|
10
12
|
if TYPE_CHECKING:
|
|
11
13
|
from analyzeAudio import ArrayAspect, ArrayAspectSpectrogramFramewise, SpectrogramMagnitude, SpectrogramPower
|
|
12
14
|
from numpy import float32
|
|
13
15
|
|
|
14
|
-
# TODO `analyzeRMSSpectrogram`, `librosa.feature.rms(S=spectrogramMagnitude)`.
|
|
15
|
-
|
|
16
16
|
def analyzeChromagram(spectrogramPower: SpectrogramPower, sampleRate: int, **keywordArguments: Any) -> ndarray[tuple[int, int, int], dtype[float32]]:
|
|
17
17
|
"""Compute octave-equivalent pitch-class energy over time.
|
|
18
18
|
|
|
@@ -58,7 +58,21 @@ def analyzeChromagram(spectrogramPower: SpectrogramPower, sampleRate: int, **key
|
|
|
58
58
|
using a HMM with supervised learning. Proceedings of the International Society for Music
|
|
59
59
|
Information Retrieval, 133–137. https://ccrma.stanford.edu/~kglee/pubs/klee-ismir06.pdf
|
|
60
60
|
"""
|
|
61
|
-
|
|
61
|
+
with warnings.catch_warnings(record=True) as warningMessages:
|
|
62
|
+
warnings.simplefilter('always', UserWarning)
|
|
63
|
+
chromagram = librosa.feature.chroma_stft(S=spectrogramPower, sr=sampleRate, **keywordArguments)
|
|
64
|
+
|
|
65
|
+
for warningMessage in warningMessages:
|
|
66
|
+
if str(warningMessage.message) == 'Trying to estimate tuning from empty frequency set.':
|
|
67
|
+
message: str = (
|
|
68
|
+
f'I could not estimate chroma tuning in `analyzeChromagram({spectrogramPower.shape = }, {sampleRate = })` '
|
|
69
|
+
'because librosa found no usable pitch frequencies. The chromagram was still computed.'
|
|
70
|
+
)
|
|
71
|
+
sys.stderr.write(message + '\n')
|
|
72
|
+
else:
|
|
73
|
+
warnings.warn(str(warningMessage.message), warningMessage.category, stacklevel=2)
|
|
74
|
+
|
|
75
|
+
return chromagram
|
|
62
76
|
|
|
63
77
|
@registrationAudioAspect('Chromagram mean')
|
|
64
78
|
def analyzeChromagramMean(spectrogramPower: SpectrogramPower, sampleRate: int, **keywordArguments: Any) -> float:
|
|
@@ -72,68 +86,78 @@ def analyzeChromagramMean(spectrogramPower: SpectrogramPower, sampleRate: int, *
|
|
|
72
86
|
"""
|
|
73
87
|
return float(analyzeChromagram(spectrogramPower, sampleRate, **keywordArguments).mean().item())
|
|
74
88
|
|
|
75
|
-
def
|
|
76
|
-
"""Compute
|
|
89
|
+
def analyzeRMSSpectrogram(spectrogramMagnitude: SpectrogramMagnitude, **keywordArguments: Any) -> ArrayAspectSpectrogramFramewise:
|
|
90
|
+
"""Compute framewise root-mean-square magnitude from a spectrogram.
|
|
77
91
|
|
|
78
92
|
(AI generated docstring)
|
|
79
93
|
|
|
80
|
-
You can use this function to
|
|
81
|
-
|
|
82
|
-
|
|
94
|
+
You can use this function to compute per-frame root-mean-square (RMS) magnitude from
|
|
95
|
+
`spectrogramMagnitude`. This is a thin wrapper around `librosa.feature.rms` that uses the
|
|
96
|
+
spectrogram input path instead of deriving a spectrogram from a waveform.
|
|
83
97
|
|
|
84
98
|
Parameters
|
|
85
99
|
----------
|
|
86
100
|
spectrogramMagnitude : SpectrogramMagnitude
|
|
87
|
-
Magnitude-domain spectral representation
|
|
101
|
+
Magnitude-domain spectral representation whose framewise RMS magnitude is measured.
|
|
88
102
|
keywordArguments : Any
|
|
89
|
-
Additional keyword arguments
|
|
103
|
+
Additional keyword arguments passed to `librosa.feature.rms`.
|
|
90
104
|
|
|
91
105
|
Returns
|
|
92
106
|
-------
|
|
93
|
-
|
|
94
|
-
Framewise
|
|
95
|
-
corresponds to one octave band.
|
|
107
|
+
rootMeanSquare : ArrayAspectSpectrogramFramewise
|
|
108
|
+
Framewise root-mean-square magnitude.
|
|
96
109
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
octave-band partition : equation
|
|
100
|
-
```
|
|
101
|
-
Let Bᵢ ≜ i-th octave band
|
|
102
|
-
f_min ≜ lower cutoff of the first band
|
|
110
|
+
"""
|
|
111
|
+
return librosa.feature.rms(S=spectrogramMagnitude, **keywordArguments)
|
|
103
112
|
|
|
104
|
-
|
|
105
|
-
|
|
113
|
+
@registrationAudioAspect('RMS Spectrogram mean')
|
|
114
|
+
def analyzeRMSSpectrogramMean(spectrogramMagnitude: SpectrogramMagnitude, **keywordArguments: Any) -> float:
|
|
115
|
+
"""Aspect 'RMS Spectrogram mean': mean framewise RMS magnitude.
|
|
106
116
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
Pᵢ ≜ mean of the largest α|Xᵢ| values in Xᵢ
|
|
112
|
-
Vᵢ ≜ mean of the smallest α|Xᵢ| values in Xᵢ
|
|
117
|
+
Returns
|
|
118
|
+
-------
|
|
119
|
+
rmsMean : float
|
|
120
|
+
Arithmetic mean of the framewise RMS magnitude.
|
|
113
121
|
|
|
114
|
-
|
|
115
|
-
|
|
122
|
+
"""
|
|
123
|
+
return float(analyzeRMSSpectrogram(spectrogramMagnitude, **keywordArguments).mean().item())
|
|
116
124
|
|
|
117
|
-
|
|
125
|
+
def analyzeRMSSpectrogram_dB(spectrogramMagnitude: SpectrogramMagnitude, **keywordArguments: Any) -> ArrayAspectSpectrogramFramewise:
|
|
126
|
+
"""Compute framewise RMS spectrogram magnitude in decibels.
|
|
127
|
+
|
|
128
|
+
(AI generated docstring)
|
|
129
|
+
|
|
130
|
+
You can use this function to convert framewise RMS spectrogram magnitudes into decibel units
|
|
131
|
+
using a 20 * log10 mapping. The function obtains linear RMS values from
|
|
132
|
+
`analyzeRMSSpectrogram` and applies a logarithmic mapping.
|
|
133
|
+
|
|
134
|
+
Parameters
|
|
118
135
|
----------
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
136
|
+
spectrogramMagnitude : SpectrogramMagnitude
|
|
137
|
+
Magnitude-domain spectral representation whose framewise RMS magnitude is measured.
|
|
138
|
+
keywordArguments : Any
|
|
139
|
+
Additional arguments forwarded to `analyzeRMSSpectrogram`.
|
|
140
|
+
|
|
141
|
+
Returns
|
|
142
|
+
-------
|
|
143
|
+
rootMeanSquare_dB : ArrayAspectSpectrogramFramewise
|
|
144
|
+
Framewise RMS spectrogram magnitude in decibels.
|
|
145
|
+
|
|
123
146
|
"""
|
|
124
|
-
|
|
147
|
+
rootMeanSquare: ArrayAspectSpectrogramFramewise = analyzeRMSSpectrogram(spectrogramMagnitude, **keywordArguments)
|
|
148
|
+
return 20 * numpy.log10(rootMeanSquare, where=(rootMeanSquare != 0), out=None)
|
|
125
149
|
|
|
126
|
-
@registrationAudioAspect('
|
|
127
|
-
def
|
|
128
|
-
"""Aspect '
|
|
150
|
+
@registrationAudioAspect('RMS Spectrogram dB mean')
|
|
151
|
+
def analyzeRMSSpectrogram_dBMean(spectrogramMagnitude: SpectrogramMagnitude, **keywordArguments: Any) -> float:
|
|
152
|
+
"""Aspect 'RMS Spectrogram dB mean': mean framewise RMS spectrogram magnitude in decibels.
|
|
129
153
|
|
|
130
154
|
Returns
|
|
131
155
|
-------
|
|
132
|
-
|
|
133
|
-
Mean value of the time-varying
|
|
156
|
+
rootMeanSquare_dBMean : float
|
|
157
|
+
Mean value of the time-varying RMS spectrogram magnitude in decibels.
|
|
134
158
|
|
|
135
159
|
"""
|
|
136
|
-
return float(
|
|
160
|
+
return float(analyzeRMSSpectrogram_dB(spectrogramMagnitude, **keywordArguments).mean().item())
|
|
137
161
|
|
|
138
162
|
def analyzeSpectralBandwidth(spectrogramMagnitude: SpectrogramMagnitude, **keywordArguments: Any) -> ArrayAspectSpectrogramFramewise:
|
|
139
163
|
"""Compute spectral spread around the framewise centroid.
|
|
@@ -253,6 +277,69 @@ def analyzeSpectralCentroidMean(spectrogramMagnitude: SpectrogramMagnitude, **ke
|
|
|
253
277
|
"""
|
|
254
278
|
return float(analyzeSpectralCentroid(spectrogramMagnitude, **keywordArguments).mean().item())
|
|
255
279
|
|
|
280
|
+
def analyzeSpectralContrast(spectrogramMagnitude: SpectrogramMagnitude, **keywordArguments: Any) -> ArrayAspect:
|
|
281
|
+
"""Compute octave-band peak-to-valley contrast.
|
|
282
|
+
|
|
283
|
+
(AI generated docstring)
|
|
284
|
+
|
|
285
|
+
You can use this function to measure how strongly spectral peaks stand above spectral valleys in
|
|
286
|
+
each octave band. High values indicate narrow-band, harmonic structure, while lower values
|
|
287
|
+
indicate flatter or noisier spectral content [1].
|
|
288
|
+
|
|
289
|
+
Parameters
|
|
290
|
+
----------
|
|
291
|
+
spectrogramMagnitude : SpectrogramMagnitude
|
|
292
|
+
Magnitude-domain spectral representation to be analyzed in octave bands.
|
|
293
|
+
keywordArguments : Any
|
|
294
|
+
Additional keyword arguments forwarded to ``librosa.feature.spectral_contrast``.
|
|
295
|
+
|
|
296
|
+
Returns
|
|
297
|
+
-------
|
|
298
|
+
spectralContrast : numpy.ndarray
|
|
299
|
+
Framewise contrast values for each octave band with shape (n_bands + 1, n_frames). Each row
|
|
300
|
+
corresponds to one octave band.
|
|
301
|
+
|
|
302
|
+
Mathematics
|
|
303
|
+
-----------
|
|
304
|
+
octave-band partition : equation
|
|
305
|
+
```
|
|
306
|
+
Let Bᵢ ≜ i-th octave band
|
|
307
|
+
f_min ≜ lower cutoff of the first band
|
|
308
|
+
|
|
309
|
+
Bᵢ = [2^(i - 1) f_min, 2^i f_min)
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
peak-valley contrast : equation
|
|
313
|
+
```
|
|
314
|
+
Let Xᵢ ≜ magnitudes in octave band Bᵢ
|
|
315
|
+
α ∈ (0, 1) ≜ neighborhood factor
|
|
316
|
+
Pᵢ ≜ mean of the largest α|Xᵢ| values in Xᵢ
|
|
317
|
+
Vᵢ ≜ mean of the smallest α|Xᵢ| values in Xᵢ
|
|
318
|
+
|
|
319
|
+
SCᵢ = log(Pᵢ) - log(Vᵢ)
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
References
|
|
323
|
+
----------
|
|
324
|
+
[1] Jiang, D.-N., Lu, L., Zhang, H.-J., Tao, J.-H., & Cai, L.-H. (2002).
|
|
325
|
+
Music type classification by spectral contrast feature. Proceedings of the IEEE International
|
|
326
|
+
Conference on Multimedia and Expo, 113–116.
|
|
327
|
+
https://hcsi.cs.tsinghua.edu.cn/Paper/Paper02/200218.pdf
|
|
328
|
+
"""
|
|
329
|
+
return librosa.feature.spectral_contrast(S=spectrogramMagnitude, **keywordArguments)
|
|
330
|
+
|
|
331
|
+
@registrationAudioAspect('Spectral Contrast mean')
|
|
332
|
+
def analyzeSpectralContrastMean(spectrogramMagnitude: SpectrogramMagnitude, **keywordArguments: Any) -> float:
|
|
333
|
+
"""Aspect 'Spectral Contrast mean': mean of the framewise spectral contrast.
|
|
334
|
+
|
|
335
|
+
Returns
|
|
336
|
+
-------
|
|
337
|
+
spectralContrastMean : float
|
|
338
|
+
Mean value of the time-varying spectral contrast.
|
|
339
|
+
|
|
340
|
+
"""
|
|
341
|
+
return float(analyzeSpectralContrast(spectrogramMagnitude, **keywordArguments).mean().item())
|
|
342
|
+
|
|
256
343
|
def analyzeSpectralFlatness(spectrogramMagnitude: SpectrogramMagnitude, **keywordArguments: Any) -> ArrayAspectSpectrogramFramewise:
|
|
257
344
|
"""Compute the spectral flatness ratio for each analysis frame.
|
|
258
345
|
|
|
@@ -1,14 +1,61 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pyright: reportArgumentType=false
|
|
2
|
+
# ty:ignore[invalid-argument-type]
|
|
3
|
+
# ruff: noqa: D100 D103
|
|
2
4
|
from __future__ import annotations
|
|
3
5
|
|
|
4
6
|
from analyzeAudio.registry import registrationAudioAspect
|
|
7
|
+
from torch import tensor
|
|
8
|
+
from torchmetrics.functional.audio.dnsmos import deep_noise_suppression_mean_opinion_score
|
|
9
|
+
from torchmetrics.functional.audio.nisqa import non_intrusive_speech_quality_assessment
|
|
5
10
|
from torchmetrics.functional.audio.srmr import speech_reverberation_modulation_energy_ratio
|
|
6
11
|
from typing import TYPE_CHECKING
|
|
12
|
+
import sys
|
|
13
|
+
import warnings
|
|
7
14
|
|
|
8
15
|
if TYPE_CHECKING:
|
|
9
16
|
from torch import Tensor
|
|
10
17
|
from typing import Any
|
|
11
18
|
|
|
19
|
+
# TODO Requires a lot of memory, and concurrency is causing crashes.
|
|
20
|
+
def analyzeDNSMOS(tensorAudio: Tensor, sampleRate: int, **keywordArguments: Any) -> Tensor:
|
|
21
|
+
defaults: dict[str, bool] = {'personalized': False}
|
|
22
|
+
return deep_noise_suppression_mean_opinion_score(tensorAudio, sampleRate, {**defaults, **keywordArguments})
|
|
23
|
+
|
|
24
|
+
# @registrationAudioAspect('DNSMOS mean')
|
|
25
|
+
def analyzeDNSMOSMean(tensorAudio: Tensor, sampleRate: int) -> float:
|
|
26
|
+
"""Aspect 'DNSMOS mean': mean Deep Noise Suppression MOS score.
|
|
27
|
+
|
|
28
|
+
Returns
|
|
29
|
+
-------
|
|
30
|
+
dnsmosMean : float
|
|
31
|
+
Mean DNSMOS component score.
|
|
32
|
+
|
|
33
|
+
"""
|
|
34
|
+
return float(analyzeDNSMOS(tensorAudio, sampleRate).mean().item())
|
|
35
|
+
|
|
36
|
+
def analyzeNISQA(tensorAudio: Tensor, sampleRate: int) -> Tensor:
|
|
37
|
+
try:
|
|
38
|
+
return non_intrusive_speech_quality_assessment(tensorAudio, sampleRate)
|
|
39
|
+
except RuntimeError as ERRORmessage:
|
|
40
|
+
message: str = f'I could not compute `analyzeNISQA({tensorAudio.shape = }, {sampleRate = })` because "{ERRORmessage}".'
|
|
41
|
+
sys.stderr.write(message + '\n')
|
|
42
|
+
return tensor([])
|
|
43
|
+
|
|
44
|
+
@registrationAudioAspect('NISQA mean')
|
|
45
|
+
def analyzeNISQAMean(tensorAudio: Tensor, sampleRate: int) -> float | None:
|
|
46
|
+
"""Aspect 'NISQA mean': mean non-intrusive speech quality score.
|
|
47
|
+
|
|
48
|
+
Returns
|
|
49
|
+
-------
|
|
50
|
+
nisqaMean : float | None
|
|
51
|
+
Mean NISQA component score.
|
|
52
|
+
|
|
53
|
+
"""
|
|
54
|
+
tensorAspect: Tensor = analyzeNISQA(tensorAudio, sampleRate)
|
|
55
|
+
if len(tensorAspect) == 0:
|
|
56
|
+
return None
|
|
57
|
+
return float(tensorAspect.mean().item())
|
|
58
|
+
|
|
12
59
|
def analyzeSRMR(tensorAudio: Tensor, sampleRate: int, *, pytorchOnCPU: bool | None, **keywordArguments: Any) -> Tensor:
|
|
13
60
|
"""Compute speech-to-reverberation modulation energy ratio values from `tensorAudio`.
|
|
14
61
|
|
|
@@ -90,7 +137,8 @@ def analyzeSRMR(tensorAudio: Tensor, sampleRate: int, *, pytorchOnCPU: bool | No
|
|
|
90
137
|
https://lightning.ai/docs/torchmetrics/stable/audio/speech_reverberation_modulation_energy_ratio.html
|
|
91
138
|
|
|
92
139
|
"""
|
|
93
|
-
keywordArguments['fast'] = keywordArguments.get('fast'
|
|
140
|
+
keywordArguments['fast'] = keywordArguments.get('fast', pytorchOnCPU) or False
|
|
141
|
+
warnings.filterwarnings('ignore', category=UserWarning, module='torchmetrics', message='.*fast=True.*')
|
|
94
142
|
return speech_reverberation_modulation_energy_ratio(tensorAudio, sampleRate, **keywordArguments)
|
|
95
143
|
|
|
96
144
|
@registrationAudioAspect('SRMR mean')
|
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
# ruff: noqa: D100
|
|
1
|
+
# ruff: noqa: D100 D103
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
|
|
4
4
|
from analyzeAudio import BleedFull, BleedFullArray, ParametersMelSpectrogram
|
|
5
|
+
from analyzeAudio.registry import registrationAudioContest
|
|
5
6
|
from typing import TYPE_CHECKING
|
|
6
7
|
from typing_extensions import Unpack
|
|
7
8
|
import librosa
|
|
8
9
|
import numpy
|
|
10
|
+
import sys
|
|
11
|
+
import warnings
|
|
9
12
|
|
|
10
13
|
if TYPE_CHECKING:
|
|
11
14
|
from analyzeAudio import SpectrogramMagnitude
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
# TODO Figure out how to cache intermediate objects in this module.
|
|
17
|
+
|
|
18
|
+
def analyzeBleedFullMelDB(
|
|
19
|
+
spectrogramMagnitudeAlfa: SpectrogramMagnitude
|
|
20
|
+
, spectrogramMagnitudeBeta: SpectrogramMagnitude
|
|
21
|
+
, **keywordArguments: Unpack[ParametersMelSpectrogram]
|
|
22
|
+
) -> BleedFullArray:
|
|
15
23
|
"""Separate mel-scaled dB excess and deficit between two spectrograms.
|
|
16
24
|
|
|
17
25
|
You can use this function to compare two magnitude spectrograms as source-separation balance data.
|
|
@@ -113,8 +121,18 @@ def analyzeBleedFullMelDB(spectrogramMagnitudeAlfa: SpectrogramMagnitude, spectr
|
|
|
113
121
|
|
|
114
122
|
top_db: float | None = keywordArguments.get('top_db', 80.0)
|
|
115
123
|
|
|
116
|
-
|
|
117
|
-
|
|
124
|
+
with warnings.catch_warnings(record=True) as warningMessages:
|
|
125
|
+
warnings.simplefilter('always', UserWarning)
|
|
126
|
+
spectrogramMagnitudeAlfa = librosa.feature.melspectrogram(S=spectrogramMagnitudeAlfa, **parametersMelSpectrogram)
|
|
127
|
+
spectrogramMagnitudeBeta = librosa.feature.melspectrogram(S=spectrogramMagnitudeBeta, **parametersMelSpectrogram)
|
|
128
|
+
for warningMessage in warningMessages:
|
|
129
|
+
if str(warningMessage.message).startswith('Empty filters detected in mel frequency basis.'):
|
|
130
|
+
message: str = (
|
|
131
|
+
f'While computing `analyzeBleedFullMelDB({spectrogramMagnitudeAlfa.shape = }, {spectrogramMagnitudeBeta.shape = })` because the difference between the maximum frequency and minimum frequency is too small for the number of mel bands, some mel bands were empty.'
|
|
132
|
+
)
|
|
133
|
+
sys.stderr.write(message + '\n')
|
|
134
|
+
else:
|
|
135
|
+
warnings.warn(str(warningMessage.message), warningMessage.category, stacklevel=2)
|
|
118
136
|
spectrogramMagnitudeAlfa = librosa.amplitude_to_db(spectrogramMagnitudeAlfa, ref=1.0, top_db=top_db) # pyright: ignore[reportUnknownMemberType]
|
|
119
137
|
spectrogramMagnitudeBeta = librosa.amplitude_to_db(spectrogramMagnitudeBeta, ref=1.0, top_db=top_db) # pyright: ignore[reportUnknownMemberType]
|
|
120
138
|
|
|
@@ -125,7 +143,11 @@ def _bleedFullArrays(spectrogramAlfa: SpectrogramMagnitude, spectrogramBeta: Spe
|
|
|
125
143
|
|
|
126
144
|
return BleedFullArray(arrayBleed=arrayDifferences[0 < arrayDifferences], arrayFull=arrayDifferences[arrayDifferences < 0])
|
|
127
145
|
|
|
128
|
-
def analyzeBleedFullMelDBMean(
|
|
146
|
+
def analyzeBleedFullMelDBMean(
|
|
147
|
+
spectrogramMagnitudeAlfa: SpectrogramMagnitude
|
|
148
|
+
, spectrogramMagnitudeBeta: SpectrogramMagnitude
|
|
149
|
+
, **keywordArguments: Unpack[ParametersMelSpectrogram]
|
|
150
|
+
) -> BleedFull:
|
|
129
151
|
"""Score mean mel-scaled dB-magnitude excess and deficit between two spectrograms.
|
|
130
152
|
|
|
131
153
|
You can use this function to summarize source-separation balance as two higher-is-better scores.
|
|
@@ -180,7 +202,7 @@ def analyzeBleedFullMelDBMean(spectrogramMagnitudeAlfa: SpectrogramMagnitude, sp
|
|
|
180
202
|
[3] numpy.mean.
|
|
181
203
|
https://numpy.org/doc/stable/reference/generated/numpy.mean.html
|
|
182
204
|
"""
|
|
183
|
-
bf: BleedFullArray = analyzeBleedFullMelDB(spectrogramMagnitudeAlfa, spectrogramMagnitudeBeta)
|
|
205
|
+
bf: BleedFullArray = analyzeBleedFullMelDB(spectrogramMagnitudeAlfa, spectrogramMagnitudeBeta, **keywordArguments)
|
|
184
206
|
|
|
185
207
|
if 0 < bf.arrayBleed.size:
|
|
186
208
|
bleed: float = numpy.mean(bf.arrayBleed).item()
|
|
@@ -195,3 +217,19 @@ def analyzeBleedFullMelDBMean(spectrogramMagnitudeAlfa: SpectrogramMagnitude, sp
|
|
|
195
217
|
full = 0.0
|
|
196
218
|
|
|
197
219
|
return BleedFull(bleed=bleed, full=full)
|
|
220
|
+
|
|
221
|
+
@registrationAudioContest('Bleedless Mel-scaled dB mean')
|
|
222
|
+
def analyzeBleedlessMelDBMean(
|
|
223
|
+
spectrogramMagnitudeAlfa: SpectrogramMagnitude
|
|
224
|
+
, spectrogramMagnitudeBeta: SpectrogramMagnitude
|
|
225
|
+
, **keywordArguments: Unpack[ParametersMelSpectrogram]
|
|
226
|
+
) -> float:
|
|
227
|
+
return analyzeBleedFullMelDBMean(spectrogramMagnitudeAlfa, spectrogramMagnitudeBeta, **keywordArguments).bleed
|
|
228
|
+
|
|
229
|
+
@registrationAudioContest('Fullness Mel-scaled dB mean')
|
|
230
|
+
def analyzeFullnessMelDBMean(
|
|
231
|
+
spectrogramMagnitudeAlfa: SpectrogramMagnitude
|
|
232
|
+
, spectrogramMagnitudeBeta: SpectrogramMagnitude
|
|
233
|
+
, **keywordArguments: Unpack[ParametersMelSpectrogram]
|
|
234
|
+
) -> float:
|
|
235
|
+
return analyzeBleedFullMelDBMean(spectrogramMagnitudeAlfa, spectrogramMagnitudeBeta, **keywordArguments).full
|