Skip to content

Commit

Permalink
get_resampler added to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
msalhab96 committed Jun 20, 2022
1 parent 8c53634 commit 419628c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from torch import Tensor
from functools import lru_cache
import json
import torchaudio


@lru_cache(maxsize=2)
Expand Down Expand Up @@ -40,3 +41,11 @@ def cat_speaker_emb(speaker_emb: Tensor, x: Tensor) -> Tensor:
def save_json(file_path: str, data: dict):
with open(file_path, 'w', encoding='utf-8') as f:
json.dump(data, f)


@lru_cache(maxsize=2)
def get_resampler(src_sr: int, target_sr: int):
return torchaudio.transforms.Resample(
orig_freq=src_sr,
new_freq=target_sr
)

0 comments on commit 419628c

Please sign in to comment.