From 0ac06c029edb57e2dcacd64da2a05869a2f7364d Mon Sep 17 00:00:00 2001
From: 志浩 <neo.dzh@alibaba-inc.com>
Date: 星期四, 16 三月 2023 19:24:15 +0800
Subject: [PATCH] fixbug path_name_type_list can [[any,str,str],[any,str,str]]

---
 funasr/datasets/iterable_dataset.py |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/funasr/datasets/iterable_dataset.py b/funasr/datasets/iterable_dataset.py
index 2ac37b2..3798280 100644
--- a/funasr/datasets/iterable_dataset.py
+++ b/funasr/datasets/iterable_dataset.py
@@ -8,6 +8,7 @@
 from typing import Iterator
 from typing import Tuple
 from typing import Union
+from typing import List
 
 import kaldiio
 import numpy as np
@@ -20,7 +21,7 @@
 from funasr.datasets.dataset import ESPnetDataset
 
 
-SUPPORT_AUDIO_TYPE_SETS = ['flac', 'mp3', 'm4a', 'ogg', 'opus', 'wav', 'wma']
+SUPPORT_AUDIO_TYPE_SETS = ['flac', 'mp3', 'ogg', 'opus', 'wav', 'pcm']
 
 def load_kaldi(input):
     retval = kaldiio.load_mat(input)
@@ -60,9 +61,14 @@
     array = np.frombuffer((middle_data.astype(dtype) - offset) / abs_max, dtype=np.float32)
     return array
 
+def load_pcm(input):
+    with open(input,"rb") as f:
+        bytes = f.read()
+    return load_bytes(bytes)
 
 DATA_TYPES = {
     "sound": lambda x: torchaudio.load(x)[0][0].numpy(),
+    "pcm": load_pcm,
     "kaldi_ark": load_kaldi,
     "bytes": load_bytes,
     "waveform": lambda x: x,
@@ -122,7 +128,7 @@
         non_iterable_list = []
         self.path_name_type_list = []
 
-        if not isinstance(path_name_type_list[0], Tuple):
+        if not isinstance(path_name_type_list[0], (Tuple, List)):
             path = path_name_type_list[0]
             name = path_name_type_list[1]
             _type = path_name_type_list[2]
@@ -219,6 +225,9 @@
                 if audio_type not in SUPPORT_AUDIO_TYPE_SETS:
                     raise NotImplementedError(
                         f'Not supported audio type: {audio_type}')
+                if audio_type == "pcm":
+                    _type = "pcm"
+
             func = DATA_TYPES[_type]
             array = func(value)
             if self.fs is not None and name == "speech":
@@ -318,6 +327,8 @@
                         if audio_type not in SUPPORT_AUDIO_TYPE_SETS:
                             raise NotImplementedError(
                                 f'Not supported audio type: {audio_type}')
+                        if audio_type == "pcm":
+                            _type = "pcm"
                     func = DATA_TYPES[_type]
                     # Load entry
                     array = func(value)

--
Gitblit v1.9.1