mirror of
https://github.com/snakers4/silero-vad.git
synced 2026-02-05 18:09:22 +08:00
Perform in-place resampling during read_audio.
This commit is contained in:
14
utils_vad.py
14
utils_vad.py
@@ -122,16 +122,12 @@ class Validator():
|
|||||||
def read_audio(path: str,
|
def read_audio(path: str,
|
||||||
sampling_rate: int = 16000):
|
sampling_rate: int = 16000):
|
||||||
|
|
||||||
wav, sr = torchaudio.load(path)
|
effects = [
|
||||||
|
['channels', '1'],
|
||||||
|
['rate', str(sampling_rate)]
|
||||||
|
]
|
||||||
|
|
||||||
if wav.size(0) > 1:
|
wav, sr = torchaudio.sox_effects.apply_effects_file(path, effects=effects)
|
||||||
wav = wav.mean(dim=0, keepdim=True)
|
|
||||||
|
|
||||||
if sr != sampling_rate:
|
|
||||||
transform = torchaudio.transforms.Resample(orig_freq=sr,
|
|
||||||
new_freq=sampling_rate)
|
|
||||||
wav = transform(wav)
|
|
||||||
sr = sampling_rate
|
|
||||||
|
|
||||||
assert sr == sampling_rate
|
assert sr == sampling_rate
|
||||||
return wav.squeeze(0)
|
return wav.squeeze(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user