@@ -22,14 +22,12 @@ def __init__(self, options: AiolaClientOptions, auth: AuthClient | AsyncAuthClie
2222 def _make_headers () -> dict [str , str ]:
2323 return {"Accept" : "audio/*" }
2424
25- def _validate_tts_params (self , text : str , voice : str , language : str | None ) -> None :
25+ def _validate_tts_params (self , text : str , voice_id : str ) -> None :
2626 """Validate TTS parameters."""
2727 if not text or not isinstance (text , str ):
2828 raise AiolaValidationError ("text must be a non-empty string" )
29- if not voice or not isinstance (voice , str ):
30- raise AiolaValidationError ("voice must be a non-empty string" )
31- if language is not None and not isinstance (language , str ):
32- raise AiolaValidationError ("language must be a string" )
29+ if not voice_id or not isinstance (voice_id , str ):
30+ raise AiolaValidationError ("voice_id must be a non-empty string" )
3331
3432
3533class TtsClient (BaseTts ):
@@ -39,9 +37,9 @@ def __init__(self, options: AiolaClientOptions, auth: AuthClient):
3937 super ().__init__ (options , auth )
4038 self ._auth : AuthClient = auth # Type narrowing
4139
42- def stream (self , * , text : str , voice : str , language : str | None = None ) -> Iterator [bytes ]:
40+ def stream (self , * , text : str , voice_id : str ) -> Iterator [bytes ]:
4341 """Stream synthesized audio in real-time."""
44- self ._validate_tts_params (text , voice , language )
42+ self ._validate_tts_params (text , voice_id )
4543
4644 try :
4745 # Create authenticated HTTP client and make the streaming request
@@ -52,13 +50,17 @@ def stream(self, *, text: str, voice: str, language: str | None = None) -> Itera
5250 "/api/tts/stream" ,
5351 json = {
5452 "text" : text ,
55- "voice" : voice ,
56- "language" : language ,
53+ "voice_id" : voice_id ,
5754 },
5855 headers = self ._make_headers (),
5956 ) as response ,
6057 ):
61- response .raise_for_status ()
58+ try :
59+ response .raise_for_status ()
60+ except httpx .HTTPStatusError :
61+ response .read ()
62+ raise
63+
6264 yield from response .iter_bytes ()
6365
6466 except AiolaError :
@@ -75,9 +77,9 @@ def stream(self, *, text: str, voice: str, language: str | None = None) -> Itera
7577 except Exception as exc :
7678 raise AiolaError (f"TTS streaming failed: { str (exc )} " ) from exc
7779
78- def synthesize (self , * , text : str , voice : str , language : str | None = None ) -> Iterator [bytes ]:
80+ def synthesize (self , * , text : str , voice_id : str ) -> Iterator [bytes ]:
7981 """Synthesize audio and return as iterator of bytes."""
80- self ._validate_tts_params (text , voice , language )
82+ self ._validate_tts_params (text , voice_id )
8183
8284 try :
8385 # Create authenticated HTTP client and make the streaming request
@@ -88,13 +90,17 @@ def synthesize(self, *, text: str, voice: str, language: str | None = None) -> I
8890 "/api/tts/synthesize" ,
8991 json = {
9092 "text" : text ,
91- "voice" : voice ,
92- "language" : language ,
93+ "voice_id" : voice_id ,
9394 },
9495 headers = self ._make_headers (),
9596 ) as response ,
9697 ):
97- response .raise_for_status ()
98+ try :
99+ response .raise_for_status ()
100+ except httpx .HTTPStatusError :
101+ response .read ()
102+ raise
103+
98104 yield from response .iter_bytes ()
99105
100106 except AiolaError :
@@ -119,9 +125,9 @@ def __init__(self, options: AiolaClientOptions, auth: AsyncAuthClient):
119125 super ().__init__ (options , auth )
120126 self ._auth : AsyncAuthClient = auth # Type narrowing
121127
122- async def stream (self , * , text : str , voice : str , language : str | None = None ) -> AsyncIterator [bytes ]:
128+ async def stream (self , * , text : str , voice_id : str ) -> AsyncIterator [bytes ]:
123129 """Stream synthesized audio in real-time (async)."""
124- self ._validate_tts_params (text , voice , language )
130+ self ._validate_tts_params (text , voice_id )
125131
126132 try :
127133 # Create authenticated HTTP client and make the streaming request
@@ -133,13 +139,17 @@ async def stream(self, *, text: str, voice: str, language: str | None = None) ->
133139 "/api/tts/stream" ,
134140 json = {
135141 "text" : text ,
136- "voice" : voice ,
137- "language" : language ,
142+ "voice_id" : voice_id ,
138143 },
139144 headers = self ._make_headers (),
140145 ) as response ,
141146 ):
142- response .raise_for_status ()
147+ try :
148+ response .raise_for_status ()
149+ except httpx .HTTPStatusError :
150+ await response .aread ()
151+ raise
152+
143153 async for chunk in response .aiter_bytes ():
144154 yield chunk
145155
@@ -157,9 +167,9 @@ async def stream(self, *, text: str, voice: str, language: str | None = None) ->
157167 except Exception as exc :
158168 raise AiolaError (f"Async TTS streaming failed: { str (exc )} " ) from exc
159169
160- async def synthesize (self , * , text : str , voice : str , language : str | None = None ) -> AsyncIterator [bytes ]:
170+ async def synthesize (self , * , text : str , voice_id : str ) -> AsyncIterator [bytes ]:
161171 """Synthesize audio and return as async iterator of bytes."""
162- self ._validate_tts_params (text , voice , language )
172+ self ._validate_tts_params (text , voice_id )
163173
164174 try :
165175 # Create authenticated HTTP client and make the streaming request
@@ -171,13 +181,17 @@ async def synthesize(self, *, text: str, voice: str, language: str | None = None
171181 "/api/tts/synthesize" ,
172182 json = {
173183 "text" : text ,
174- "voice" : voice ,
175- "language" : language ,
184+ "voice_id" : voice_id ,
176185 },
177186 headers = self ._make_headers (),
178187 ) as response ,
179188 ):
180- response .raise_for_status ()
189+ try :
190+ response .raise_for_status ()
191+ except httpx .HTTPStatusError :
192+ await response .aread ()
193+ raise
194+
181195 async for chunk in response .aiter_bytes ():
182196 yield chunk
183197
0 commit comments