Skip to content

Commit

Permalink
Fix/fix-speakers-not-updated (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
34j authored Mar 23, 2023
1 parent 6e77be6 commit 1accf1d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 16 deletions.
13 changes: 11 additions & 2 deletions src/so_vits_svc_fork/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@
import torch
from rich.logging import RichHandler

from so_vits_svc_fork import __version__

LOG = getLogger(__name__)
LOGGER_INIT = False


def init_logger() -> None:
global LOGGER_INIT
if LOGGER_INIT:
return
IN_COLAB = os.getenv("COLAB_RELEASE_TAG")
IS_TEST = "test" in Path(__file__).parent.stem

Expand All @@ -36,10 +44,11 @@ def init_logger() -> None:
if IS_TEST:
LOG.debug("Test mode is on.")

LOG.info(f"Version: {__version__}")
LOGGER_INIT = True

init_logger()

LOG = getLogger(__name__)
init_logger()


class RichHelpFormatter(click.HelpFormatter):
Expand Down
6 changes: 4 additions & 2 deletions src/so_vits_svc_fork/default_gui_presets.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"additional_infer_before_seconds": 0.15,
"additional_infer_after_seconds": 0.1,
"realtime_algorithm": "1 (Divide constantly)",
"passthrough_original": false
"passthrough_original": false,
"use_gpu": true
},
"Default VC (CPU)": {
"silence_threshold": -35.0,
Expand Down Expand Up @@ -67,7 +68,8 @@
"additional_infer_before_seconds": 0.05,
"additional_infer_after_seconds": 0.05,
"realtime_algorithm": "1 (Divide constantly)",
"passthrough_original": false
"passthrough_original": false,
"use_gpu": true
},
"Default File": {
"silence_threshold": -35.0,
Expand Down
49 changes: 37 additions & 12 deletions src/so_vits_svc_fork/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,19 @@ def delete_preset(name: str) -> dict:
return load_presets()


def main():
sg.theme("Dark")
model_candidates = list(sorted(Path("./logs/44k/").glob("G_*.pth")))

def get_devices(update: bool = True) -> tuple[list[str], list[str]]:
if update:
sd._terminate()
sd._initialize()
devices = sd.query_devices()
input_devices = [d["name"] for d in devices if d["max_input_channels"] > 0]
output_devices = [d["name"] for d in devices if d["max_output_channels"] > 0]
return input_devices, output_devices


def main():
sg.theme("Dark")
model_candidates = list(sorted(Path("./logs/44k/").glob("G_*.pth")))

frame_contents = {
"Paths": [
Expand Down Expand Up @@ -278,19 +284,17 @@ def main():
sg.Push(),
sg.Combo(
key="input_device",
values=input_devices,
values=[],
size=(20, 1),
default_value=input_devices[0],
),
],
[
sg.Text("Output device"),
sg.Push(),
sg.Combo(
key="output_device",
values=output_devices,
values=[],
size=(20, 1),
default_value=output_devices[0],
),
],
[
Expand Down Expand Up @@ -401,11 +405,31 @@ def update_speaker() -> None:
config_path = Path(values["config_path"])
if config_path.exists() and config_path.is_file():
hp = utils.get_hparams_from_file(values["config_path"])
LOG.info(f"Loaded config from {values['config_path']}")
LOG.debug(f"Loaded config from {values['config_path']}")
window["speaker"].update(
values=list(hp.__dict__["spk"].keys()), set_to_index=0
)

def update_devices() -> None:
input_devices, output_devices = get_devices()
window["input_device"].update(
values=input_devices, value=values["input_device"]
)
window["output_device"].update(
values=output_devices, value=values["output_device"]
)
input_default, output_default = sd.default.device
if values["input_device"] not in input_devices:
window["input_device"].update(
values=input_devices,
set_to_index=0 if input_default is None else input_default - 1,
)
if values["output_device"] not in output_devices:
window["output_device"].update(
values=output_devices,
set_to_index=0 if output_default is None else output_default - 1,
)

PRESET_KEYS = [
key
for key in values.keys()
Expand All @@ -416,20 +440,21 @@ def apply_preset(name: str) -> None:
for key, value in load_presets()[name].items():
if key in PRESET_KEYS:
window[key].update(value)
values[key] = value

update_speaker()
default_name = list(load_presets().keys())[0]
apply_preset(default_name)
window["presets"].update(default_name)
del default_name
with ProcessPool(max_workers=1) as pool:
future: None | ProcessFuture = None
while True:
event, values = window.read(100)
event, values = window.read(500)
if event == sg.WIN_CLOSED:
break
if not event == sg.EVENT_TIMEOUT:
LOG.info(f"Event {event}, values {values}")
update_devices()
if event.endswith("_path"):
for name in window.AllKeysDict:
if str(name).endswith("_browse"):
Expand All @@ -442,7 +467,7 @@ def apply_preset(name: str) -> None:
browser.update()
else:
LOG.warning(f"Browser {browser} is not a FileBrowse")
elif event == "add_preset":
if event == "add_preset":
presets = add_preset(
values["preset_name"], {key: values[key] for key in PRESET_KEYS}
)
Expand Down

0 comments on commit 1accf1d

Please sign in to comment.