mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
support pcm audio format
This commit is contained in:
parent
c14169f374
commit
ade51b3a12
@ -20,7 +20,7 @@ import os.path
|
|||||||
from funasr.datasets.dataset import ESPnetDataset
|
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):
|
def load_kaldi(input):
|
||||||
retval = kaldiio.load_mat(input)
|
retval = kaldiio.load_mat(input)
|
||||||
@ -60,9 +60,14 @@ def load_bytes(input):
|
|||||||
array = np.frombuffer((middle_data.astype(dtype) - offset) / abs_max, dtype=np.float32)
|
array = np.frombuffer((middle_data.astype(dtype) - offset) / abs_max, dtype=np.float32)
|
||||||
return array
|
return array
|
||||||
|
|
||||||
|
def load_pcm(input):
|
||||||
|
with open(input,"rb") as f:
|
||||||
|
bytes = f.read()
|
||||||
|
return load_bytes(bytes)
|
||||||
|
|
||||||
DATA_TYPES = {
|
DATA_TYPES = {
|
||||||
"sound": lambda x: torchaudio.load(x)[0][0].numpy(),
|
"sound": lambda x: torchaudio.load(x)[0][0].numpy(),
|
||||||
|
"pcm": load_pcm,
|
||||||
"kaldi_ark": load_kaldi,
|
"kaldi_ark": load_kaldi,
|
||||||
"bytes": load_bytes,
|
"bytes": load_bytes,
|
||||||
"waveform": lambda x: x,
|
"waveform": lambda x: x,
|
||||||
@ -219,6 +224,9 @@ class IterableESPnetDataset(IterableDataset):
|
|||||||
if audio_type not in SUPPORT_AUDIO_TYPE_SETS:
|
if audio_type not in SUPPORT_AUDIO_TYPE_SETS:
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
f'Not supported audio type: {audio_type}')
|
f'Not supported audio type: {audio_type}')
|
||||||
|
if audio_type == "pcm":
|
||||||
|
_type = "pcm"
|
||||||
|
|
||||||
func = DATA_TYPES[_type]
|
func = DATA_TYPES[_type]
|
||||||
array = func(value)
|
array = func(value)
|
||||||
if self.fs is not None and name == "speech":
|
if self.fs is not None and name == "speech":
|
||||||
@ -318,6 +326,8 @@ class IterableESPnetDataset(IterableDataset):
|
|||||||
if audio_type not in SUPPORT_AUDIO_TYPE_SETS:
|
if audio_type not in SUPPORT_AUDIO_TYPE_SETS:
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
f'Not supported audio type: {audio_type}')
|
f'Not supported audio type: {audio_type}')
|
||||||
|
if audio_type == "pcm":
|
||||||
|
_type = "pcm"
|
||||||
func = DATA_TYPES[_type]
|
func = DATA_TYPES[_type]
|
||||||
# Load entry
|
# Load entry
|
||||||
array = func(value)
|
array = func(value)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user