Skip to content

Commit b5063c5

Browse files
fern-api[bot]louisjoecodes
authored andcommitted
SDK regeneration
1 parent ec0c1b3 commit b5063c5

11 files changed

+217
-62
lines changed

poetry.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "elevenlabs"
3-
version = "1.13.4"
3+
version = "1.13.5"
44
description = ""
55
readme = "README.md"
66
authors = []

reference.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,10 +1176,12 @@ from elevenlabs import ElevenLabs
11761176
client = ElevenLabs(
11771177
api_key="YOUR_API_KEY",
11781178
)
1179-
client.text_to_speech.stream_with_timestamps(
1179+
response = client.text_to_speech.stream_with_timestamps(
11801180
voice_id="21m00Tcm4TlvDq8ikWAM",
11811181
text="text",
11821182
)
1183+
for chunk in response:
1184+
yield chunk
11831185

11841186
```
11851187
</dd>

src/elevenlabs/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@
240240
BodyTextToSpeechStreamingWithTimestampsV1TextToSpeechVoiceIdStreamWithTimestampsPostApplyTextNormalization,
241241
BodyTextToSpeechV1TextToSpeechVoiceIdPostApplyTextNormalization,
242242
BodyTextToSpeechWithTimestampsV1TextToSpeechVoiceIdWithTimestampsPostApplyTextNormalization,
243+
TextToSpeechStreamWithTimestampsResponse,
244+
TextToSpeechStreamWithTimestampsResponseAlignment,
245+
TextToSpeechStreamWithTimestampsResponseNormalizedAlignment,
243246
)
244247
from .text_to_voice import TextToVoiceCreatePreviewsRequestOutputFormat
245248
from .version import __version__
@@ -428,6 +431,9 @@
428431
"SubscriptionResponseModelCurrency",
429432
"SubscriptionStatus",
430433
"TextToSpeechAsStreamRequest",
434+
"TextToSpeechStreamWithTimestampsResponse",
435+
"TextToSpeechStreamWithTimestampsResponseAlignment",
436+
"TextToSpeechStreamWithTimestampsResponseNormalizedAlignment",
431437
"TextToVoiceCreatePreviewsRequestOutputFormat",
432438
"TtsConversationalConfig",
433439
"TtsConversationalConfigOverride",

src/elevenlabs/core/client_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def get_headers(self) -> typing.Dict[str, str]:
1616
headers: typing.Dict[str, str] = {
1717
"X-Fern-Language": "Python",
1818
"X-Fern-SDK-Name": "elevenlabs",
19-
"X-Fern-SDK-Version": "1.13.4",
19+
"X-Fern-SDK-Version": "1.13.5",
2020
}
2121
if self._api_key is not None:
2222
headers["xi-api-key"] = self._api_key

src/elevenlabs/text_to_speech/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
BodyTextToSpeechStreamingWithTimestampsV1TextToSpeechVoiceIdStreamWithTimestampsPostApplyTextNormalization,
66
BodyTextToSpeechV1TextToSpeechVoiceIdPostApplyTextNormalization,
77
BodyTextToSpeechWithTimestampsV1TextToSpeechVoiceIdWithTimestampsPostApplyTextNormalization,
8+
TextToSpeechStreamWithTimestampsResponse,
9+
TextToSpeechStreamWithTimestampsResponseAlignment,
10+
TextToSpeechStreamWithTimestampsResponseNormalizedAlignment,
811
)
912

1013
__all__ = [
1114
"BodyTextToSpeechStreamingV1TextToSpeechVoiceIdStreamPostApplyTextNormalization",
1215
"BodyTextToSpeechStreamingWithTimestampsV1TextToSpeechVoiceIdStreamWithTimestampsPostApplyTextNormalization",
1316
"BodyTextToSpeechV1TextToSpeechVoiceIdPostApplyTextNormalization",
1417
"BodyTextToSpeechWithTimestampsV1TextToSpeechVoiceIdWithTimestampsPostApplyTextNormalization",
18+
"TextToSpeechStreamWithTimestampsResponse",
19+
"TextToSpeechStreamWithTimestampsResponseAlignment",
20+
"TextToSpeechStreamWithTimestampsResponseNormalizedAlignment",
1521
]

src/elevenlabs/text_to_speech/client.py

Lines changed: 82 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from .types.body_text_to_speech_streaming_with_timestamps_v_1_text_to_speech_voice_id_stream_with_timestamps_post_apply_text_normalization import (
2727
BodyTextToSpeechStreamingWithTimestampsV1TextToSpeechVoiceIdStreamWithTimestampsPostApplyTextNormalization,
2828
)
29+
from .types.text_to_speech_stream_with_timestamps_response import TextToSpeechStreamWithTimestampsResponse
30+
import json
2931
from ..core.client_wrapper import AsyncClientWrapper
3032

3133
# this is used as the default value for optional parameters
@@ -538,7 +540,7 @@ def stream_with_timestamps(
538540
BodyTextToSpeechStreamingWithTimestampsV1TextToSpeechVoiceIdStreamWithTimestampsPostApplyTextNormalization
539541
] = OMIT,
540542
request_options: typing.Optional[RequestOptions] = None,
541-
) -> None:
543+
) -> typing.Iterator[TextToSpeechStreamWithTimestampsResponse]:
542544
"""
543545
Converts text into speech using a voice of your choice and returns a stream of JSONs containing audio as a base64 encoded string together with information on when which character was spoken.
544546
@@ -595,9 +597,10 @@ def stream_with_timestamps(
595597
request_options : typing.Optional[RequestOptions]
596598
Request-specific configuration.
597599
598-
Returns
599-
-------
600-
None
600+
Yields
601+
------
602+
typing.Iterator[TextToSpeechStreamWithTimestampsResponse]
603+
Stream of JSON objects containing audio chunks and character timing information
601604
602605
Examples
603606
--------
@@ -606,12 +609,14 @@ def stream_with_timestamps(
606609
client = ElevenLabs(
607610
api_key="YOUR_API_KEY",
608611
)
609-
client.text_to_speech.stream_with_timestamps(
612+
response = client.text_to_speech.stream_with_timestamps(
610613
voice_id="21m00Tcm4TlvDq8ikWAM",
611614
text="text",
612615
)
616+
for chunk in response:
617+
yield chunk
613618
"""
614-
_response = self._client_wrapper.httpx_client.request(
619+
with self._client_wrapper.httpx_client.stream(
615620
f"v1/text-to-speech/{jsonable_encoder(voice_id)}/stream/with-timestamps",
616621
method="POST",
617622
params={
@@ -644,24 +649,38 @@ def stream_with_timestamps(
644649
},
645650
request_options=request_options,
646651
omit=OMIT,
647-
)
648-
try:
649-
if 200 <= _response.status_code < 300:
650-
return
651-
if _response.status_code == 422:
652-
raise UnprocessableEntityError(
653-
typing.cast(
654-
HttpValidationError,
655-
construct_type(
656-
type_=HttpValidationError, # type: ignore
657-
object_=_response.json(),
658-
),
652+
) as _response:
653+
try:
654+
if 200 <= _response.status_code < 300:
655+
for _text in _response.iter_lines():
656+
try:
657+
if len(_text) == 0:
658+
continue
659+
yield typing.cast(
660+
TextToSpeechStreamWithTimestampsResponse,
661+
construct_type(
662+
type_=TextToSpeechStreamWithTimestampsResponse, # type: ignore
663+
object_=json.loads(_text),
664+
),
665+
)
666+
except:
667+
pass
668+
return
669+
_response.read()
670+
if _response.status_code == 422:
671+
raise UnprocessableEntityError(
672+
typing.cast(
673+
HttpValidationError,
674+
construct_type(
675+
type_=HttpValidationError, # type: ignore
676+
object_=_response.json(),
677+
),
678+
)
659679
)
660-
)
661-
_response_json = _response.json()
662-
except JSONDecodeError:
663-
raise ApiError(status_code=_response.status_code, body=_response.text)
664-
raise ApiError(status_code=_response.status_code, body=_response_json)
680+
_response_json = _response.json()
681+
except JSONDecodeError:
682+
raise ApiError(status_code=_response.status_code, body=_response.text)
683+
raise ApiError(status_code=_response.status_code, body=_response_json)
665684

666685

667686
class AsyncTextToSpeechClient:
@@ -1194,7 +1213,7 @@ async def stream_with_timestamps(
11941213
BodyTextToSpeechStreamingWithTimestampsV1TextToSpeechVoiceIdStreamWithTimestampsPostApplyTextNormalization
11951214
] = OMIT,
11961215
request_options: typing.Optional[RequestOptions] = None,
1197-
) -> None:
1216+
) -> typing.AsyncIterator[TextToSpeechStreamWithTimestampsResponse]:
11981217
"""
11991218
Converts text into speech using a voice of your choice and returns a stream of JSONs containing audio as a base64 encoded string together with information on when which character was spoken.
12001219
@@ -1251,9 +1270,10 @@ async def stream_with_timestamps(
12511270
request_options : typing.Optional[RequestOptions]
12521271
Request-specific configuration.
12531272
1254-
Returns
1255-
-------
1256-
None
1273+
Yields
1274+
------
1275+
typing.AsyncIterator[TextToSpeechStreamWithTimestampsResponse]
1276+
Stream of JSON objects containing audio chunks and character timing information
12571277
12581278
Examples
12591279
--------
@@ -1267,15 +1287,17 @@ async def stream_with_timestamps(
12671287
12681288
12691289
async def main() -> None:
1270-
await client.text_to_speech.stream_with_timestamps(
1290+
response = await client.text_to_speech.stream_with_timestamps(
12711291
voice_id="21m00Tcm4TlvDq8ikWAM",
12721292
text="text",
12731293
)
1294+
async for chunk in response:
1295+
yield chunk
12741296
12751297
12761298
asyncio.run(main())
12771299
"""
1278-
_response = await self._client_wrapper.httpx_client.request(
1300+
async with self._client_wrapper.httpx_client.stream(
12791301
f"v1/text-to-speech/{jsonable_encoder(voice_id)}/stream/with-timestamps",
12801302
method="POST",
12811303
params={
@@ -1308,21 +1330,35 @@ async def main() -> None:
13081330
},
13091331
request_options=request_options,
13101332
omit=OMIT,
1311-
)
1312-
try:
1313-
if 200 <= _response.status_code < 300:
1314-
return
1315-
if _response.status_code == 422:
1316-
raise UnprocessableEntityError(
1317-
typing.cast(
1318-
HttpValidationError,
1319-
construct_type(
1320-
type_=HttpValidationError, # type: ignore
1321-
object_=_response.json(),
1322-
),
1333+
) as _response:
1334+
try:
1335+
if 200 <= _response.status_code < 300:
1336+
async for _text in _response.aiter_lines():
1337+
try:
1338+
if len(_text) == 0:
1339+
continue
1340+
yield typing.cast(
1341+
TextToSpeechStreamWithTimestampsResponse,
1342+
construct_type(
1343+
type_=TextToSpeechStreamWithTimestampsResponse, # type: ignore
1344+
object_=json.loads(_text),
1345+
),
1346+
)
1347+
except:
1348+
pass
1349+
return
1350+
await _response.aread()
1351+
if _response.status_code == 422:
1352+
raise UnprocessableEntityError(
1353+
typing.cast(
1354+
HttpValidationError,
1355+
construct_type(
1356+
type_=HttpValidationError, # type: ignore
1357+
object_=_response.json(),
1358+
),
1359+
)
13231360
)
1324-
)
1325-
_response_json = _response.json()
1326-
except JSONDecodeError:
1327-
raise ApiError(status_code=_response.status_code, body=_response.text)
1328-
raise ApiError(status_code=_response.status_code, body=_response_json)
1361+
_response_json = _response.json()
1362+
except JSONDecodeError:
1363+
raise ApiError(status_code=_response.status_code, body=_response.text)
1364+
raise ApiError(status_code=_response.status_code, body=_response_json)

src/elevenlabs/text_to_speech/types/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@
1212
from .body_text_to_speech_with_timestamps_v_1_text_to_speech_voice_id_with_timestamps_post_apply_text_normalization import (
1313
BodyTextToSpeechWithTimestampsV1TextToSpeechVoiceIdWithTimestampsPostApplyTextNormalization,
1414
)
15+
from .text_to_speech_stream_with_timestamps_response import TextToSpeechStreamWithTimestampsResponse
16+
from .text_to_speech_stream_with_timestamps_response_alignment import TextToSpeechStreamWithTimestampsResponseAlignment
17+
from .text_to_speech_stream_with_timestamps_response_normalized_alignment import (
18+
TextToSpeechStreamWithTimestampsResponseNormalizedAlignment,
19+
)
1520

1621
__all__ = [
1722
"BodyTextToSpeechStreamingV1TextToSpeechVoiceIdStreamPostApplyTextNormalization",
1823
"BodyTextToSpeechStreamingWithTimestampsV1TextToSpeechVoiceIdStreamWithTimestampsPostApplyTextNormalization",
1924
"BodyTextToSpeechV1TextToSpeechVoiceIdPostApplyTextNormalization",
2025
"BodyTextToSpeechWithTimestampsV1TextToSpeechVoiceIdWithTimestampsPostApplyTextNormalization",
26+
"TextToSpeechStreamWithTimestampsResponse",
27+
"TextToSpeechStreamWithTimestampsResponseAlignment",
28+
"TextToSpeechStreamWithTimestampsResponseNormalizedAlignment",
2129
]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This file was auto-generated by Fern from our API Definition.
2+
3+
from ...core.unchecked_base_model import UncheckedBaseModel
4+
import typing_extensions
5+
import typing
6+
from ...core.serialization import FieldMetadata
7+
import pydantic
8+
from .text_to_speech_stream_with_timestamps_response_alignment import TextToSpeechStreamWithTimestampsResponseAlignment
9+
from .text_to_speech_stream_with_timestamps_response_normalized_alignment import (
10+
TextToSpeechStreamWithTimestampsResponseNormalizedAlignment,
11+
)
12+
from ...core.pydantic_utilities import IS_PYDANTIC_V2
13+
14+
15+
class TextToSpeechStreamWithTimestampsResponse(UncheckedBaseModel):
16+
audio_base_64: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="audio_base64")] = (
17+
pydantic.Field(default=None)
18+
)
19+
"""
20+
Base64 encoded audio chunk
21+
"""
22+
23+
alignment: typing.Optional[TextToSpeechStreamWithTimestampsResponseAlignment] = None
24+
normalized_alignment: typing.Optional[TextToSpeechStreamWithTimestampsResponseNormalizedAlignment] = None
25+
26+
if IS_PYDANTIC_V2:
27+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2
28+
else:
29+
30+
class Config:
31+
frozen = True
32+
smart_union = True
33+
extra = pydantic.Extra.allow

0 commit comments

Comments
 (0)