From 23fffa95c86fd0dd69ce25104831d3310a2eeea8 Mon Sep 17 00:00:00 2001 From: lustresixx Date: Tue, 10 Mar 2026 17:09:13 +0800 Subject: [PATCH] fix(provider): support 84-char Azure TTS subscription keys (#5813) * fix(provider): support 84-char Azure TTS subscription keys * test(provider): add negative Azure TTS key validation cases * chore: delete test --------- Co-authored-by: Soulter <905617992@qq.com> --- astrbot/core/provider/sources/azure_tts_source.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/astrbot/core/provider/sources/azure_tts_source.py b/astrbot/core/provider/sources/azure_tts_source.py index 0e8f00ce5..fc2bb6c09 100644 --- a/astrbot/core/provider/sources/azure_tts_source.py +++ b/astrbot/core/provider/sources/azure_tts_source.py @@ -20,6 +20,7 @@ from ..register import register_provider_adapter TEMP_DIR = Path(get_astrbot_temp_path()) / "azure_tts" TEMP_DIR.mkdir(parents=True, exist_ok=True) +AZURE_TTS_SUBSCRIPTION_KEY_PATTERN = r"^(?:[a-zA-Z0-9]{32}|[a-zA-Z0-9]{84})$" class OTTSProvider: @@ -116,7 +117,7 @@ class AzureNativeProvider(TTSProvider): "azure_tts_subscription_key", "", ).strip() - if not re.fullmatch(r"^[a-zA-Z0-9]{32}$", self.subscription_key): + if not re.fullmatch(AZURE_TTS_SUBSCRIPTION_KEY_PATTERN, self.subscription_key): raise ValueError("无效的Azure订阅密钥") self.region = provider_config.get("azure_tts_region", "eastus").strip() self.endpoint = ( @@ -235,9 +236,9 @@ class AzureTTSProvider(TTSProvider): raise ValueError(error_msg) from e except KeyError as e: raise ValueError(f"配置错误: 缺少必要参数 {e}") from e - if re.fullmatch(r"^[a-zA-Z0-9]{32}$", key_value): + if re.fullmatch(AZURE_TTS_SUBSCRIPTION_KEY_PATTERN, key_value): return AzureNativeProvider(config, self.provider_settings) - raise ValueError("订阅密钥格式无效,应为32位字母数字或other[...]格式") + raise ValueError("订阅密钥格式无效,应为32位或84位字母数字或other[...]格式") async def get_audio(self, text: str) -> str: if isinstance(self.provider, OTTSProvider):