From 7c1f30358207f60f61fa9b4defe8108e403b67f9 Mon Sep 17 00:00:00 2001 From: Jael Gu Date: Mon, 29 Aug 2022 17:21:56 +0800 Subject: [PATCH] Replace resampy with torchaudio Signed-off-by: Jael Gu --- nn_fingerprint.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nn_fingerprint.py b/nn_fingerprint.py index 112ef8c..23f9338 100644 --- a/nn_fingerprint.py +++ b/nn_fingerprint.py @@ -20,8 +20,8 @@ from pathlib import Path from typing import List import torch +import torchaudio import numpy -import resampy import onnxruntime from towhee.operator.base import NNOperator @@ -119,9 +119,11 @@ class NNFingerprint(NNOperator): audio = audio[None, :] assert len(audio.shape) == 2 audio = self.int2float(audio) + audio = torch.from_numpy(audio) if sr != self.params['sample_rate']: - audio = resampy.resample(audio, sr, self.params['sample_rate']) + resampler = torchaudio.transforms.Resample(sr, self.params['sample_rate'], dtype=audio.dtype) + audio = resampler(audio) wav = preprocess_wav(audio, segment_size=int(self.params['sample_rate'] * self.params['segment_size']),