Skip to content

Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.

update

嘉渊7f7c23c36fab
diff --git a/funasr/datasets/small_datasets/dataset.py b/funasr/datasets/small_datasets/dataset.py
index a7017a5c4..a6c678aee 100644
--- a/funasr/datasets/small_datasets/dataset.py
+++ b/funasr/datasets/small_datasets/dataset.py
@@ -110,6 +110,7 @@ class ESPnetDataset(Dataset):
float_dtype: str = "float32",
int_dtype: str = "long",
dest_sample_rate: int = 16000,
+ speed_perturb: tuple = None,
):
assert check_argument_types()
if len(path_name_type_list) == 0:
@@ -123,6 +124,7 @@ class ESPnetDataset(Dataset):
self.float_dtype = float_dtype
self.int_dtype = int_dtype
self.dest_sample_rate = dest_sample_rate
+ self.speed_perturb = speed_perturb
self.loader_dict = {}
self.debug_info = {}
@@ -146,7 +148,7 @@ class ESPnetDataset(Dataset):
loader_type: loader_type. sound, npy, text, etc
"""
if loader_type == "sound":
- loader = SoundScpReader(path, self.dest_sample_rate, normalize=True, always_2d=False)
+ loader = SoundScpReader(path, self.dest_sample_rate, normalize=True, always_2d=False, speed_perturb=self.speed_perturb)
return AdapterForSoundScpReader(loader, self.float_dtype)
elif loader_type == "kaldi_ark":
loader = kaldiio.load_scp(path)
diff --git a/funasr/fileio/sound_scp.py b/funasr/fileio/sound_scp.py
index dc872b047..f0ac053c3 100644
--- a/funasr/fileio/sound_scp.py
+++ b/funasr/fileio/sound_scp.py
@@ -2,11 +2,14 @@ import collections.abc
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 torchaudio
+
from funasr.fileio.read_text import read_2column_text
@@ -32,6 +35,7 @@ class SoundScpReader(collections.abc.Mapping):
always_2d: bool = False,
normalize: bool = False,
dest_sample_rate: int = 16000,
+ speed_perturb: tuple = None,
):
assert check_argument_types()
self.fname = fname
@@ -40,6 +44,7 @@ class SoundScpReader(collections.abc.Mapping):
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 +58,13 @@ class SoundScpReader(collections.abc.Mapping):
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(
+ array, rate,
+ [['speed', str(speed)], ['rate', str(rate)]])
+
return rate, array
def get_path(self, key):