mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
update
This commit is contained in:
parent
74a2059e9c
commit
7f7c23c36f
@ -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)
|
||||
|
||||
@ -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):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user