From 58f239f5bbff6fa35c221cafd9a5f83fb9779bc3 Mon Sep 17 00:00:00 2001
From: 嘉渊 <wangjiaming.wjm@alibaba-inc.com>
Date: 星期五, 12 五月 2023 16:57:35 +0800
Subject: [PATCH] update repo
---
funasr/fileio/sound_scp.py | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/funasr/fileio/sound_scp.py b/funasr/fileio/sound_scp.py
index dc872b0..7b35a35 100644
--- a/funasr/fileio/sound_scp.py
+++ b/funasr/fileio/sound_scp.py
@@ -2,10 +2,14 @@
from pathlib import Path
from typing import Union
+import random
import numpy as np
import soundfile
import librosa
from typeguard import check_argument_types
+
+import torch
+import torchaudio
from funasr.fileio.read_text import read_2column_text
@@ -32,6 +36,7 @@
always_2d: bool = False,
normalize: bool = False,
dest_sample_rate: int = 16000,
+ speed_perturb: Union[list, tuple] = None,
):
assert check_argument_types()
self.fname = fname
@@ -40,6 +45,7 @@
self.normalize = normalize
self.data = read_2column_text(fname)
self.dest_sample_rate = dest_sample_rate
+ self.speed_perturb = speed_perturb
def __getitem__(self, key):
wav = self.data[key]
@@ -53,6 +59,14 @@
wav, sr=self.dest_sample_rate, mono=not self.always_2d, dtype=self.dtype
)
+ if self.speed_perturb is not None:
+ speed = random.choice(self.speed_perturb)
+ if speed != 1.0:
+ array, _ = torchaudio.sox_effects.apply_effects_tensor(
+ torch.tensor(array).view(1, -1), rate,
+ [['speed', str(speed)], ['rate', str(rate)]])
+ array = array.view(-1).numpy()
+
return rate, array
def get_path(self, key):
--
Gitblit v1.9.1