1
0
mirror of https://github.com/fumiama/Retrieval-based-Voice-Conversion-WebUI.git synced 2026-06-05 01:10:22 +08:00
Files
Retrieval-based-Voice-Conve…/infer/modules/vc/utils.py
2026-04-18 19:04:13 +08:00

37 lines
1.0 KiB
Python

import os, pathlib
import torch
from fairseq import checkpoint_utils, data
def get_index_path_from_model(sid):
return next(
(
f
for f in [
str(pathlib.Path(root, name))
for path in [os.getenv("outside_index_root"), os.getenv("index_root")]
for root, _, files in os.walk(path, topdown=False)
for name in files
if name.endswith(".index") and "trained" not in name
]
if sid.split(".")[0] in f
),
"",
)
def load_hubert(device, is_half):
with torch.serialization.safe_globals([data.dictionary.Dictionary]):
models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
["assets/hubert/hubert_base.pt"],
suffix="",
)
hubert_model = models[0]
hubert_model = hubert_model.to(device)
if is_half:
hubert_model = hubert_model.half()
else:
hubert_model = hubert_model.float()
return hubert_model.eval()