| | |
| | | import torch.distributed as dist |
| | | import torchaudio |
| | | import numpy as np |
| | | import soundfile |
| | | # import librosa |
| | | import librosa |
| | | from kaldiio import ReadHelper |
| | | from torch.utils.data import IterableDataset |
| | | |
| | |
| | | ark_reader = ReadHelper('ark:{}'.format(data_file)) |
| | | reader_list.append(ark_reader) |
| | | elif data_type == "text" or data_type == "sound" or data_type == 'text_hotword': |
| | | text_reader = open(data_file, "r") |
| | | text_reader = open(data_file, "r", encoding="utf-8") |
| | | reader_list.append(text_reader) |
| | | elif data_type == "none": |
| | | continue |
| | |
| | | try: |
| | | waveform, sampling_rate = torchaudio.load(path) |
| | | except: |
| | | waveform, sampling_rate = soundfile.read(path, dtype='float32') |
| | | # waveform, sampling_rate = librosa.load(path, dtype='float32') |
| | | waveform, sampling_rate = librosa.load(path, dtype='float32') |
| | | if waveform.ndim == 2: |
| | | waveform = waveform[:, 0] |
| | | waveform = np.expand_dims(waveform, axis=0) |
| | |
| | | # pre_prob = conf.get("pre_prob", 0) # unused yet |
| | | if pre_hwfile is not None: |
| | | pre_hwlist = [] |
| | | with open(pre_hwfile, 'r') as fin: |
| | | with open(pre_hwfile, 'r', encoding="utf-8") as fin: |
| | | for line in fin.readlines(): |
| | | pre_hwlist.append(line.strip()) |
| | | else: |