File size: 1,770 Bytes
35bb6f4 97fe226 35bb6f4 97fe226 35bb6f4 | 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 67 68 69 | from __future__ import annotations
import json
from typing import Literal
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
model_config = {"env_prefix": "NEUTTS_", "env_file": ".env", "extra": "ignore"}
# Server
host: str = "0.0.0.0"
port: int = 8880
# Models
default_models: str = "neutts-nano-q4-gguf"
default_codec: str = "neuphonic/neucodec-onnx-decoder"
default_backbone_device: Literal["auto", "cpu", "cuda"] = "auto"
default_codec_device: Literal["cpu", "cuda"] = "cpu"
# Voice
default_voice: str = "jo"
# Audio
sample_rate: int = 24000
default_response_format: Literal["mp3", "opus", "aac", "flac", "wav", "pcm"] = "mp3"
# CORS
cors_enabled: bool = True
cors_origins: str = "*"
# Logging
log_level: str = "INFO"
# Performance
max_inference_workers: int = 4
# Voice Upload
allow_voice_upload: bool = True
@property
def cors_origins_list(self) -> list[str]:
try:
parsed = json.loads(self.cors_origins)
if isinstance(parsed, list):
return parsed
except json.JSONDecodeError:
pass
return [o.strip() for o in self.cors_origins.split(",") if o.strip()]
@property
def default_models_list(self) -> list[str]:
return [m.strip() for m in self.default_models.split(",") if m.strip()]
@property
def resolved_backbone_device(self) -> str:
if self.default_backbone_device == "auto":
try:
import torch
return "cuda" if torch.cuda.is_available() else "cpu"
except ImportError:
return "cpu"
return self.default_backbone_device
settings = Settings()
|