hunterHearsPy 1.0.3__py3-none-any.whl
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.
- hunterHearsPy/__init__.py +36 -0
- hunterHearsPy/amplitude.py +170 -0
- hunterHearsPy/autoRevert.py +75 -0
- hunterHearsPy/clippingArrays.py +143 -0
- hunterHearsPy/ioAudio.py +663 -0
- hunterHearsPy/py.typed +0 -0
- hunterHearsPy/theTypes.py +118 -0
- hunterHearsPy/windowingFunctions.py +211 -0
- hunterHearsPy/windowingFunctionsTensor.py +168 -0
- hunterhearspy-1.0.3.dist-info/METADATA +115 -0
- hunterhearspy-1.0.3.dist-info/RECORD +13 -0
- hunterhearspy-1.0.3.dist-info/WHEEL +4 -0
- hunterhearspy-1.0.3.dist-info/licenses/LICENSE +407 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""Type definitions for audio signal processing and waveform analysis.
|
|
2
|
+
|
|
3
|
+
(AI generated docstring)
|
|
4
|
+
|
|
5
|
+
This module defines type aliases and typed dictionaries for NumPy arrays,
|
|
6
|
+
waveforms, spectrograms, and parameter structures used throughout the audio
|
|
7
|
+
signal processing library.
|
|
8
|
+
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from collections.abc import Callable
|
|
13
|
+
from numpy import complexfloating, dtype, floating, ndarray
|
|
14
|
+
from typing import Any, TYPE_CHECKING, TypeAlias, TypedDict, TypeVar
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from scipy.signal._short_time_fft import _FFTMode, _PadType, _ScaleTo
|
|
18
|
+
|
|
19
|
+
ArrayType = TypeVar('ArrayType', bound=ndarray[tuple[Any, ...], dtype[Any]], covariant=True)
|
|
20
|
+
WindowingFunctionDtype: TypeAlias = floating[Any]
|
|
21
|
+
WindowingFunction: TypeAlias = ndarray[tuple[int], dtype[WindowingFunctionDtype]]
|
|
22
|
+
callableReturnsNDArray = TypeVar('callableReturnsNDArray', bound=Callable[..., WindowingFunction])
|
|
23
|
+
WaveformDtype: TypeAlias = floating[Any]
|
|
24
|
+
Waveform: TypeAlias = ndarray[tuple[int, int], dtype[WaveformDtype]]
|
|
25
|
+
"""Two-axes NumPy `ndarray` representing audio waveforms.
|
|
26
|
+
|
|
27
|
+
A NumPy `ndarray` of audio waveform data with shape (channels, samples). For mono audio, `channels` = 1.
|
|
28
|
+
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
ArrayWaveforms: TypeAlias = ndarray[tuple[int, int, int], dtype[WaveformDtype]]
|
|
32
|
+
"""Three-axes NumPy `ndarray` representing multiple waveforms.
|
|
33
|
+
|
|
34
|
+
A NumPy `ndarray` containing `ndarray` of type `Waveform` indexed on the last axis: shape is (channels, samples, `Waveform`).
|
|
35
|
+
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
SpectrogramDtype: TypeAlias = complexfloating[Any, Any]
|
|
39
|
+
Spectrogram: TypeAlias = ndarray[tuple[int, int, int], dtype[SpectrogramDtype]]
|
|
40
|
+
"""Three-axes `ndarray` representing a spectrogram.
|
|
41
|
+
|
|
42
|
+
A NumPy `ndarray` of spectrogram data with shape (channels, frequency_bins, time_frames). For mono audio, `channels` = 1.
|
|
43
|
+
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
ArraySpectrograms: TypeAlias = ndarray[tuple[int, int, int, int], dtype[SpectrogramDtype]]
|
|
47
|
+
"""Four-axes NumPy `ndarray` representing multiple spectrograms.
|
|
48
|
+
|
|
49
|
+
A NumPy `ndarray` containing `ndarray` of type `Spectrogram` indexed on the last axis: shape is (channels, frequency_bins, time_frames, `Spectrogram`).
|
|
50
|
+
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
class ParametersSTFT(TypedDict, total=False):
|
|
54
|
+
"""Optional parameters for Short-Time Fourier Transform operations.
|
|
55
|
+
|
|
56
|
+
(AI generated docstring)
|
|
57
|
+
|
|
58
|
+
TypedDict defining optional configuration parameters for STFT computations.
|
|
59
|
+
All fields are optional due to `total=False`.
|
|
60
|
+
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
padding: _PadType
|
|
64
|
+
axis: int
|
|
65
|
+
|
|
66
|
+
class ParametersShortTimeFFT(TypedDict, total=False):
|
|
67
|
+
"""Optional parameters for Short-Time FFT operations.
|
|
68
|
+
|
|
69
|
+
(AI generated docstring)
|
|
70
|
+
|
|
71
|
+
TypedDict defining optional configuration parameters for short-time FFT.
|
|
72
|
+
All fields are optional due to `total=False`.
|
|
73
|
+
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
fft_mode: _FFTMode
|
|
77
|
+
scale_to: _ScaleTo
|
|
78
|
+
|
|
79
|
+
class ParametersUniversal(TypedDict):
|
|
80
|
+
"""Required parameters for universal audio processing operations.
|
|
81
|
+
|
|
82
|
+
(AI generated docstring)
|
|
83
|
+
|
|
84
|
+
TypedDict defining required configuration parameters used across multiple
|
|
85
|
+
audio processing functions. All fields must be provided.
|
|
86
|
+
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
lengthFFT: int
|
|
90
|
+
lengthHop: int
|
|
91
|
+
lengthWindowingFunction: int
|
|
92
|
+
sampleRate: float
|
|
93
|
+
windowingFunction: WindowingFunction
|
|
94
|
+
|
|
95
|
+
class WaveformMetadata(TypedDict):
|
|
96
|
+
"""Metadata describing waveform file properties and processing state.
|
|
97
|
+
|
|
98
|
+
(AI generated docstring)
|
|
99
|
+
|
|
100
|
+
TypedDict containing information about a waveform's source file and
|
|
101
|
+
any padding or trimming applied during processing.
|
|
102
|
+
|
|
103
|
+
"""
|
|
104
|
+
|
|
105
|
+
pathFilename: str
|
|
106
|
+
lengthWaveform: int
|
|
107
|
+
samplesLeading: int
|
|
108
|
+
samplesTrailing: int
|
|
109
|
+
|
|
110
|
+
NormalizationReverter: TypeAlias = Callable[[Waveform], Waveform]
|
|
111
|
+
"""Function type for reversing normalization operations.
|
|
112
|
+
|
|
113
|
+
(AI generated docstring)
|
|
114
|
+
|
|
115
|
+
Type alias for callable objects that accept a normalized waveform and
|
|
116
|
+
return the waveform restored to its original amplitude scale.
|
|
117
|
+
|
|
118
|
+
"""
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"""Generate windowing functions for signal processing.
|
|
2
|
+
|
|
3
|
+
Contents
|
|
4
|
+
--------
|
|
5
|
+
Functions
|
|
6
|
+
cosineWings
|
|
7
|
+
Generate a cosine-tapered windowing function with a flat center and tapered ends.
|
|
8
|
+
equalPower
|
|
9
|
+
Generate an equal-power taper for crossfades.
|
|
10
|
+
halfsine
|
|
11
|
+
Generate a half-sine windowing function.
|
|
12
|
+
tukey
|
|
13
|
+
Generate a Tukey windowing function with optional taper control.
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from numpy import cos, pi, sin
|
|
18
|
+
from typing import TYPE_CHECKING
|
|
19
|
+
import numpy
|
|
20
|
+
import scipy.signal.windows as SciPy
|
|
21
|
+
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
from hunterHearsPy import WindowingFunction
|
|
24
|
+
|
|
25
|
+
def _getLengthTaper(lengthWindow: int, ratioTaper: float | None) -> int:
|
|
26
|
+
"""I use this shared subroutine to split a window length into taper sections.
|
|
27
|
+
|
|
28
|
+
This function converts a whole window length and a taper ratio into the number of samples in one
|
|
29
|
+
edge taper. Public window constructors call it so they can share the same taper-length logic.
|
|
30
|
+
|
|
31
|
+
Parameters
|
|
32
|
+
----------
|
|
33
|
+
lengthWindow : int
|
|
34
|
+
Total length of the windowing function.
|
|
35
|
+
ratioTaper : float | None
|
|
36
|
+
Ratio of taper length to windowing-function length. When `None`, the default taper ratio is
|
|
37
|
+
used.
|
|
38
|
+
|
|
39
|
+
Returns
|
|
40
|
+
-------
|
|
41
|
+
lengthTaper : int
|
|
42
|
+
Number of samples in one taper section.
|
|
43
|
+
""" # noqa: DOC501
|
|
44
|
+
if ratioTaper is None:
|
|
45
|
+
lengthTaper = int(lengthWindow * 0.1 / 2)
|
|
46
|
+
elif 0 <= ratioTaper <= 1:
|
|
47
|
+
lengthTaper = int(lengthWindow * ratioTaper / 2)
|
|
48
|
+
else:
|
|
49
|
+
message: str = f"I received `{ratioTaper = }`. If set, `ratioTaper` must be between 0 and 1, inclusive."
|
|
50
|
+
raise ValueError(message)
|
|
51
|
+
return lengthTaper
|
|
52
|
+
|
|
53
|
+
def cosineWings(lengthWindow: int, ratioTaper: float | None = None) -> WindowingFunction:
|
|
54
|
+
"""Generate a cosine-tapered windowing function with a flat center and tapered ends.
|
|
55
|
+
|
|
56
|
+
This function creates a NumPy array [1] of coefficients that rise smoothly from 0 to 1, stay
|
|
57
|
+
flat in the middle, and mirror the taper at the end. It uses `numpy.linspace` [2] to sample the
|
|
58
|
+
taper and `numpy.cos` [3] to shape it. It acts on `lengthWindow` and `ratioTaper` and returns
|
|
59
|
+
the windowing coefficients.
|
|
60
|
+
|
|
61
|
+
Parameters
|
|
62
|
+
----------
|
|
63
|
+
lengthWindow : int
|
|
64
|
+
Total length of the windowing function.
|
|
65
|
+
ratioTaper : float | None = None
|
|
66
|
+
Ratio of taper length to windowing-function length. The value must be between 0 and 1,
|
|
67
|
+
inclusive.
|
|
68
|
+
|
|
69
|
+
Returns
|
|
70
|
+
-------
|
|
71
|
+
windowingFunction : WindowingFunction
|
|
72
|
+
NumPy array of windowing coefficients with cosine tapers.
|
|
73
|
+
|
|
74
|
+
See Also
|
|
75
|
+
--------
|
|
76
|
+
`hunterHearsPy.optionalPyTorch.cosineWingsTensor`
|
|
77
|
+
Tensor version of this windowing function.
|
|
78
|
+
|
|
79
|
+
References
|
|
80
|
+
----------
|
|
81
|
+
[1] NumPy `ndarray`.
|
|
82
|
+
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html
|
|
83
|
+
[2] NumPy `linspace`.
|
|
84
|
+
https://numpy.org/doc/stable/reference/generated/numpy.linspace.html
|
|
85
|
+
[3] NumPy `cos`.
|
|
86
|
+
https://numpy.org/doc/stable/reference/generated/numpy.cos.html
|
|
87
|
+
|
|
88
|
+
"""
|
|
89
|
+
lengthTaper: int = _getLengthTaper(lengthWindow, ratioTaper)
|
|
90
|
+
|
|
91
|
+
windowingFunction: WindowingFunction = numpy.ones(shape=lengthWindow)
|
|
92
|
+
if 0 < lengthTaper:
|
|
93
|
+
taper = 1 - cos(numpy.linspace(start=0, stop=pi / 2, num=lengthTaper, dtype=windowingFunction.dtype))
|
|
94
|
+
windowingFunction[0:lengthTaper] = taper
|
|
95
|
+
windowingFunction[-lengthTaper:None] = taper[::-1]
|
|
96
|
+
return windowingFunction
|
|
97
|
+
|
|
98
|
+
def equalPower(lengthWindow: int, ratioTaper: float | None = None) -> WindowingFunction:
|
|
99
|
+
"""Generate an equal-power taper for crossfades.
|
|
100
|
+
|
|
101
|
+
This function creates a NumPy array [1] of coefficients that follow a square-root taper at both
|
|
102
|
+
ends and a flat center. It uses `numpy.linspace` [2] to sample the taper and `numpy.sqrt` [3] to
|
|
103
|
+
convert it to equal-power scaling. It acts on `lengthWindow` and `ratioTaper` and returns the
|
|
104
|
+
windowing coefficients.
|
|
105
|
+
|
|
106
|
+
Parameters
|
|
107
|
+
----------
|
|
108
|
+
lengthWindow : int
|
|
109
|
+
Total length of the windowing function.
|
|
110
|
+
ratioTaper : float | None = None
|
|
111
|
+
Ratio of taper length to windowing-function length. The value must be between 0 and 1,
|
|
112
|
+
inclusive.
|
|
113
|
+
|
|
114
|
+
Returns
|
|
115
|
+
-------
|
|
116
|
+
windowingFunction : WindowingFunction
|
|
117
|
+
NumPy array of windowing coefficients with tapers.
|
|
118
|
+
|
|
119
|
+
See Also
|
|
120
|
+
--------
|
|
121
|
+
`hunterHearsPy.optionalPyTorch.equalPowerTensor`
|
|
122
|
+
Tensor version of this windowing function.
|
|
123
|
+
|
|
124
|
+
References
|
|
125
|
+
----------
|
|
126
|
+
[1] NumPy `ndarray`.
|
|
127
|
+
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html
|
|
128
|
+
[2] NumPy `linspace`.
|
|
129
|
+
https://numpy.org/doc/stable/reference/generated/numpy.linspace.html
|
|
130
|
+
[3] NumPy `sqrt`.
|
|
131
|
+
https://numpy.org/doc/stable/reference/generated/numpy.sqrt.html
|
|
132
|
+
|
|
133
|
+
"""
|
|
134
|
+
lengthTaper: int = _getLengthTaper(lengthWindow, ratioTaper)
|
|
135
|
+
|
|
136
|
+
windowingFunction: WindowingFunction = numpy.ones(shape=lengthWindow)
|
|
137
|
+
if 0 < lengthTaper:
|
|
138
|
+
taper = numpy.sqrt(numpy.linspace(start=0, stop=1, num=lengthTaper, dtype=windowingFunction.dtype))
|
|
139
|
+
windowingFunction[0:lengthTaper] = taper
|
|
140
|
+
windowingFunction[-lengthTaper:None] = taper[::-1]
|
|
141
|
+
return windowingFunction
|
|
142
|
+
|
|
143
|
+
def halfsine(lengthWindow: int) -> WindowingFunction:
|
|
144
|
+
"""Generate a half-sine windowing function.
|
|
145
|
+
|
|
146
|
+
This function creates a NumPy array [1] of coefficients that follow a half-sine profile across
|
|
147
|
+
the requested length. It uses `numpy.arange` [2] and `numpy.sin` [3] to place the samples. It
|
|
148
|
+
acts on `lengthWindow` and returns the windowing coefficients.
|
|
149
|
+
|
|
150
|
+
Parameters
|
|
151
|
+
----------
|
|
152
|
+
lengthWindow : int
|
|
153
|
+
Total length of the windowing function.
|
|
154
|
+
|
|
155
|
+
Returns
|
|
156
|
+
-------
|
|
157
|
+
windowingFunction : WindowingFunction
|
|
158
|
+
NumPy array of windowing coefficients following a half-sine shape.
|
|
159
|
+
|
|
160
|
+
See Also
|
|
161
|
+
--------
|
|
162
|
+
`hunterHearsPy.optionalPyTorch.halfsineTensor`
|
|
163
|
+
Tensor version of this windowing function.
|
|
164
|
+
|
|
165
|
+
References
|
|
166
|
+
----------
|
|
167
|
+
[1] NumPy `ndarray`.
|
|
168
|
+
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html
|
|
169
|
+
[2] NumPy `arange`.
|
|
170
|
+
https://numpy.org/doc/stable/reference/generated/numpy.arange.html
|
|
171
|
+
[3] NumPy `sin`.
|
|
172
|
+
https://numpy.org/doc/stable/reference/generated/numpy.sin.html
|
|
173
|
+
|
|
174
|
+
"""
|
|
175
|
+
return sin(pi * (numpy.arange(lengthWindow) + 0.5) / lengthWindow, dtype=numpy.float64)
|
|
176
|
+
|
|
177
|
+
def tukey(lengthWindow: int, ratioTaper: float | None = None, **keywordArguments: float) -> WindowingFunction:
|
|
178
|
+
"""Generate a Tukey windowing function with optional SciPy keyword overrides.
|
|
179
|
+
|
|
180
|
+
This function creates a NumPy array [1] by delegating to SciPy's Tukey window implementation
|
|
181
|
+
[2]. It accepts `lengthWindow`, `ratioTaper`, and extra keyword arguments, then returns the
|
|
182
|
+
windowing coefficients.
|
|
183
|
+
|
|
184
|
+
Parameters
|
|
185
|
+
----------
|
|
186
|
+
lengthWindow : int
|
|
187
|
+
Total length of the windowing function.
|
|
188
|
+
ratioTaper : float | None = None
|
|
189
|
+
Ratio of taper length to windowing-function length. The value must be between 0 and 1,
|
|
190
|
+
inclusive.
|
|
191
|
+
**keywordArguments : float
|
|
192
|
+
Additional keyword arguments. `alpha` overrides `ratioTaper` when provided, matching SciPy's
|
|
193
|
+
API.
|
|
194
|
+
|
|
195
|
+
Returns
|
|
196
|
+
-------
|
|
197
|
+
windowingFunction : WindowingFunction
|
|
198
|
+
NumPy array of Tukey windowing function coefficients.
|
|
199
|
+
|
|
200
|
+
References
|
|
201
|
+
----------
|
|
202
|
+
[1] NumPy `ndarray`.
|
|
203
|
+
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html
|
|
204
|
+
[2] SciPy Tukey window.
|
|
205
|
+
https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.windows.tukey.html
|
|
206
|
+
|
|
207
|
+
"""
|
|
208
|
+
alpha: float | None = keywordArguments.get('alpha', ratioTaper) # Are you tempted to use `or 0.1`? Don't be: it will override the user's value for `ratioTaper=0`.
|
|
209
|
+
if alpha is None:
|
|
210
|
+
alpha = 0.1
|
|
211
|
+
return SciPy.tukey(lengthWindow, alpha)
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"""Create PyTorch tensor windowing functions."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from hunterHearsPy import callableReturnsNDArray, cosineWings, equalPower, halfsine, tukey
|
|
5
|
+
from typing import Any, TYPE_CHECKING
|
|
6
|
+
import torch
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from torch.types import Device
|
|
10
|
+
|
|
11
|
+
def _convertToTensor(*arguments: Any, callableTarget: callableReturnsNDArray, device: Device, **keywordArguments: Any) -> torch.Tensor:
|
|
12
|
+
arrayTarget = callableTarget(*arguments, **keywordArguments)
|
|
13
|
+
return torch.tensor(data=arrayTarget, dtype=torch.float32, device=device)
|
|
14
|
+
|
|
15
|
+
def cosineWingsTensor(lengthWindow: int, ratioTaper: float | None=None, device: Device | None=None) -> torch.Tensor:
|
|
16
|
+
"""Generate a cosine-tapered windowing function with a flat center and tapered ends.
|
|
17
|
+
|
|
18
|
+
This function creates a NumPy array [1] of coefficients that rise smoothly from 0 to 1, stay
|
|
19
|
+
flat in the middle, and mirror the taper at the end. It uses `numpy.linspace` [2] to sample the
|
|
20
|
+
taper and `numpy.cos` [3] to shape it. It acts on `lengthWindow` and `ratioTaper` and returns
|
|
21
|
+
the windowing coefficients.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
lengthWindow : int
|
|
26
|
+
Total length of the windowing function.
|
|
27
|
+
ratioTaper : float | None = None
|
|
28
|
+
Ratio of taper length to windowing-function length. The value must be between 0 and 1,
|
|
29
|
+
inclusive.
|
|
30
|
+
device : Device = torch.device(device='cpu')
|
|
31
|
+
PyTorch device for `Tensor`.
|
|
32
|
+
|
|
33
|
+
Returns
|
|
34
|
+
-------
|
|
35
|
+
windowingFunction : WindowingFunction
|
|
36
|
+
NumPy array of windowing coefficients with cosine tapers.
|
|
37
|
+
|
|
38
|
+
See Also
|
|
39
|
+
--------
|
|
40
|
+
`hunterHearsPy.optionalPyTorch.cosineWingsTensor`
|
|
41
|
+
Tensor version of this windowing function.
|
|
42
|
+
|
|
43
|
+
References
|
|
44
|
+
----------
|
|
45
|
+
[1] NumPy `ndarray`.
|
|
46
|
+
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html
|
|
47
|
+
[2] NumPy `linspace`.
|
|
48
|
+
https://numpy.org/doc/stable/reference/generated/numpy.linspace.html
|
|
49
|
+
[3] NumPy `cos`.
|
|
50
|
+
https://numpy.org/doc/stable/reference/generated/numpy.cos.html
|
|
51
|
+
|
|
52
|
+
"""
|
|
53
|
+
device = device or torch.device(device='cpu')
|
|
54
|
+
return _convertToTensor(lengthWindow, ratioTaper, callableTarget=cosineWings, device=device)
|
|
55
|
+
|
|
56
|
+
def equalPowerTensor(lengthWindow: int, ratioTaper: float | None=None, device: Device | None=None) -> torch.Tensor:
|
|
57
|
+
"""Generate an equal-power taper for crossfades.
|
|
58
|
+
|
|
59
|
+
This function creates a NumPy array [1] of coefficients that follow a square-root taper at both
|
|
60
|
+
ends and a flat center. It uses `numpy.linspace` [2] to sample the taper and `numpy.sqrt` [3] to
|
|
61
|
+
convert it to equal-power scaling. It acts on `lengthWindow` and `ratioTaper` and returns the
|
|
62
|
+
windowing coefficients.
|
|
63
|
+
|
|
64
|
+
Parameters
|
|
65
|
+
----------
|
|
66
|
+
lengthWindow : int
|
|
67
|
+
Total length of the windowing function.
|
|
68
|
+
ratioTaper : float | None = None
|
|
69
|
+
Ratio of taper length to windowing-function length. The value must be between 0 and 1,
|
|
70
|
+
inclusive.
|
|
71
|
+
device : Device = torch.device(device='cpu')
|
|
72
|
+
PyTorch device for `Tensor`.
|
|
73
|
+
|
|
74
|
+
Returns
|
|
75
|
+
-------
|
|
76
|
+
windowingFunction : WindowingFunction
|
|
77
|
+
NumPy array of windowing coefficients with tapers.
|
|
78
|
+
|
|
79
|
+
See Also
|
|
80
|
+
--------
|
|
81
|
+
`hunterHearsPy.optionalPyTorch.equalPowerTensor`
|
|
82
|
+
Tensor version of this windowing function.
|
|
83
|
+
|
|
84
|
+
References
|
|
85
|
+
----------
|
|
86
|
+
[1] NumPy `ndarray`.
|
|
87
|
+
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html
|
|
88
|
+
[2] NumPy `linspace`.
|
|
89
|
+
https://numpy.org/doc/stable/reference/generated/numpy.linspace.html
|
|
90
|
+
[3] NumPy `sqrt`.
|
|
91
|
+
https://numpy.org/doc/stable/reference/generated/numpy.sqrt.html
|
|
92
|
+
|
|
93
|
+
"""
|
|
94
|
+
device = device or torch.device(device='cpu')
|
|
95
|
+
return _convertToTensor(lengthWindow, ratioTaper, callableTarget=equalPower, device=device)
|
|
96
|
+
|
|
97
|
+
def halfsineTensor(lengthWindow: int, device: Device | None=None) -> torch.Tensor:
|
|
98
|
+
"""Generate a half-sine windowing function.
|
|
99
|
+
|
|
100
|
+
This function creates a NumPy array [1] of coefficients that follow a half-sine profile across
|
|
101
|
+
the requested length. It uses `numpy.arange` [2] and `numpy.sin` [3] to place the samples. It
|
|
102
|
+
acts on `lengthWindow` and returns the windowing coefficients.
|
|
103
|
+
|
|
104
|
+
Parameters
|
|
105
|
+
----------
|
|
106
|
+
lengthWindow : int
|
|
107
|
+
Total length of the windowing function.
|
|
108
|
+
device : Device = torch.device(device='cpu')
|
|
109
|
+
PyTorch device for `Tensor`.
|
|
110
|
+
|
|
111
|
+
Returns
|
|
112
|
+
-------
|
|
113
|
+
windowingFunction : WindowingFunction
|
|
114
|
+
NumPy array of windowing coefficients following a half-sine shape.
|
|
115
|
+
|
|
116
|
+
See Also
|
|
117
|
+
--------
|
|
118
|
+
`hunterHearsPy.optionalPyTorch.halfsineTensor`
|
|
119
|
+
Tensor version of this windowing function.
|
|
120
|
+
|
|
121
|
+
References
|
|
122
|
+
----------
|
|
123
|
+
[1] NumPy `ndarray`.
|
|
124
|
+
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html
|
|
125
|
+
[2] NumPy `arange`.
|
|
126
|
+
https://numpy.org/doc/stable/reference/generated/numpy.arange.html
|
|
127
|
+
[3] NumPy `sin`.
|
|
128
|
+
https://numpy.org/doc/stable/reference/generated/numpy.sin.html
|
|
129
|
+
|
|
130
|
+
"""
|
|
131
|
+
device = device or torch.device(device='cpu')
|
|
132
|
+
return _convertToTensor(lengthWindow, callableTarget=halfsine, device=device)
|
|
133
|
+
|
|
134
|
+
def tukeyTensor(lengthWindow: int, ratioTaper: float | None=None, device: Device | None=None, **keywordArguments: float) -> torch.Tensor:
|
|
135
|
+
"""Generate a Tukey windowing function with optional SciPy keyword overrides.
|
|
136
|
+
|
|
137
|
+
This function creates a NumPy array [1] by delegating to SciPy's Tukey window implementation
|
|
138
|
+
[2]. It accepts `lengthWindow`, `ratioTaper`, and extra keyword arguments, then returns the
|
|
139
|
+
windowing coefficients.
|
|
140
|
+
|
|
141
|
+
Parameters
|
|
142
|
+
----------
|
|
143
|
+
lengthWindow : int
|
|
144
|
+
Total length of the windowing function.
|
|
145
|
+
ratioTaper : float | None = None
|
|
146
|
+
Ratio of taper length to windowing-function length. The value must be between 0 and 1,
|
|
147
|
+
inclusive.
|
|
148
|
+
**keywordArguments : float
|
|
149
|
+
Additional keyword arguments. `alpha` overrides `ratioTaper` when provided, matching SciPy's
|
|
150
|
+
API.
|
|
151
|
+
device : Device = torch.device(device='cpu')
|
|
152
|
+
PyTorch device for `Tensor`.
|
|
153
|
+
|
|
154
|
+
Returns
|
|
155
|
+
-------
|
|
156
|
+
windowingFunction : WindowingFunction
|
|
157
|
+
NumPy array of Tukey windowing function coefficients.
|
|
158
|
+
|
|
159
|
+
References
|
|
160
|
+
----------
|
|
161
|
+
[1] NumPy `ndarray`.
|
|
162
|
+
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html
|
|
163
|
+
[2] SciPy Tukey window.
|
|
164
|
+
https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.windows.tukey.html
|
|
165
|
+
|
|
166
|
+
"""
|
|
167
|
+
device = device or torch.device(device='cpu')
|
|
168
|
+
return _convertToTensor(lengthWindow, ratioTaper, callableTarget=tukey, device=device, **keywordArguments)
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hunterHearsPy
|
|
3
|
+
Version: 1.0.3
|
|
4
|
+
Summary: Audio processing.
|
|
5
|
+
Keywords:
|
|
6
|
+
Author: Hunter Hogan
|
|
7
|
+
Author-email: Hunter Hogan <HunterHogan@pm.me>
|
|
8
|
+
License-Expression: CC-BY-NC-4.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Natural Language :: English
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Dist: huntermakespy>=0.7.0
|
|
20
|
+
Requires-Dist: numpy
|
|
21
|
+
Requires-Dist: resampy
|
|
22
|
+
Requires-Dist: scipy
|
|
23
|
+
Requires-Dist: soundfile>=0.14.0
|
|
24
|
+
Requires-Dist: tqdm
|
|
25
|
+
Requires-Dist: torch ; extra == 'torch'
|
|
26
|
+
Maintainer: Hunter Hogan
|
|
27
|
+
Maintainer-email: Hunter Hogan <HunterHogan@pm.me>
|
|
28
|
+
Requires-Python: >=3.10
|
|
29
|
+
Project-URL: Context7, https://context7.com/hunterhogan/hunterhearspy
|
|
30
|
+
Project-URL: Donate, https://www.patreon.com/integrated
|
|
31
|
+
Project-URL: Download, https://pypi.org/project/hunterHearsPy
|
|
32
|
+
Project-URL: Homepage, https://github.com/hunterhogan/hunterHearsPy
|
|
33
|
+
Project-URL: Issues, https://github.com/hunterhogan/hunterHearsPy/issues
|
|
34
|
+
Project-URL: Repository, https://github.com/hunterhogan/hunterHearsPy.git
|
|
35
|
+
Provides-Extra: torch
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# hunterHearsPy
|
|
39
|
+
|
|
40
|
+
A comprehensive collection of Python utilities for audio processing.
|
|
41
|
+
|
|
42
|
+
## Audio Processing Made Simple
|
|
43
|
+
|
|
44
|
+
### Load and Save Audio Files
|
|
45
|
+
|
|
46
|
+
Read audio files with automatic stereo conversion and sample rate control:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from hunterHearsPy import readAudioFile, writeWAV
|
|
50
|
+
|
|
51
|
+
# Load audio with sample rate conversion
|
|
52
|
+
waveform = readAudioFile('input.wav', sampleRate=44100)
|
|
53
|
+
|
|
54
|
+
# Save in WAV format (always 32-bit float)
|
|
55
|
+
writeWAV('output.wav', waveform)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Process Multiple Audio Files at Once
|
|
59
|
+
|
|
60
|
+
Load and process batches of audio files:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from hunterHearsPy import loadWaveforms
|
|
64
|
+
|
|
65
|
+
# Load multiple files with consistent formatting
|
|
66
|
+
array_waveforms = loadWaveforms(['file1.wav', 'file2.wav', 'file3.wav'])
|
|
67
|
+
|
|
68
|
+
# The result is a unified array with shape (channels, samples, file_count)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Work with Spectrograms
|
|
72
|
+
|
|
73
|
+
Convert between waveforms and spectrograms:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from hunterHearsPy import stft, halfsine
|
|
77
|
+
|
|
78
|
+
# Create a spectrogram with a half-sine window
|
|
79
|
+
spectrogram = stft(waveform, windowingFunction=halfsine(1024))
|
|
80
|
+
|
|
81
|
+
# Convert back to a waveform
|
|
82
|
+
reconstructed = stft(spectrogram, inverse=True, lengthWaveform=original_length)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Process Audio in the Frequency Domain
|
|
86
|
+
|
|
87
|
+
Create functions that operate on spectrograms:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from hunterHearsPy import waveformSpectrogramWaveform
|
|
91
|
+
|
|
92
|
+
def boost_low_frequencies(spectrogram):
|
|
93
|
+
# Boost frequencies below 500 Hz
|
|
94
|
+
spectrogram[:, :10, :] *= 2.0
|
|
95
|
+
return spectrogram
|
|
96
|
+
|
|
97
|
+
# Create a processor that handles the STFT/ISTFT automatically
|
|
98
|
+
processor = waveformSpectrogramWaveform(boost_low_frequencies)
|
|
99
|
+
|
|
100
|
+
# Apply the processor to a waveform
|
|
101
|
+
processed_waveform = processor(original_waveform)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Installation
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
pip install hunterHearsPy
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## My recovery
|
|
111
|
+
|
|
112
|
+
[](https://HunterThinks.com/support)
|
|
113
|
+
[](https://www.youtube.com/@HunterHogan)
|
|
114
|
+
|
|
115
|
+
[](https://creativecommons.org/licenses/by-nc/4.0/)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
hunterHearsPy/__init__.py,sha256=_-lsnc6iLtdDs_l4WmMso25ClM3kWEXO9CbeLJus5eI,2385
|
|
2
|
+
hunterHearsPy/amplitude.py,sha256=1LhJ1Pp-H5aZb_6oTK4EZ-pHgEXLfWxf5MsmhqtD7t4,6497
|
|
3
|
+
hunterHearsPy/autoRevert.py,sha256=pUv_9PDo-Z2w-9HMmZGGbpKSu-z-lnEIiNlxihdDq9U,2529
|
|
4
|
+
hunterHearsPy/clippingArrays.py,sha256=8LkFZQt-cwR-VCzWJK_Bzm5wp9NsH3xiv4ZSxhu72q0,5194
|
|
5
|
+
hunterHearsPy/ioAudio.py,sha256=Sleh4Kf-MNG0Tdq3kGvmUBZt4RMxPaLj0SbTOWb9Ynw,29581
|
|
6
|
+
hunterHearsPy/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
hunterHearsPy/theTypes.py,sha256=L_4lSLFMYuERU5nYXKomd7UrhXbHVwUcB8MCghPyq0s,3722
|
|
8
|
+
hunterHearsPy/windowingFunctions.py,sha256=cu1arlNIu6fkQ2jbauzQl1aWyKkjjNgx3Ssd-9M7_4g,7195
|
|
9
|
+
hunterHearsPy/windowingFunctionsTensor.py,sha256=2A5NVTdeSejKyu9A7p6A0vy79GdsmLDzwDHUUA-qTKw,6563
|
|
10
|
+
hunterhearspy-1.0.3.dist-info/licenses/LICENSE,sha256=NxH5Y8BdC-gNU-WSMwim3uMbID2iNDXJz7fHtuTdXhk,19346
|
|
11
|
+
hunterhearspy-1.0.3.dist-info/WHEEL,sha256=wXwAVsgVaOZ_pwDFqQm5Rd6PID-Fc74nkLc8X8gHiDo,81
|
|
12
|
+
hunterhearspy-1.0.3.dist-info/METADATA,sha256=sdcQlp0eJZ2Q8GHB2NtIpXNsZpSX9mRvj6F_BYztgPo,3546
|
|
13
|
+
hunterhearspy-1.0.3.dist-info/RECORD,,
|