Skip to content

Commit

Permalink
Fix sample rate type annotations (#1789)
Browse files Browse the repository at this point in the history
* Fix audio load sampling rate type

* Add backward-compatible sr cast and annotation

* Remove sr audio cast in audio load

* additional type annotation fixes on 1753

---------

Co-authored-by: tarepan <tarepan5884@gmail.com>
  • Loading branch information
bmcfee and tarepan committed Dec 21, 2023
1 parent 07d7295 commit 6e0d0f5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Glossary
corresponds to amplitude of the waveform at sample `t`.

sampling rate
The (positive integer) number of samples per second of a time series.
This is denoted by an integer variable `sr`.
The number of samples per second of a time series.
This is denoted by a positive number `sr`.

frame
A short slice of a :term:`time series` used for analysis purposes. This
Expand Down
2 changes: 1 addition & 1 deletion librosa/core/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def load(
duration: Optional[float] = None,
dtype: DTypeLike = np.float32,
res_type: str = "soxr_hq",
) -> Tuple[np.ndarray, float]:
) -> Tuple[np.ndarray, Union[int, float]]:
"""Load an audio file as a floating point time series.
Audio will be automatically resampled to the given rate
Expand Down
8 changes: 4 additions & 4 deletions librosa/core/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,14 +600,14 @@ def blocks_to_samples(

@overload
def blocks_to_time(
blocks: _IntLike_co, *, block_length: int, hop_length: int, sr: int
blocks: _IntLike_co, *, block_length: int, hop_length: int, sr: float
) -> np.floating[Any]:
...


@overload
def blocks_to_time(
blocks: _SequenceLike[_IntLike_co], *, block_length: int, hop_length: int, sr: int
blocks: _SequenceLike[_IntLike_co], *, block_length: int, hop_length: int, sr: float
) -> np.ndarray:
...

Expand All @@ -618,7 +618,7 @@ def blocks_to_time(
*,
block_length: int,
hop_length: int,
sr: int,
sr: float,
) -> Union[np.floating[Any], np.ndarray]:
...

Expand All @@ -628,7 +628,7 @@ def blocks_to_time(
*,
block_length: int,
hop_length: int,
sr: int,
sr: float,
) -> Union[np.floating[Any], np.ndarray]:
"""Convert block indices to time (in seconds)
Expand Down

0 comments on commit 6e0d0f5

Please sign in to comment.