audio_util
Shared helpers for on-the-fly waveform resampling.
get_cached_resampler(cache, orig_freq, new_freq, device=None)
Return the torchaudio.transforms.Resample for (orig_freq, new_freq), creating and
storing it in cache on first use so it isn't rebuilt for every utterance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache
|
Dict[Tuple[int, int], Resample]
|
Caller-owned dict (e.g. an instance attribute) that persists across calls. |
required |
orig_freq
|
int
|
The source sampling rate. |
required |
new_freq
|
int
|
The target sampling rate. |
required |
device
|
device
|
Device the returned resampler must be on. Also applied on a cache hit, so a cache shared across devices (e.g. a model moved from CPU to GPU between calls) always gets a resampler on the currently requested device. |
None
|
Returns:
| Type | Description |
|---|---|
Resample
|
torchaudio.transforms.Resample: The cached (or newly created) resampler. |