From 2c3836a882ed569234c9063ea912f98a30ec90c7 Mon Sep 17 00:00:00 2001
From: 仁迷 <haoneng.lhn@alibaba-inc.com>
Date: 星期一, 13 二月 2023 16:20:02 +0800
Subject: [PATCH] update dataset audio load
---
funasr/datasets/large_datasets/dataset.py | 13 +++++++++----
1 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/funasr/datasets/large_datasets/dataset.py b/funasr/datasets/large_datasets/dataset.py
index 81c1361..8a2f2e6 100644
--- a/funasr/datasets/large_datasets/dataset.py
+++ b/funasr/datasets/large_datasets/dataset.py
@@ -4,6 +4,7 @@
from functools import partial
import torch
+import torchaudio
import torch.distributed as dist
from kaldiio import ReadHelper
from torch.utils.data import IterableDataset
@@ -102,6 +103,8 @@
elif data_type == "text" or data_type == "sound":
text_reader = open(data_file, "r")
reader_list.append(text_reader)
+ elif data_type == "none":
+ continue
else:
raise TypeError("Data type {} is not supported".format(data_type))
@@ -115,7 +118,8 @@
sample_dict["key"] = key
elif data_type == "sound":
key, path = item.strip().split()
- mat, sampling_rate = soundfile.read(path)
+ waveform, sampling_rate = torchaudio.load(path)
+ mat = waveform[0]
sample_dict[data_name] = mat
sample_dict["sampling_rate"] = sampling_rate
if data_name == "speech":
@@ -156,9 +160,10 @@
filter_fn = partial(filter, **filter_conf)
dataset = FilterIterDataPipe(dataset, fn=filter_fn)
- vocab = {'vocab': dict, 'seg_dict': seg_dict}
- tokenize_fn = partial(tokenize, **vocab)
- dataset = MapperIterDataPipe(dataset, fn=tokenize_fn)
+ if "text" in data_names:
+ vocab = {'vocab': dict, 'seg_dict': seg_dict}
+ tokenize_fn = partial(tokenize, **vocab)
+ dataset = MapperIterDataPipe(dataset, fn=tokenize_fn)
if shuffle:
buffer_conf = conf.get('shuffle_conf', {})
--
Gitblit v1.9.1