perf: validate Azure speech key and region before creating speech

This commit is contained in:
harry 2025-05-10 17:20:44 +08:00
parent fec3a8b6bd
commit 4d5ca7f6f4

View File

@ -1337,6 +1337,10 @@ def azure_tts_v2(text: str, voice_name: str, voice_file: str) -> Union[SubMaker,
# Creates an instance of a speech config with specified subscription key and service region. # Creates an instance of a speech config with specified subscription key and service region.
speech_key = config.azure.get("speech_key", "") speech_key = config.azure.get("speech_key", "")
service_region = config.azure.get("speech_region", "") service_region = config.azure.get("speech_region", "")
if not speech_key or not service_region:
logger.error("Azure speech key or region is not set")
return None
audio_config = speechsdk.audio.AudioOutputConfig( audio_config = speechsdk.audio.AudioOutputConfig(
filename=voice_file, use_default_speaker=True filename=voice_file, use_default_speaker=True
) )