File size: 1,719 Bytes
04ffec9
 
 
 
 
 
 
1f3bd14
04ffec9
 
 
 
 
 
 
 
 
1f3bd14
04ffec9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import numpy as np
from typing import List

from speakers.common.registry import registry
from speakers.tasks.base_task import BaseTask, Runner, FlowData
from speakers.tasks.vits_voice_task import VitsVoiceTask, VitsVoiceFlowData
from speakers.tasks.bark_voice_task import BarkVoiceTask, BarkVoiceFlowData
from speakers.tasks.edge_voice_task import EdgeVoiceTask, EdgeVoiceFlowData

__all__ = [
    "BaseTask",
    "Runner",
    "FlowData",
    "load_task",
    "get_task",
    "VitsVoiceFlowData",
    "BarkVoiceFlowData",
    "EdgeVoiceFlowData",
    "tasks_cache"
]

tasks_cache = {}


def load_task(config: dict = None):
    """
    Load preprocessor configs and construct preprocessors.

    If no preprocessor is specified, return BaseProcessor, which does not do any preprocessing.

    Args:
        config (dict): preprocessor configs.

    Returns:
        vits_processors (dict): preprocessors for vits inputs.
        rvc_processors (dict): preprocessors for rvc inputs.

    """

    if config is None:
        raise RuntimeError("Load preprocessor configs is None.")

    def _build_task_from_cfg(cfg):
        return (
            registry.get_task_class(cfg.name).from_config(cfg)
            if cfg is not None
            else BaseTask()
        )
    for task in config:
        for key, task_cfg in task.items():  # 使用 .items() 方法获取键值对
            processors = _build_task_from_cfg(task_cfg)
            tasks_cache[key] = processors


def get_task(key: str) -> BaseTask:

    if not tasks_cache.get(key):
        raise ValueError(f'Could not find task for: "{key}". '
                         f'Choose from the following: %s' % ','.join(tasks_cache))

    return tasks_cache[key]