1+ from typing import cast
12import uuid
23import time
34import json
@@ -40,7 +41,7 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
4041
4142 async def _sync_time (self ):
4243 try :
43- response = await self .client .get (self .auth_time_url )
44+ response = await cast ( AsyncClient , self .client ) .get (self .auth_time_url )
4445 response .raise_for_status ()
4546 server_time = int (response .json ()["timestamp" ])
4647 local_time = int (time .time ())
@@ -62,7 +63,7 @@ async def get_audio(self, text: str, voice_params: dict) -> str:
6263 signature = await self ._generate_signature ()
6364 for attempt in range (self .retry_count ):
6465 try :
65- response = await self .client .post (
66+ response = await cast ( AsyncClient , self .client ) .post (
6667 f"{ self .api_url } ?sign={ signature } " ,
6768 data = {
6869 "text" : text ,
@@ -87,6 +88,7 @@ async def get_audio(self, text: str, voice_params: dict) -> str:
8788 if attempt == self .retry_count - 1 :
8889 raise RuntimeError (f"OTTS请求失败: { str (e )} " ) from e
8990 await asyncio .sleep (0.5 * (attempt + 1 ))
91+ raise RuntimeError ("OTTS未返回音频文件" )
9092
9193
9294class AzureNativeProvider (TTSProvider ):
@@ -130,7 +132,7 @@ async def _refresh_token(self):
130132 token_url = (
131133 f"https://{ self .region } .api.cognitive.microsoft.com/sts/v1.0/issuetoken"
132134 )
133- response = await self .client .post (
135+ response = await cast ( AsyncClient , self .client ) .post (
134136 token_url , headers = {"Ocp-Apim-Subscription-Key" : self .subscription_key }
135137 )
136138 response .raise_for_status ()
@@ -153,7 +155,7 @@ async def get_audio(self, text: str) -> str:
153155 </mstts:express-as>
154156 </voice>
155157 </speak>"""
156- response = await self .client .post (
158+ response = await cast ( AsyncClient , self .client ) .post (
157159 self .endpoint ,
158160 content = ssml ,
159161 headers = {
@@ -176,8 +178,11 @@ def __init__(self, provider_config: dict, provider_settings: dict):
176178 key_value = provider_config .get ("azure_tts_subscription_key" , "" )
177179 self .provider = self ._parse_provider (key_value , provider_config )
178180
179- def _parse_provider (self , key_value : str , config : dict ) -> TTSProvider :
181+ def _parse_provider (
182+ self , key_value : str , config : dict
183+ ) -> OTTSProvider | AzureNativeProvider :
180184 if key_value .lower ().startswith ("other[" ):
185+ json_str = ""
181186 try :
182187 match = re .match (r"other\[(.*)\]" , key_value , re .DOTALL )
183188 if not match :
0 commit comments