Spaces:
Sleeping
Sleeping
kevinwang676
commited on
Commit
•
b9545e1
1
Parent(s):
159575d
Update app.py
Browse files
app.py
CHANGED
@@ -53,31 +53,6 @@ cmodel = WavLMModel.from_pretrained("microsoft/wavlm-large").to(device)
|
|
53 |
from openai import OpenAI
|
54 |
|
55 |
import ffmpeg
|
56 |
-
import urllib.request
|
57 |
-
urllib.request.urlretrieve("https://download.openxlab.org.cn/models/Kevin676/rvc-models/weight/UVR-HP2.pth", "uvr5/uvr_model/UVR-HP2.pth")
|
58 |
-
urllib.request.urlretrieve("https://download.openxlab.org.cn/models/Kevin676/rvc-models/weight/UVR-HP5.pth", "uvr5/uvr_model/UVR-HP5.pth")
|
59 |
-
|
60 |
-
from uvr5.vr import AudioPre
|
61 |
-
weight_uvr5_root = "uvr5/uvr_model"
|
62 |
-
uvr5_names = []
|
63 |
-
for name in os.listdir(weight_uvr5_root):
|
64 |
-
if name.endswith(".pth") or "onnx" in name:
|
65 |
-
uvr5_names.append(name.replace(".pth", ""))
|
66 |
-
|
67 |
-
func = AudioPre
|
68 |
-
|
69 |
-
pre_fun_hp2 = func(
|
70 |
-
agg=int(10),
|
71 |
-
model_path=os.path.join(weight_uvr5_root, "UVR-HP2.pth"),
|
72 |
-
device="cuda",
|
73 |
-
is_half=True,
|
74 |
-
)
|
75 |
-
pre_fun_hp5 = func(
|
76 |
-
agg=int(10),
|
77 |
-
model_path=os.path.join(weight_uvr5_root, "UVR-HP5.pth"),
|
78 |
-
device="cuda",
|
79 |
-
is_half=True,
|
80 |
-
)
|
81 |
|
82 |
|
83 |
def convert(api_key, text, tgt, voice, save_path):
|
@@ -249,34 +224,22 @@ def merge_audios(folder_path):
|
|
249 |
|
250 |
import shutil
|
251 |
|
252 |
-
def convert_from_srt(apikey, filename,
|
253 |
subtitle_list = read_srt(filename)
|
254 |
-
|
255 |
-
if os.path.exists("audio_full.wav"):
|
256 |
-
os.remove("audio_full.wav")
|
257 |
-
|
258 |
-
ffmpeg.input(video_full).output("audio_full.wav", ac=2, ar=44100).run()
|
259 |
-
|
260 |
-
if split_model=="UVR-HP2":
|
261 |
-
pre_fun = pre_fun_hp2
|
262 |
-
else:
|
263 |
-
pre_fun = pre_fun_hp5
|
264 |
|
265 |
-
filename = "output"
|
266 |
-
pre_fun._path_audio_("audio_full.wav", f"./denoised/{split_model}/{filename}/", f"./denoised/{split_model}/{filename}/", "wav")
|
267 |
if os.path.isdir("output"):
|
268 |
shutil.rmtree("output")
|
269 |
if multilingual==False:
|
270 |
for i in subtitle_list:
|
271 |
os.makedirs("output", exist_ok=True)
|
272 |
-
trim_audio([[i.start_time, i.end_time]],
|
273 |
print(f"正在合成第{i.index}条语音")
|
274 |
print(f"语音内容:{i.text}")
|
275 |
convert(apikey, i.text, f"sliced_audio_{i.index}_0.wav", voice, i.text + " " + str(i.index))
|
276 |
else:
|
277 |
for i in subtitle_list:
|
278 |
os.makedirs("output", exist_ok=True)
|
279 |
-
trim_audio([[i.start_time, i.end_time]],
|
280 |
print(f"正在合成第{i.index}条语音")
|
281 |
print(f"语音内容:{i.text.splitlines()[1]}")
|
282 |
convert(apikey, i.text.splitlines()[1], f"sliced_audio_{i.index}_0.wav", voice, i.text.splitlines()[1] + " " + str(i.index))
|
@@ -309,4 +272,4 @@ with gr.Blocks() as app:
|
|
309 |
</div>
|
310 |
''')
|
311 |
|
312 |
-
app.launch(
|
|
|
53 |
from openai import OpenAI
|
54 |
|
55 |
import ffmpeg
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
|
58 |
def convert(api_key, text, tgt, voice, save_path):
|
|
|
224 |
|
225 |
import shutil
|
226 |
|
227 |
+
def convert_from_srt(apikey, filename, audio_full, voice, split_model, multilingual):
|
228 |
subtitle_list = read_srt(filename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
|
|
|
|
|
230 |
if os.path.isdir("output"):
|
231 |
shutil.rmtree("output")
|
232 |
if multilingual==False:
|
233 |
for i in subtitle_list:
|
234 |
os.makedirs("output", exist_ok=True)
|
235 |
+
trim_audio([[i.start_time, i.end_time]], audio_full, f"sliced_audio_{i.index}")
|
236 |
print(f"正在合成第{i.index}条语音")
|
237 |
print(f"语音内容:{i.text}")
|
238 |
convert(apikey, i.text, f"sliced_audio_{i.index}_0.wav", voice, i.text + " " + str(i.index))
|
239 |
else:
|
240 |
for i in subtitle_list:
|
241 |
os.makedirs("output", exist_ok=True)
|
242 |
+
trim_audio([[i.start_time, i.end_time]], audio_full, f"sliced_audio_{i.index}")
|
243 |
print(f"正在合成第{i.index}条语音")
|
244 |
print(f"语音内容:{i.text.splitlines()[1]}")
|
245 |
convert(apikey, i.text.splitlines()[1], f"sliced_audio_{i.index}_0.wav", voice, i.text.splitlines()[1] + " " + str(i.index))
|
|
|
272 |
</div>
|
273 |
''')
|
274 |
|
275 |
+
app.launch(show_error=True)
|