Spaces:
Runtime error
Runtime error
import infer_web | |
import wget | |
import os | |
import scipy.io.wavfile as wavfile | |
from utils import model | |
import validators | |
from myutils import delete_files | |
class Inference: | |
inference_cont = 0 | |
def __init__( | |
self, | |
model_name=None, | |
source_audio_path=None, | |
output_file_name=None, | |
feature_index_path="", | |
f0_file=None, | |
speaker_id=0, | |
transposition=-2, | |
f0_method="harvest", | |
crepe_hop_length=160, | |
harvest_median_filter=3, | |
resample=0, | |
mix=1, | |
feature_ratio=0.78, | |
protection_amnt=0.33, | |
protect1=False | |
): | |
Inference.inference_cont += 1 | |
self._model_name = model_name | |
self._source_audio_path = source_audio_path | |
self._output_file_name = output_file_name | |
self._feature_index_path = feature_index_path | |
self._f0_file = f0_file | |
self._speaker_id = speaker_id | |
self._transposition = transposition | |
self._f0_method = f0_method | |
self._crepe_hop_length = crepe_hop_length | |
self._harvest_median_filter = harvest_median_filter | |
self._resample = resample | |
self._mix = mix | |
self._feature_ratio = feature_ratio | |
self._protection_amnt = protection_amnt | |
self._protect1 = protect1 | |
self._id = Inference.inference_cont | |
if not os.path.exists("./hubert_base.pt"): | |
wget.download( | |
"https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/hubert_base.pt", out="./hubert_base.pt") | |
if not os.path.exists("./rmvpe.pt"): | |
wget.download( | |
"https://huggingface.co/lj1995/VoiceConversionWebUI/blob/main/rmvpe.pt", out="./rmvpe.pt" | |
) | |
def id(self): | |
return self._id | |
def id(self, id): | |
self._id = id | |
def audio(self): | |
return self._audio | |
def audio_file(self, audio): | |
self._audio_file = audio | |
def model_name(self): | |
return self._model_name | |
def model_name(self, model_name): | |
self._model_name = model_name | |
def source_audio_path(self): | |
return self._source_audio_path | |
def source_audio_path(self, source_audio_path): | |
if not self._output_file_name: | |
self._output_file_name = os.path.join("./audio-outputs", os.path.basename(source_audio_path)) | |
self._source_audio_path = source_audio_path | |
def output_file_name(self): | |
return self._output_file_name | |
def output_file_name(self, output_file_name): | |
self._output_file_name = output_file_name | |
def feature_index_path(self): | |
return self._feature_index_path | |
def feature_index_path(self, feature_index_path): | |
self._feature_index_path = feature_index_path | |
def f0_file(self): | |
return self._f0_file | |
def f0_file(self, f0_file): | |
self._f0_file = f0_file | |
def speaker_id(self): | |
return self._speaker_id | |
def speaker_id(self, speaker_id): | |
self._speaker_id = speaker_id | |
def transposition(self): | |
return self._transposition | |
def transposition(self, transposition): | |
self._transposition = transposition | |
def f0_method(self): | |
return self._f0_method | |
def f0_method(self, f0_method): | |
self._f0_method = f0_method | |
def crepe_hop_length(self): | |
return self._crepe_hop_length | |
def crepe_hop_length(self, crepe_hop_length): | |
self._crepe_hop_length = crepe_hop_length | |
def harvest_median_filter(self): | |
return self._harvest_median_filter | |
def harvest_median_filter(self, harvest_median_filter): | |
self._harvest_median_filter = harvest_median_filter | |
def resample(self): | |
return self._resample | |
def resample(self, resample): | |
self._resample = resample | |
def mix(self): | |
return self._mix | |
def mix(self, mix): | |
self._mix = mix | |
def feature_ratio(self): | |
return self._feature_ratio | |
def feature_ratio(self, feature_ratio): | |
self._feature_ratio = feature_ratio | |
def protection_amnt(self): | |
return self._protection_amnt | |
def protection_amnt(self, protection_amnt): | |
self._protection_amnt = protection_amnt | |
def protect1(self): | |
return self._protect1 | |
def protect1(self, protect1): | |
self._protect1 = protect1 | |
def run(self): | |
current_dir = os.getcwd() | |
modelname = model.model_downloader(self._model_name, "./zips/", "./weights/") | |
model_info = model.get_model(os.path.join(current_dir, 'weights') , modelname) | |
index = model_info.get('index', '') | |
pth = model_info.get('pth', None) | |
infer_web.get_vc(pth) | |
conversion_data = infer_web.vc_single( | |
self.speaker_id, | |
self.source_audio_path, | |
self.source_audio_path, | |
self.transposition, | |
self.f0_file, | |
self.f0_method, | |
index, | |
index, | |
self.feature_ratio, | |
self.harvest_median_filter, | |
self.resample, | |
self.mix, | |
self.protection_amnt, | |
self.crepe_hop_length, | |
) | |
if "Success." in conversion_data[0]: | |
wavfile.write( | |
"%s/%s" % ("audio-outputs",os.path.basename(self._output_file_name)), | |
conversion_data[1][0], | |
conversion_data[1][1], | |
) | |
return({ | |
"success": True, | |
"file": self._output_file_name | |
}) | |
else: | |
return({ | |
"success": False, | |
"file": self._output_file_name | |
}) | |
#print(conversion_data[0]) |