|
22 | 22 | """
|
23 | 23 | # We dont import annotations from __future__ here
|
24 | 24 | # due to pydantic
|
25 |
| -from typing import Any, Optional, Union |
| 25 | +from typing import Any, Optional |
26 | 26 |
|
27 | 27 | import json
|
28 | 28 | import tempfile
|
|
31 | 31 | from logging import getLogger
|
32 | 32 | from pathlib import Path
|
33 | 33 |
|
34 |
| -from pydantic import BaseModel, Field, SecretStr, validator |
| 34 | +from pydantic import BaseModel, Field, SecretStr |
35 | 35 | from pydantic_settings import BaseSettings, SettingsConfigDict
|
36 | 36 |
|
37 | 37 | # Library wide logger instance
|
@@ -80,12 +80,25 @@ class Settings(BaseSettings):
|
80 | 80 | Attributes are read from environment variables or `.env` file.
|
81 | 81 | """
|
82 | 82 |
|
83 |
| - model_config = SettingsConfigDict(env_prefix="ICESPEAK_") |
| 83 | + model_config = SettingsConfigDict( |
| 84 | + env_file=".env", |
| 85 | + env_file_encoding="utf-8", |
| 86 | + env_prefix="ICESPEAK_", |
| 87 | + env_nested_delimiter="__", |
| 88 | + case_sensitive=False, |
| 89 | + # Run validators when attributes are modified |
| 90 | + validate_assignment=True, |
| 91 | + ) |
84 | 92 |
|
85 | 93 | DEFAULT_VOICE: str = Field(
|
86 | 94 | default="Gudrun", description="Default TTS voice if none is requested."
|
87 | 95 | )
|
88 |
| - DEFAULT_VOICE_SPEED: float = Field(default=1.0, le=MAX_SPEED, ge=MIN_SPEED) |
| 96 | + DEFAULT_VOICE_SPEED: float = Field( |
| 97 | + default=1.0, |
| 98 | + le=MAX_SPEED, |
| 99 | + ge=MIN_SPEED, |
| 100 | + description="Default TTS voice speed.", |
| 101 | + ) |
89 | 102 | DEFAULT_TEXT_FORMAT: TextFormats = Field(
|
90 | 103 | default=TextFormats.SSML,
|
91 | 104 | description="Default format to interpret input text as.",
|
@@ -124,16 +137,6 @@ class Settings(BaseSettings):
|
124 | 137 | description="Name of the Google API key file.",
|
125 | 138 | )
|
126 | 139 |
|
127 |
| - # Logging settings |
128 |
| - LOG_LEVEL: Union[str, int] = Field(default="INFO", description="Logging level.") |
129 |
| - |
130 |
| - @validator("LOG_LEVEL") |
131 |
| - def set_log_level(cls, lvl: Union[str, int]) -> Union[str, int]: |
132 |
| - # Set logging level for root Ratatoskur logger, |
133 |
| - # this raises a ValueError if the provided level is invalid |
134 |
| - LOG.setLevel(lvl) |
135 |
| - return lvl |
136 |
| - |
137 | 140 | def get_audio_dir(self) -> Path:
|
138 | 141 | """
|
139 | 142 | Return directory for saving output audio files.
|
@@ -182,7 +185,9 @@ class Keys(BaseModel):
|
182 | 185 |
|
183 | 186 | _kd = SETTINGS.KEYS_DIR
|
184 | 187 | if not (_kd.exists() and _kd.is_dir()):
|
185 |
| - LOG.warning("Keys directory missing or incorrect, TTS will not work!") |
| 188 | + LOG.warning( |
| 189 | + "Keys directory missing or incorrect, TTS will not work! Set to: %s", _kd |
| 190 | + ) |
186 | 191 | else:
|
187 | 192 | # Load API keys, logging exceptions in level DEBUG so they aren't logged twice,
|
188 | 193 | # as exceptions are logged as warnings when voice modules are initialized
|
|
0 commit comments