From 4f5b9354d0ec209ba81400550fa2aca41268ad51 Mon Sep 17 00:00:00 2001
From: hnluo <haoneng.lhn@alibaba-inc.com>
Date: 星期一, 06 二月 2023 17:08:01 +0800
Subject: [PATCH] Merge pull request #64 from alibaba-damo-academy/dev_lhn
---
funasr/datasets/iterable_dataset.py | 12 +++++++++++-
funasr/utils/asr_utils.py | 10 +++++++---
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/funasr/datasets/iterable_dataset.py b/funasr/datasets/iterable_dataset.py
index 2ac37b2..fa0adeb 100644
--- a/funasr/datasets/iterable_dataset.py
+++ b/funasr/datasets/iterable_dataset.py
@@ -20,7 +20,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 +60,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,
@@ -219,6 +224,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 +326,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)
diff --git a/funasr/utils/asr_utils.py b/funasr/utils/asr_utils.py
index aa5c9db..a6f5ddd 100644
--- a/funasr/utils/asr_utils.py
+++ b/funasr/utils/asr_utils.py
@@ -18,7 +18,7 @@
global_asr_language = 'zh-cn'
-SUPPORT_AUDIO_TYPE_SETS = ['flac', 'mp3', 'm4a', 'ogg', 'opus', 'wav', 'wma']
+SUPPORT_AUDIO_TYPE_SETS = ['flac', 'mp3', 'ogg', 'opus', 'wav', 'pcm']
def get_version():
return float(pkg_resources.get_distribution('easyasr').version)
@@ -128,7 +128,12 @@
def get_sr_from_wav(fname: str):
fs = None
if os.path.isfile(fname):
- audio, fs = torchaudio.load(fname)
+ audio_type = os.path.basename(fname).split(".")[1].lower()
+ if audio_type in SUPPORT_AUDIO_TYPE_SETS:
+ if audio_type == "pcm":
+ fs = None
+ else:
+ audio, fs = torchaudio.load(fname)
return fs
elif os.path.isdir(fname):
dir_files = os.listdir(fname)
@@ -347,4 +352,3 @@
percent = 1
res = int(50 * percent) * '#'
print('\r[%-50s] %d%%' % (res, int(100 * percent)), end='')
-
--
Gitblit v1.9.1