From 94de39dde2e616a01683c518023d0fab72b4e103 Mon Sep 17 00:00:00 2001
From: 游雁 <zhifu.gzf@alibaba-inc.com>
Date: 星期一, 19 二月 2024 22:21:50 +0800
Subject: [PATCH] aishell example

---
 funasr/utils/prepare_data.py |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/funasr/utils/prepare_data.py b/funasr/utils/prepare_data.py
index 3ae18b8..36eebdc 100644
--- a/funasr/utils/prepare_data.py
+++ b/funasr/utils/prepare_data.py
@@ -5,9 +5,9 @@
 
 import kaldiio
 import numpy as np
+import librosa
 import torch.distributed as dist
 import torchaudio
-import soundfile
 
 
 def filter_wav_text(data_dir, dataset):
@@ -46,7 +46,7 @@
     try:
         waveform, sampling_rate = torchaudio.load(wav_path)
     except:
-        waveform, sampling_rate = soundfile.read(wav_path)
+        waveform, sampling_rate = librosa.load(wav_path)
         waveform = np.expand_dims(waveform, axis=0)
     n_frames = (waveform.shape[1] * 1000.0) / (sampling_rate * frontend_conf["frame_shift"] * frontend_conf["lfr_n"])
     feature_dim = frontend_conf["n_mels"] * frontend_conf["lfr_m"]
@@ -87,6 +87,7 @@
                 sample_name, feature_path = line.strip().split()
                 feature = kaldiio.load_mat(feature_path)
                 n_frames, feature_dim = feature.shape
+                write_flag = True
                 if n_frames > 0 and length_min > 0:
                     write_flag = n_frames >= length_min
                 if n_frames > 0 and length_max > 0:
@@ -198,6 +199,7 @@
     data_names = args.dataset_conf.get("data_names", "speech,text").split(",")
     data_types = args.dataset_conf.get("data_types", "sound,text").split(",")
     file_names = args.data_file_names.split(",")
+    batch_type = args.dataset_conf["batch_conf"]["batch_type"]
     print("data_names: {}, data_types: {}, file_names: {}".format(data_names, data_types, file_names))
     assert len(data_names) == len(data_types) == len(file_names)
     if args.dataset_type == "small":
@@ -228,7 +230,7 @@
             filter_wav_text(args.data_dir, args.train_set)
             filter_wav_text(args.data_dir, args.valid_set)
 
-        if args.dataset_type == "small":
+        if args.dataset_type == "small" and batch_type != "unsorted":
             calc_shape(args, args.train_set)
             calc_shape(args, args.valid_set)
 

--
Gitblit v1.9.1