Skip to content

Commit 9030acf

Browse files
committed
Fix reading of .env file
1 parent c705074 commit 9030acf

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

src/icespeak/settings.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"""
2323
# We dont import annotations from __future__ here
2424
# due to pydantic
25-
from typing import Any, Optional, Union
25+
from typing import Any, Optional
2626

2727
import json
2828
import tempfile
@@ -31,7 +31,7 @@
3131
from logging import getLogger
3232
from pathlib import Path
3333

34-
from pydantic import BaseModel, Field, SecretStr, validator
34+
from pydantic import BaseModel, Field, SecretStr
3535
from pydantic_settings import BaseSettings, SettingsConfigDict
3636

3737
# Library wide logger instance
@@ -80,12 +80,25 @@ class Settings(BaseSettings):
8080
Attributes are read from environment variables or `.env` file.
8181
"""
8282

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+
)
8492

8593
DEFAULT_VOICE: str = Field(
8694
default="Gudrun", description="Default TTS voice if none is requested."
8795
)
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+
)
89102
DEFAULT_TEXT_FORMAT: TextFormats = Field(
90103
default=TextFormats.SSML,
91104
description="Default format to interpret input text as.",
@@ -124,16 +137,6 @@ class Settings(BaseSettings):
124137
description="Name of the Google API key file.",
125138
)
126139

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-
137140
def get_audio_dir(self) -> Path:
138141
"""
139142
Return directory for saving output audio files.
@@ -182,7 +185,9 @@ class Keys(BaseModel):
182185

183186
_kd = SETTINGS.KEYS_DIR
184187
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+
)
186191
else:
187192
# Load API keys, logging exceptions in level DEBUG so they aren't logged twice,
188193
# as exceptions are logged as warnings when voice modules are initialized

src/icespeak/voices/azure.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,10 @@ def load_api_keys(self):
165165
# See issues regarding compatibility with OpenSSL version >=3:
166166
# https://github.com/Azure-Samples/cognitive-services-speech-sdk/issues/1747
167167
# https://github.com/Azure-Samples/cognitive-services-speech-sdk/issues/1986
168-
LOG.warning("OpenSSL version not compatible with Azure Cognitive Services.")
169-
raise RuntimeError("Incompatible OpenSSL version.")
168+
LOG.warning(
169+
"OpenSSL version not compatible with "
170+
"Azure Cognitive Services, TTS might not work."
171+
)
170172

171173
if API_KEYS.azure is None:
172174
raise RuntimeError("Azure API keys missing.")

0 commit comments

Comments
 (0)