|
16 | 16 | from collections.abc import Generator |
17 | 17 | from ctypes.util import find_library as _find_library |
18 | 18 | from os import SEEK_CUR, SEEK_END, SEEK_SET |
19 | | -from typing import Any, BinaryIO, Final, TypeAlias |
| 19 | +from typing import Any, BinaryIO, Final, Literal, TypeAlias, overload |
20 | 20 |
|
21 | | -import numpy.typing |
| 21 | +import numpy |
22 | 22 | from typing_extensions import Self |
23 | 23 |
|
24 | 24 | from _soundfile import ffi as _ffi |
25 | 25 |
|
26 | 26 | FileDescriptorOrPath: TypeAlias = str | int | BinaryIO | _os.PathLike[Any] |
27 | | -AudioData: TypeAlias = numpy.typing.NDArray[Any] |
| 27 | +AudioData: TypeAlias = numpy.ndarray[tuple[int, ...], numpy.dtype[numpy.float32 | numpy.float64 | numpy.int32 | numpy.int16]] |
| 28 | +AudioData_2d: TypeAlias = numpy.ndarray[tuple[int, int], numpy.dtype[numpy.float32 | numpy.float64 | numpy.int32 | numpy.int16]] |
| 29 | +dtype_str: TypeAlias = Literal['float64', 'float32', 'int32', 'int16'] |
28 | 30 | _snd: Any |
29 | 31 | _ffi: Any |
30 | 32 |
|
|
223 | 225 | __libsndfile_version__ = __libsndfile_version__[len('libsndfile-'):] |
224 | 226 |
|
225 | 227 |
|
226 | | - |
227 | | -def read(file: FileDescriptorOrPath, frames: int = -1, start: int = 0, stop: int | None = None, |
228 | | - dtype: str = 'float64', always_2d: bool = False, |
229 | | - fill_value: float | None = None, out: AudioData | None = None, |
230 | | - samplerate: int | None = None, channels: int | None = None, |
231 | | - format: str | None = None, subtype: str | None = None, |
232 | | - endian: str | None = None, closefd: bool = True) -> tuple[AudioData, int]: |
| 228 | +@overload |
| 229 | +def read(file: FileDescriptorOrPath, frames: int = -1, start: int = 0, stop: int | None = None, dtype: dtype_str = 'float64', |
| 230 | + *, always_2d: Literal[True], fill_value: float | None = None, out: AudioData_2d | None = None, |
| 231 | + samplerate: int | None = None, channels: int | None = None, format: str | None = None, subtype: str | None = None, |
| 232 | + endian: str | None = None, closefd: bool = True) -> tuple[AudioData_2d, int]:... |
| 233 | +@overload |
| 234 | +def read(file: FileDescriptorOrPath, frames: int = -1, start: int = 0, stop: int | None = None, dtype: dtype_str = 'float64', |
| 235 | + always_2d: bool = False, fill_value: float | None = None, out: AudioData | None = None, |
| 236 | + samplerate: int | None = None, channels: int | None = None, format: str | None = None, subtype: str | None = None, |
| 237 | + endian: str | None = None, closefd: bool = True) -> tuple[AudioData, int]:... |
| 238 | +def read(file: FileDescriptorOrPath, frames: int = -1, start: int = 0, stop: int | None = None, dtype: dtype_str = 'float64', |
| 239 | + always_2d: bool = False, fill_value: float | None = None, out: AudioData | None = None, |
| 240 | + samplerate: int | None = None, channels: int | None = None, format: str | None = None, subtype: str | None = None, |
| 241 | + endian: str | None = None, closefd: bool = True) -> tuple[AudioData | AudioData_2d, int]: |
233 | 242 |
|
234 | 243 | """Provide audio data from a sound file as NumPy array. |
235 | 244 |
|
|
0 commit comments