def __init__(self, json_dir, n_src=2, sample_rate=8000, segment=4.0): super().__init__() # Task setting self.json_dir = json_dir self.sample_rate = sample_rate if segment is None: self.seg_len = None else: self.seg_len = int(segment * sample_rate) self.n_src = n_src self.like_test = self.seg_len is None # Load json files mix_json = os.path.join(json_dir, "mix.json") sources_json = [ os.path.join(json_dir, source + ".json") for source in [f"s{n+1}" for n in range(n_src)] ] with open(mix_json, "r") as f: mix_infos = json.load(f) sources_infos = [] for src_json in sources_json: with open(src_json, "r") as f: sources_infos.append(json.load(f)) # Filter out short utterances only when segment is specified orig_len = len(mix_infos) drop_utt, drop_len = 0, 0 if not self.like_test: for i in range(len(mix_infos) - 1, -1, -1): # Go backward if mix_infos[i][1] < self.seg_len: drop_utt += 1 drop_len += mix_infos[i][1] del mix_infos[i] for src_inf in sources_infos: del src_inf[i] print( "Drop {} utts({:.2f} h) from {} (shorter than {} samples)".format( drop_utt, drop_len / sample_rate / 36000, orig_len, self.seg_len ) ) self.mix = mix_infos self.sources = sources_infos
时间: 2024-02-10 13:21:12 浏览: 190
TimingTheWorld_Decimal.zip_DECIMAL FPGA_basys2_segment在FPGA
这是一个 Python 类的初始化函数,看起来是用于处理音频混合数据和其源数据的。具体来说,它的输入参数包括一个 JSON 目录、音频源的数量、采样率和段长度等。它会从指定的 JSON 文件中读取混合音频和其源音频的信息,并对其中长度太短的音频进行过滤。最终,该函数会将处理好的音频混合数据和其源数据存储在该类的 mix 和 sources 属性中。
阅读全文