mirror of
https://github.com/RVC-Boss/GPT-SoVITS.git
synced 2025-04-06 03:57:44 +08:00
Merge 5553ebe932f5df6b5bd79e1545958aa1628e43a9 into 5dfce9a3f0def7f1ee1e075df569b0b2d41df9e3
This commit is contained in:
commit
d1fd1d1ad5
@ -3,6 +3,8 @@ import logging
|
||||
import os
|
||||
import random
|
||||
import traceback
|
||||
from datetime import datetime
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
import torch.utils.data
|
||||
@ -19,6 +21,7 @@ from scipy.io import wavfile
|
||||
from io import BytesIO
|
||||
from my_utils import load_audio
|
||||
|
||||
|
||||
# ZeroDivisionError fixed by Tybost (https://github.com/RVC-Boss/GPT-SoVITS/issues/79)
|
||||
class TextAudioSpeakerLoader(torch.utils.data.Dataset):
|
||||
"""
|
||||
@ -28,10 +31,18 @@ class TextAudioSpeakerLoader(torch.utils.data.Dataset):
|
||||
"""
|
||||
|
||||
def __init__(self, hparams, val=False):
|
||||
exp_dir = hparams.exp_dir
|
||||
self.path2 = "%s/2-name2text.txt" % exp_dir
|
||||
self.path4 = "%s/4-cnhubert" % exp_dir
|
||||
self.path5 = "%s/5-wav32k" % exp_dir
|
||||
self.exp_dir = hparams.exp_dir
|
||||
|
||||
if not os.path.exists("%s/2-name2text.txt" % self.exp_dir): # 如果文件夹为空,寻址最新创建项目
|
||||
parent_dir = "/".join(os.getcwd().split("/")[:-1])
|
||||
self.find_newest_folder(parent_dir)
|
||||
|
||||
self.path2 = "%s/2-name2text.txt" % self.exp_dir
|
||||
self.path4 = "%s/4-cnhubert" % self.exp_dir
|
||||
self.path5 = "%s/5-wav32k" % self.exp_dir
|
||||
|
||||
f"""-loading self.path2: {self.path2} correctly-"""
|
||||
|
||||
assert os.path.exists(self.path2)
|
||||
assert os.path.exists(self.path4)
|
||||
assert os.path.exists(self.path5)
|
||||
@ -104,6 +115,20 @@ class TextAudioSpeakerLoader(torch.utils.data.Dataset):
|
||||
self.audiopaths_sid_text = audiopaths_sid_text_new
|
||||
self.lengths = lengths
|
||||
|
||||
def find_newest_folder(self, directory):
|
||||
if os.path.exists(directory):
|
||||
try:
|
||||
for root, dirs, files in os.walk(directory):
|
||||
# 获取当前目录下所有子文件夹的修改时间
|
||||
folder_times = [datetime.fromtimestamp(os.path.getmtime(root + '/' + d)) for d in dirs]
|
||||
|
||||
if len(folder_times) > 0:
|
||||
# 根据修改时间选择最新的子文件夹
|
||||
self.exp_dir = max(zip(folder_times, dirs), key=lambda x: x[0])[-1]
|
||||
except:
|
||||
f"""locating newest folder fail in {directory}"""
|
||||
return
|
||||
|
||||
def get_audio_text_speaker_pair(self, audiopath_sid_text):
|
||||
audiopath, phoneme_ids = audiopath_sid_text
|
||||
text = torch.FloatTensor(phoneme_ids)
|
||||
|
Loading…
x
Reference in New Issue
Block a user