init
Browse filesUpload 3 files.
- .gitattributes +2 -0
- PreprocessSortPath.txt +3 -0
- SortUrl_01.txt +3 -0
- download_files_and_create_list.py +82 -0
.gitattributes
CHANGED
|
@@ -53,3 +53,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
| 56 |
+
PreprocessSortPath.txt filter=lfs diff=lfs merge=lfs -text
|
| 57 |
+
SortUrl_01.txt filter=lfs diff=lfs merge=lfs -text
|
PreprocessSortPath.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:28fd4cf31b613f7eaea90a955c5512488e53854eff4dba2d1833a3e1a8e8f9d0
|
| 3 |
+
size 28305148
|
SortUrl_01.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:668135191559e49d2821654d42658dd64d43763e1e992f4e10bbfad73b5e2035
|
| 3 |
+
size 25636366
|
download_files_and_create_list.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os, time, requests
|
| 2 |
+
from pydub import AudioSegment
|
| 3 |
+
|
| 4 |
+
preprocess_path = "D:/AI-DeepLearning/_Dataset/SortUrl_01.txt"
|
| 5 |
+
preprocess_output_path = "D:/AI-DeepLearning/_Dataset/PreprocessSortPathUrl.txt"
|
| 6 |
+
output_path = "D:/AI-DeepLearning/_Dataset/ViTS/BanGDream"
|
| 7 |
+
sub_path = "VoiceData"
|
| 8 |
+
|
| 9 |
+
# The path of audio when your training
|
| 10 |
+
write_in_path = "D:/AI-DeepLearning/Bert-VITS2-Integration-package/Data/BanGDream/custom_character_voice"
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def download_mp3_and_convert_to_wav(preprocess_path, output_path, sub_path):
|
| 14 |
+
data_list = []
|
| 15 |
+
|
| 16 |
+
# Path to save the download audio
|
| 17 |
+
voice_output_path = os.path.join(output_path, sub_path)
|
| 18 |
+
if not os.path.exists(voice_output_path):
|
| 19 |
+
os.mkdir(voice_output_path)
|
| 20 |
+
|
| 21 |
+
with open(preprocess_path, "r", encoding="utf-8") as f:
|
| 22 |
+
for line in f.readlines():
|
| 23 |
+
data_list.append(line.strip("\n"))
|
| 24 |
+
|
| 25 |
+
f.close()
|
| 26 |
+
|
| 27 |
+
# If you want overwrite please exchange 'a+' to 'w'
|
| 28 |
+
# , and change line56 if-loop to avoid passing existfile write.
|
| 29 |
+
with open(preprocess_output_path, "a+", encoding="utf-8") as f:
|
| 30 |
+
count = 0
|
| 31 |
+
for line in data_list:
|
| 32 |
+
url = line.split("|")[0]
|
| 33 |
+
speaker = line.split("|")[1]
|
| 34 |
+
script = line.split("|")[2]
|
| 35 |
+
|
| 36 |
+
# Check is it an url
|
| 37 |
+
if not 'https' in url:
|
| 38 |
+
print(f'{url} is not a url.')
|
| 39 |
+
count += 1
|
| 40 |
+
print(f'{count}/{len(data_list)}')
|
| 41 |
+
continue
|
| 42 |
+
|
| 43 |
+
# Find speaker
|
| 44 |
+
speaker_path = os.path.join(voice_output_path, speaker)
|
| 45 |
+
|
| 46 |
+
if not os.path.exists(speaker_path):
|
| 47 |
+
os.mkdir(speaker_path)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
# Mp3
|
| 51 |
+
mp3_file = url.split("/")[-1]
|
| 52 |
+
mp3_path = os.path.join(speaker_path, mp3_file)
|
| 53 |
+
save_wav_path = mp3_path.replace(".mp3", ".wav")
|
| 54 |
+
|
| 55 |
+
download = requests.get(url)
|
| 56 |
+
if not os.path.exists(mp3_path) and not os.path.exists(save_wav_path):
|
| 57 |
+
if download.status_code == 200:
|
| 58 |
+
with open(mp3_path, "wb") as voice:
|
| 59 |
+
voice.write(download.content)
|
| 60 |
+
voice.close()
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
# Turn wav and delete mp3
|
| 64 |
+
audio = AudioSegment.from_mp3(mp3_path)
|
| 65 |
+
audio = audio.set_frame_rate(44100).set_channels(1)
|
| 66 |
+
audio.export(save_wav_path, format="wav")
|
| 67 |
+
os.remove(mp3_path)
|
| 68 |
+
|
| 69 |
+
wav_file = mp3_file.replace(".mp3", ".wav")
|
| 70 |
+
write_in_wav_path = os.path.join(write_in_path, speaker, wav_file)
|
| 71 |
+
|
| 72 |
+
f.write(f'{write_in_wav_path}|{speaker}|JP|{script}\n')
|
| 73 |
+
else:
|
| 74 |
+
mp3_file = mp3_file.replace('.mp3', '')
|
| 75 |
+
print(f'{mp3_file} already exists.')
|
| 76 |
+
|
| 77 |
+
count += 1
|
| 78 |
+
print(f'{count}/{len(data_list)}')
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
if __name__ == "__main__":
|
| 82 |
+
download_mp3_and_convert_to_wav(preprocess_path=preprocess_path, output_path=output_path, sub_path=sub_path)
|