None1145 commited on
Commit
b37d2bb
·
verified ·
1 Parent(s): a81439c

Delete preprocess_flist_config.py

Browse files
Files changed (1) hide show
  1. preprocess_flist_config.py +0 -119
preprocess_flist_config.py DELETED
@@ -1,119 +0,0 @@
1
- import argparse
2
- import json
3
- import os
4
- import re
5
- import wave
6
- from random import shuffle
7
-
8
- from loguru import logger
9
- from tqdm import tqdm
10
-
11
- import diffusion.logger.utils as du
12
-
13
- pattern = re.compile(r'^[\.a-zA-Z0-9_\/]+$')
14
-
15
- def get_wav_duration(file_path):
16
- try:
17
- with wave.open(file_path, 'rb') as wav_file:
18
- # 获取音频帧数
19
- n_frames = wav_file.getnframes()
20
- # 获取采样率
21
- framerate = wav_file.getframerate()
22
- # 计算时长(秒)
23
- return n_frames / float(framerate)
24
- except Exception as e:
25
- logger.error(f"Reading {file_path}")
26
- raise e
27
-
28
- if __name__ == "__main__":
29
- parser = argparse.ArgumentParser()
30
- parser.add_argument("--train_list", type=str, default="./filelists/train.txt", help="path to train list")
31
- parser.add_argument("--val_list", type=str, default="./filelists/val.txt", help="path to val list")
32
- parser.add_argument("--source_dir", type=str, default="./dataset/44k", help="path to source dir")
33
- parser.add_argument("--speech_encoder", type=str, default="vec768l12", help="choice a speech encoder|'vec768l12','vec256l9','hubertsoft','whisper-ppg','cnhubertlarge','dphubert','whisper-ppg-large','wavlmbase+'")
34
- parser.add_argument("--vol_aug", action="store_true", help="Whether to use volume embedding and volume augmentation")
35
- parser.add_argument("--tiny", action="store_true", help="Whether to train sovits tiny")
36
- args = parser.parse_args()
37
-
38
- config_template = json.load(open("configs_template/config_tiny_template.json")) if args.tiny else json.load(open("configs_template/config_template.json"))
39
- train = []
40
- val = []
41
- idx = 0
42
- spk_dict = {}
43
- spk_id = 0
44
-
45
- for speaker in tqdm(os.listdir(args.source_dir)):
46
- spk_dict[speaker] = spk_id
47
- spk_id += 1
48
- wavs = []
49
-
50
- for file_name in os.listdir(os.path.join(args.source_dir, speaker)):
51
- if not file_name.endswith("wav"):
52
- continue
53
- if file_name.startswith("."):
54
- continue
55
-
56
- file_path = "/".join([args.source_dir, speaker, file_name])
57
-
58
- if not pattern.match(file_name):
59
- logger.warning("Detected non-ASCII file name: " + file_path)
60
-
61
- if get_wav_duration(file_path) < 0.3:
62
- logger.info("Skip too short audio: " + file_path)
63
- continue
64
-
65
- wavs.append(file_path)
66
-
67
- shuffle(wavs)
68
- train += wavs[2:]
69
- val += wavs[:2]
70
-
71
- shuffle(train)
72
- shuffle(val)
73
-
74
- logger.info("Writing " + args.train_list)
75
- with open(args.train_list, "w") as f:
76
- for fname in tqdm(train):
77
- wavpath = fname
78
- f.write(wavpath + "\n")
79
-
80
- logger.info("Writing " + args.val_list)
81
- with open(args.val_list, "w") as f:
82
- for fname in tqdm(val):
83
- wavpath = fname
84
- f.write(wavpath + "\n")
85
-
86
-
87
- d_config_template = du.load_config("configs_template/diffusion_template.yaml")
88
- d_config_template["model"]["n_spk"] = spk_id
89
- d_config_template["data"]["encoder"] = args.speech_encoder
90
- d_config_template["spk"] = spk_dict
91
-
92
- config_template["spk"] = spk_dict
93
- config_template["model"]["n_speakers"] = spk_id
94
- config_template["model"]["speech_encoder"] = args.speech_encoder
95
-
96
- if args.speech_encoder == "vec768l12" or args.speech_encoder == "dphubert" or args.speech_encoder == "wavlmbase+":
97
- config_template["model"]["ssl_dim"] = config_template["model"]["filter_channels"] = config_template["model"]["gin_channels"] = 768
98
- d_config_template["data"]["encoder_out_channels"] = 768
99
- elif args.speech_encoder == "vec256l9" or args.speech_encoder == 'hubertsoft':
100
- config_template["model"]["ssl_dim"] = config_template["model"]["gin_channels"] = 256
101
- d_config_template["data"]["encoder_out_channels"] = 256
102
- elif args.speech_encoder == "whisper-ppg" or args.speech_encoder == 'cnhubertlarge':
103
- config_template["model"]["ssl_dim"] = config_template["model"]["filter_channels"] = config_template["model"]["gin_channels"] = 1024
104
- d_config_template["data"]["encoder_out_channels"] = 1024
105
- elif args.speech_encoder == "whisper-ppg-large":
106
- config_template["model"]["ssl_dim"] = config_template["model"]["filter_channels"] = config_template["model"]["gin_channels"] = 1280
107
- d_config_template["data"]["encoder_out_channels"] = 1280
108
-
109
- if args.vol_aug:
110
- config_template["train"]["vol_aug"] = config_template["model"]["vol_embedding"] = True
111
-
112
- if args.tiny:
113
- config_template["model"]["filter_channels"] = 512
114
-
115
- logger.info("Writing to configs/config.json")
116
- with open("configs/config.json", "w") as f:
117
- json.dump(config_template, f, indent=2)
118
- logger.info("Writing to configs/diffusion.yaml")
119
- du.save_config("configs/diffusion.yaml",d_config_template)