|
|
|
@ -16,18 +16,35 @@ import json
|
|
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
import paddle
|
|
|
|
|
import jsonlines
|
|
|
|
|
from paddle.io import DataLoader
|
|
|
|
|
from paddle.io import Dataset
|
|
|
|
|
|
|
|
|
|
from paddlespeech.s2t.frontend.audio import AudioSegment
|
|
|
|
|
from paddlespeech.s2t.frontend.utility import load_cmvn
|
|
|
|
|
from paddlespeech.s2t.frontend.utility import read_manifest
|
|
|
|
|
from paddlespeech.s2t.utils.log import Log
|
|
|
|
|
|
|
|
|
|
__all__ = ["FeatureNormalizer"]
|
|
|
|
|
|
|
|
|
|
logger = Log(__name__).getlog()
|
|
|
|
|
|
|
|
|
|
def read_manifest(manifest_path):
|
|
|
|
|
"""Load and parse manifest file.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
manifest_path ([type]): Manifest file to load and parse.
|
|
|
|
|
Raises:
|
|
|
|
|
IOError: If failed to parse the manifest.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
List[dict]: Manifest parsing results.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
manifest = []
|
|
|
|
|
with jsonlines.open(manifest_path, 'r') as reader:
|
|
|
|
|
for json_data in reader:
|
|
|
|
|
manifest.append(json_data)
|
|
|
|
|
return manifest
|
|
|
|
|
|
|
|
|
|
# https://github.com/PaddlePaddle/Paddle/pull/31481
|
|
|
|
|
class CollateFunc(object):
|
|
|
|
@ -61,7 +78,11 @@ class CollateFunc(object):
|
|
|
|
|
class AudioDataset(Dataset):
|
|
|
|
|
def __init__(self, manifest_path, num_samples=-1, rng=None, random_seed=0):
|
|
|
|
|
self._rng = rng if rng else np.random.RandomState(random_seed)
|
|
|
|
|
manifest = read_manifest(manifest_path)
|
|
|
|
|
manifest = []
|
|
|
|
|
with jsonlines.open(manifest_path, 'r') as reader:
|
|
|
|
|
for json_data in reader:
|
|
|
|
|
manifest.append(json_data)
|
|
|
|
|
|
|
|
|
|
if num_samples == -1:
|
|
|
|
|
sampled_manifest = manifest
|
|
|
|
|
else:
|
|
|
|
|