File size: 2,026 Bytes
558c90a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
import os, sys, json
from typing import List, Any, Optional ,Dict, Literal   
from pydantic import BaseModel, Field, model_validator

__version__ = "2.6.1"

from Synthesizers.base import load_config


class Api_Config(BaseModel):   
    config_path:str = None
    tts_port: int = 5000
    tts_host: str = "0.0.0.0" 
    synthesizer: str = "gsv_fast"


    def __init__(self, config_path = None):
        super().__init__()
        
        self.config_path = config_path
        assert os.path.exists(self.config_path), f"配置文件不存在: {self.config_path}"
        if os.path.exists(self.config_path):
            all_config = load_config(self.config_path)
            config:dict = all_config.get("common", {})
            for key, value in config.items():
                setattr(self, key, value)
        
class App_Config(BaseModel):

    config_path:str = None
    locale: str = "auto"
    is_share: bool = False
    inbrowser: bool = True
    server_name: str = "0.0.0.0"
    server_port: int = -1 # -1 means auto select
    also_enable_api: bool = True
    synthesizer: str = "gsv_fast"
    max_text_length: int = -1

    @model_validator(mode='after')
    def check_locale(self):
        # Example: validating locale to be one of a set predefined values or patterns
        self.locale = self.locale.replace("-", "_")
        return self

    @staticmethod
    def check_port(port:int, server_name:str):
        url = f"http://{server_name}:{port}"
     
    
    def __init__(self, config_path = None):
        super().__init__()
        
        self.config_path = config_path
        assert os.path.exists(self.config_path), f"配置文件不存在: {self.config_path}"
        if os.path.exists(self.config_path):
            all_config = load_config(self.config_path)
            config = all_config.get("app_config", {})
            for key, value in config.items():
                setattr(self, key, value)

app_config = App_Config("common_config.json")
api_config = Api_Config("common_config.json")