commit 75b6b14808f0bf7b99f8b3659e27e9cd5f334a38
parent 5c727e07c4c1745f713995a2a501ff53a7cd986e
Author: Steven Atkinson <[email protected]>
Date: Sat, 4 Mar 2023 15:56:56 -0600
Add rate param to wav_to_np (#115)
Diffstat:
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/nam/data.py b/nam/data.py
@@ -37,6 +37,7 @@ class WavInfo:
def wav_to_np(
filename: Union[str, Path],
+ rate: Optional[int] = REQUIRED_RATE,
require_match: Optional[Union[str, Path]] = None,
required_shape: Optional[Tuple[int]] = None,
required_wavinfo: Optional[WavInfo] = None,
@@ -49,7 +50,11 @@ def wav_to_np(
x_wav = wavio.read(str(filename))
assert x_wav.data.shape[1] == _REQUIRED_CHANNELS, "Mono"
assert x_wav.sampwidth == _REQUIRED_SAMPWIDTH, "24-bit"
- assert x_wav.rate == REQUIRED_RATE, "48 kHz"
+ if rate is not None and x_wav.rate != rate:
+ raise RuntimeError(
+ f"Explicitly expected sample rate of {rate}, but found {x_wav.rate} in "
+ f"file {filename}!"
+ )
if require_match is not None:
assert required_shape is None