Lycoris53 commited on
Commit
594e563
·
1 Parent(s): c06d694

Create ConvertBitrate

Browse files
Files changed (1) hide show
  1. ConvertBitrate +77 -0
ConvertBitrate ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import librosa
2
+ import os
3
+ import soundfile
4
+ from tqdm import tqdm, tqdm_notebook
5
+
6
+ base_dir = "./data_sakuramiko_senbetsu"
7
+ output_dir = "./plachta/VITS-fast-fine-tuning/custom_character_voice/sakuramiko"
8
+ all_dir = [f for f in os.listdir(base_dir) if not os.path.isfile(os.path.join(base_dir, f))]
9
+
10
+ file_list = []
11
+
12
+ skip_dir = ["301_dousa",
13
+ "801_eng_suuji",
14
+ "801_eng_jikan",
15
+ "803_eng_others",
16
+ "912_alphabet",
17
+ "912_alphabet2",
18
+ "913_web",
19
+ "sample"]
20
+
21
+ total_file_write = 0
22
+
23
+ def recursive_til_audio_file_found(path):
24
+ listed_dir = [f for f in os.listdir(path)]
25
+ if len(listed_dir) == 0:
26
+ return
27
+ test_path_first = os.path.join(path, listed_dir[0])
28
+
29
+ # continue through the directory if not a file
30
+ if not os.path.isfile(test_path_first):
31
+ for next_dir in listed_dir:
32
+ next_path = os.path.join(path, next_dir)
33
+ # skip any directory specify in skip_dir
34
+ for skip in skip_dir:
35
+ if next_path.find(skip) != -1:
36
+ break
37
+ else:
38
+ recursive_til_audio_file_found(next_path)
39
+ return
40
+
41
+ #for new_dir in tqdm_notebook(listed_dir, desc=f"Processing : {path}"):
42
+ for new_dir in listed_dir:
43
+ new_path = os.path.join(path, new_dir)
44
+
45
+ #if it is file, convert the audio to 16k and write to output directory
46
+ # output_path_base = path.replace(base_dir, output_dir)
47
+ # if not os.path.exists(output_path_base):
48
+ # os.makedirs(output_path_base, exist_ok=True)
49
+
50
+ # not an audio file
51
+ if new_path.find(".wav") == -1 and new_path.find(".mp3") == -1:
52
+ continue
53
+
54
+ global total_file_write
55
+ # audio, rate = librosa.load(new_path, sr=16000)
56
+ audio, rate = librosa.load(new_path, sr=22050)
57
+ # output_path = os.path.join(output_path_base, new_dir)
58
+ output_path = os.path.join(output_dir, "sakuramiko_" + str(total_file_write) + ".wav")
59
+ # output_path = os.path.join(output_dir, new_dir[0:-4] + ".wav")
60
+ soundfile.write(output_path, audio, rate, format='wav', subtype="PCM_16")
61
+ file_list.append(new_dir)
62
+
63
+ total_file_write += 1
64
+ pbar.update(1)
65
+ #print(f"\rWrite file{output_path}", end="")
66
+
67
+ with tqdm(total=24778) as pbar:
68
+ recursive_til_audio_file_found(base_dir)
69
+ print(f"Total audio file written : {total_file_write}")
70
+
71
+ import json
72
+ out_json = {}
73
+ for val in file_list:
74
+ out_json[val] = {"path":val, "kana":""}
75
+
76
+ with open("./amitaro.json", "w") as outfile:
77
+ outfile.write(json.dumps(out_json))