@@ -109,20 +109,13 @@ class Settings(BaseSettings):
109
109
AUDIO_DIR : Optional [Path ] = Field (
110
110
default = None ,
111
111
description = (
112
- "Where to save output audio files. "
113
- "If not set, creates a directory in the platform's temporary directory."
112
+ "Where to save output audio files. If not set, creates a directory in the platform's temporary directory."
114
113
),
115
114
)
116
- AUDIO_CACHE_SIZE : int = Field (
117
- default = 300 , gt = - 1 , description = "Max number of audio files to cache."
118
- )
119
- AUDIO_CACHE_CLEAN : bool = Field (
120
- default = True , description = "If True, cleans up generated audio files upon exit."
121
- )
115
+ AUDIO_CACHE_SIZE : int = Field (default = 300 , gt = - 1 , description = "Max number of audio files to cache." )
116
+ AUDIO_CACHE_CLEAN : bool = Field (default = True , description = "If True, cleans up generated audio files upon exit." )
122
117
123
- KEYS_DIR : Path = Field (
124
- default = Path ("keys" ), description = "Where to look for API keys."
125
- )
118
+ KEYS_DIR : Path = Field (default = Path ("keys" ), description = "Where to look for API keys." )
126
119
AWSPOLLY_KEY_FILENAME : str = Field (
127
120
default = "AWSPollyServerKey.json" ,
128
121
description = "Name of the AWS Polly API key file." ,
@@ -140,6 +133,11 @@ class Settings(BaseSettings):
140
133
description = "Name of the OpenAI API key file." ,
141
134
)
142
135
136
+ AWSPOLLY_API_KEY : Optional [str ] = Field (default = None , description = "AWS Polly API key as JSON string" )
137
+ AZURE_API_KEY : Optional [str ] = Field (default = None , description = "Azure API key as JSON string" )
138
+ GOOGLE_API_KEY : Optional [str ] = Field (default = None , description = "Google API key as JSON string" )
139
+ OPENAI_API_KEY : Optional [str ] = Field (default = None , description = "OpenAI API key string" )
140
+
143
141
def get_audio_dir (self ) -> Path :
144
142
"""
145
143
Return directory for saving output audio files.
@@ -187,9 +185,7 @@ class Keys(BaseModel):
187
185
188
186
azure : Optional [AzureKey ] = Field (default = None , description = "Azure API key." )
189
187
aws : Optional [AWSPollyKey ] = Field (default = None , description = "AWS Polly API key." )
190
- google : Optional [dict [str , Any ]] = Field (
191
- default = None , description = "Google API key."
192
- )
188
+ google : Optional [dict [str , Any ]] = Field (default = None , description = "Google API key." )
193
189
openai : Optional [OpenAIKey ] = Field (default = None , description = "OpenAI API key." )
194
190
195
191
def __hash__ (self ):
@@ -213,60 +209,47 @@ def __eq__(self, other: object):
213
209
214
210
_kd = SETTINGS .KEYS_DIR
215
211
if not (_kd .exists () and _kd .is_dir ()):
216
- _LOG .warning (
217
- "Keys directory missing or incorrect: %s" , _kd
218
- )
212
+ _LOG .warning ("Keys directory missing or incorrect: %s" , _kd )
219
213
220
214
# Load API keys, logging exceptions in level DEBUG so they aren't logged twice,
221
215
# as exceptions are logged as warnings when voice modules are initialized
222
216
223
217
# Amazon Polly
224
218
try :
225
- if key := os . getenv ( "ICESPEAK_AWSPOLLY_API_KEY" ) :
226
- API_KEYS .aws = AWSPollyKey .model_validate_json (key )
219
+ if SETTINGS . AWSPOLLY_API_KEY :
220
+ API_KEYS .aws = AWSPollyKey .model_validate_json (SETTINGS . AWSPOLLY_API_KEY )
227
221
else :
228
- API_KEYS .aws = AWSPollyKey .model_validate_json (
229
- (_kd / SETTINGS .AWSPOLLY_KEY_FILENAME ).read_text ().strip ()
230
- )
222
+ API_KEYS .aws = AWSPollyKey .model_validate_json ((_kd / SETTINGS .AWSPOLLY_KEY_FILENAME ).read_text ().strip ())
231
223
except Exception as err :
232
224
_LOG .debug (
233
225
"Could not load AWS Polly API key, ASR with AWS Polly will not work. Error: %s" ,
234
226
err ,
235
227
)
236
228
# Azure
237
229
try :
238
- if key := os . getenv ( "ICESPEAK_AZURE_API_KEY" ) :
239
- API_KEYS .azure = AzureKey .model_validate_json (key )
230
+ if SETTINGS . AZURE_API_KEY :
231
+ API_KEYS .azure = AzureKey .model_validate_json (SETTINGS . AZURE_API_KEY )
240
232
else :
241
- API_KEYS .azure = AzureKey .model_validate_json (
242
- (_kd / SETTINGS .AZURE_KEY_FILENAME ).read_text ().strip ()
243
- )
233
+ API_KEYS .azure = AzureKey .model_validate_json ((_kd / SETTINGS .AZURE_KEY_FILENAME ).read_text ().strip ())
244
234
except Exception as err :
245
- _LOG .debug (
246
- "Could not load Azure API key, ASR with Azure will not work. Error: %s" , err
247
- )
235
+ _LOG .debug ("Could not load Azure API key, ASR with Azure will not work. Error: %s" , err )
248
236
# Google
249
237
try :
250
- if key := os . getenv ( "ICESPEAK_GOOGLE_API_KEY" ) :
251
- API_KEYS .google = json .loads (key )
238
+ if SETTINGS . GOOGLE_API_KEY :
239
+ API_KEYS .google = json .loads (SETTINGS . GOOGLE_API_KEY )
252
240
else :
253
- API_KEYS .google = json .loads (
254
- (_kd / SETTINGS .GOOGLE_KEY_FILENAME ).read_text ().strip ()
255
- )
241
+ API_KEYS .google = json .loads ((_kd / SETTINGS .GOOGLE_KEY_FILENAME ).read_text ().strip ())
256
242
except Exception as err :
257
243
_LOG .debug (
258
244
"Could not load Google API key, ASR with Google will not work. Error: %s" ,
259
245
err ,
260
246
)
261
247
# OpenAI
262
248
try :
263
- # First try to load the key from environment variable OPENAI_API_KEY
264
- if key := os .getenv ("ICESPEAK_OPENAI_API_KEY" ):
265
- API_KEYS .openai = OpenAIKey (api_key = SecretStr (key ))
249
+ if SETTINGS .OPENAI_API_KEY :
250
+ API_KEYS .openai = OpenAIKey (api_key = SecretStr (SETTINGS .OPENAI_API_KEY ))
266
251
else :
267
- API_KEYS .openai = OpenAIKey .model_validate_json (
268
- (_kd / SETTINGS .OPENAI_KEY_FILENAME ).read_text ().strip ()
269
- )
252
+ API_KEYS .openai = OpenAIKey .model_validate_json ((_kd / SETTINGS .OPENAI_KEY_FILENAME ).read_text ().strip ())
270
253
except Exception as err :
271
254
_LOG .debug (
272
255
"Could not load OpenAI API key, ASR with OpenAI will not work. Error: %s" ,
0 commit comments