diff --git a/i18n/locale/en_US.json b/i18n/locale/en_US.json index 5da1dfe..3b91eab 100644 --- a/i18n/locale/en_US.json +++ b/i18n/locale/en_US.json @@ -53,7 +53,7 @@ "加载预训练底模D路径": "Load pre-trained base model D path", "加载预训练底模G路径": "Load pre-trained base model G path", "单次推理": "Single Inference", - "卸载音色省显存": "Unload voice to save GPU memory", + "卸载音色省显存": "Unload model to save GPU memory", "变调(整数, 半音数量, 升八度12降八度-12)": "Transpose (integer, number of semitones, raise by an octave: 12, lower by an octave: -12)", "后处理重采样至最终采样率,0为不进行重采样": "Resample the output audio in post-processing to the final sample rate. Set to 0 for no resampling", "否": "No", diff --git a/infer-web.py b/infer-web.py index 80dcca7..321e5b9 100644 --- a/infer-web.py +++ b/infer-web.py @@ -1093,7 +1093,7 @@ with gr.Blocks(title="RVC WebUI") as app: ) sid0.change( fn=vc.get_vc, - inputs=[sid0, protect0, protect1], + inputs=[sid0, protect0, protect1, file_index2, file_index4], outputs=[ spk_item, protect0, diff --git a/infer/modules/vc/hash.py b/infer/modules/vc/hash.py index 3b76f1a..83fadb3 100644 --- a/infer/modules/vc/hash.py +++ b/infer/modules/vc/hash.py @@ -190,27 +190,30 @@ def _extend_difference(n, a, b): def hash_similarity(h1: str, h2: str) -> float: - h1b, h2b = decode_from_string(h1), decode_from_string(h2) - if len(h1b) != half_hash_len * 2 or len(h2b) != half_hash_len * 2: - raise Exception("invalid hash length") - h1n, h2n = np.frombuffer(h1b, dtype=">i2"), np.frombuffer(h2b, dtype=">i2") - d = 0 - for i in range(half_hash_len // 4): - a = i * 2 - b = a + 1 - ax = complex(h1n[a], h1n[b]) - bx = complex(h2n[a], h2n[b]) - if abs(ax) == 0 or abs(bx) == 0: - continue - d += np.abs(ax - bx) - frac = np.linalg.norm(h1n) * np.linalg.norm(h2n) - cosine = ( - np.dot(h1n.astype(np.float32), h2n.astype(np.float32)) / frac - if frac != 0 - else 1.0 - ) - distance = _extend_difference(np.exp(-d / expand_factor), 0.5, 1.0) - return round((abs(cosine) + distance) / 2, 6) + try: + h1b, h2b = decode_from_string(h1), decode_from_string(h2) + if len(h1b) != half_hash_len * 2 or len(h2b) != half_hash_len * 2: + raise Exception("invalid hash length") + h1n, h2n = np.frombuffer(h1b, dtype=">i2"), np.frombuffer(h2b, dtype=">i2") + d = 0 + for i in range(half_hash_len // 4): + a = i * 2 + b = a + 1 + ax = complex(h1n[a], h1n[b]) + bx = complex(h2n[a], h2n[b]) + if abs(ax) == 0 or abs(bx) == 0: + continue + d += np.abs(ax - bx) + frac = np.linalg.norm(h1n) * np.linalg.norm(h2n) + cosine = ( + np.dot(h1n.astype(np.float32), h2n.astype(np.float32)) / frac + if frac != 0 + else 1.0 + ) + distance = _extend_difference(np.exp(-d / expand_factor), 0.5, 1.0) + return round((abs(cosine) + distance) / 2, 6) + except Exception as e: + return str(e) def hash_id(h: str) -> str: diff --git a/infer/modules/vc/modules.py b/infer/modules/vc/modules.py index 5db22e7..c31e6eb 100644 --- a/infer/modules/vc/modules.py +++ b/infer/modules/vc/modules.py @@ -89,11 +89,15 @@ class VC: elif torch.backends.mps.is_available(): torch.mps.empty_cache() return ( - {"visible": False, "__type__": "update"}, - to_return_protect0, - to_return_protect1, - "", - "", + ( + {"visible": False, "__type__": "update"}, + to_return_protect0, + to_return_protect1, + {"value": to_return_protect[2], "__type__": "update"}, + {"value": to_return_protect[3], "__type__": "update"}, + {"value": "", "__type__": "update"}, + ) if to_return_protect + else {"visible": True, "maximum": 0, "__type__": "update"} ) person = f'{os.getenv("weight_root")}/{sid}' logger.info(f"Loading: {person}") @@ -221,10 +225,10 @@ class VC: % (index_info, *times), (tgt_sr, audio_opt), ) - except: + except Exception as e: info = traceback.format_exc() logger.warning(info) - return info, (None, None) + return str(e), None def vc_multi( self, diff --git a/infer/modules/vc/pipeline.py b/infer/modules/vc/pipeline.py index 6b33022..6833bd9 100644 --- a/infer/modules/vc/pipeline.py +++ b/infer/modules/vc/pipeline.py @@ -253,7 +253,10 @@ class Pipeline(object): # _, I = index.search(npy, 1) # npy = big_npy[I.squeeze()] - score, ix = index.search(npy, k=8) + try: + score, ix = index.search(npy, k=8) + except: + raise Exception("index mistatch") weight = np.square(1 / score) weight /= weight.sum(axis=1, keepdims=True) npy = np.sum(big_npy[ix] * np.expand_dims(weight, axis=2), axis=1)