# This file was auto-generated by Fern from our API Definition. import typing from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.request_options import RequestOptions from ...types.media_generation_create_response import MediaGenerationCreateResponse from ...types.media_generation_list_response import MediaGenerationListResponse from ...types.media_generation_response import MediaGenerationResponse from ...types.text_to_speech_generation_request import TextToSpeechGenerationRequest from .raw_client import AsyncRawTextToSpeechClient, RawTextToSpeechClient from .types.text_to_speech_list_request_status import TextToSpeechListRequestStatus # this is used as the default value for optional parameters OMIT = typing.cast(typing.Any, ...) class TextToSpeechClient: def __init__(self, *, client_wrapper: SyncClientWrapper): self._raw_client = RawTextToSpeechClient(client_wrapper=client_wrapper) @property def with_raw_response(self) -> RawTextToSpeechClient: """ Retrieves a raw implementation of this client that returns raw responses. Returns ------- RawTextToSpeechClient """ return self._raw_client def list( self, *, cursor: typing.Optional[str] = None, page_size: typing.Optional[int] = None, status: typing.Optional[TextToSpeechListRequestStatus] = None, model_id: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None, ) -> MediaGenerationListResponse: """ List the speech generations created through this API, newest first. Parameters ---------- cursor : typing.Optional[str] Pagination cursor: the `next_cursor` value of the previous page's response. Omit it for the first page. page_size : typing.Optional[int] How many generations to return per page. status : typing.Optional[TextToSpeechListRequestStatus] Only return generations with this lifecycle status. model_id : typing.Optional[str] Only return generations of this model. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- MediaGenerationListResponse Successful Response Examples -------- from elevenlabs import ElevenLabs client = ElevenLabs( api_key="YOUR_API_KEY", ) client.flows.text_to_speech.list( cursor="cursor", page_size=1, status="pending", model_id="model_id", ) """ _response = self._raw_client.list( cursor=cursor, page_size=page_size, status=status, model_id=model_id, request_options=request_options ) return _response.data def create( self, *, request: TextToSpeechGenerationRequest, request_options: typing.Optional[RequestOptions] = None ) -> MediaGenerationCreateResponse: """ Start a speech generation with the selected model. Charged per character via text-to-speech billing. Use this over `/v1/text-to-speech` for the asynchronous generation lifecycle or for models not offered there; for direct, synchronous speech synthesis, prefer `/v1/text-to-speech`. Parameters ---------- request : TextToSpeechGenerationRequest request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- MediaGenerationCreateResponse Successful Response Examples -------- from elevenlabs import ElevenLabs, TextToSpeechGenerationRequest_ElevenFlashV25 client = ElevenLabs( api_key="YOUR_API_KEY", ) client.flows.text_to_speech.create( request=TextToSpeechGenerationRequest_ElevenFlashV25( text="The first move is what sets everything in motion.", voice="JBFqnCBsd6RMkjVDRZzb", ), ) """ _response = self._raw_client.create(request=request, request_options=request_options) return _response.data def get( self, generation_id: str, *, request_options: typing.Optional[RequestOptions] = None ) -> MediaGenerationResponse: """ Retrieve the status of a speech generation, and retrieve its output URL once completed. Parameters ---------- generation_id : str request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- MediaGenerationResponse Successful Response Examples -------- from elevenlabs import ElevenLabs client = ElevenLabs( api_key="YOUR_API_KEY", ) client.flows.text_to_speech.get( generation_id="generation_id", ) """ _response = self._raw_client.get(generation_id, request_options=request_options) return _response.data class AsyncTextToSpeechClient: def __init__(self, *, client_wrapper: AsyncClientWrapper): self._raw_client = AsyncRawTextToSpeechClient(client_wrapper=client_wrapper) @property def with_raw_response(self) -> AsyncRawTextToSpeechClient: """ Retrieves a raw implementation of this client that returns raw responses. Returns ------- AsyncRawTextToSpeechClient """ return self._raw_client async def list( self, *, cursor: typing.Optional[str] = None, page_size: typing.Optional[int] = None, status: typing.Optional[TextToSpeechListRequestStatus] = None, model_id: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None, ) -> MediaGenerationListResponse: """ List the speech generations created through this API, newest first. Parameters ---------- cursor : typing.Optional[str] Pagination cursor: the `next_cursor` value of the previous page's response. Omit it for the first page. page_size : typing.Optional[int] How many generations to return per page. status : typing.Optional[TextToSpeechListRequestStatus] Only return generations with this lifecycle status. model_id : typing.Optional[str] Only return generations of this model. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- MediaGenerationListResponse Successful Response Examples -------- import asyncio from elevenlabs import AsyncElevenLabs client = AsyncElevenLabs( api_key="YOUR_API_KEY", ) async def main() -> None: await client.flows.text_to_speech.list( cursor="cursor", page_size=1, status="pending", model_id="model_id", ) asyncio.run(main()) """ _response = await self._raw_client.list( cursor=cursor, page_size=page_size, status=status, model_id=model_id, request_options=request_options ) return _response.data async def create( self, *, request: TextToSpeechGenerationRequest, request_options: typing.Optional[RequestOptions] = None ) -> MediaGenerationCreateResponse: """ Start a speech generation with the selected model. Charged per character via text-to-speech billing. Use this over `/v1/text-to-speech` for the asynchronous generation lifecycle or for models not offered there; for direct, synchronous speech synthesis, prefer `/v1/text-to-speech`. Parameters ---------- request : TextToSpeechGenerationRequest request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- MediaGenerationCreateResponse Successful Response Examples -------- import asyncio from elevenlabs import ( AsyncElevenLabs, TextToSpeechGenerationRequest_ElevenFlashV25, ) client = AsyncElevenLabs( api_key="YOUR_API_KEY", ) async def main() -> None: await client.flows.text_to_speech.create( request=TextToSpeechGenerationRequest_ElevenFlashV25( text="The first move is what sets everything in motion.", voice="JBFqnCBsd6RMkjVDRZzb", ), ) asyncio.run(main()) """ _response = await self._raw_client.create(request=request, request_options=request_options) return _response.data async def get( self, generation_id: str, *, request_options: typing.Optional[RequestOptions] = None ) -> MediaGenerationResponse: """ Retrieve the status of a speech generation, and retrieve its output URL once completed. Parameters ---------- generation_id : str request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- MediaGenerationResponse Successful Response Examples -------- import asyncio from elevenlabs import AsyncElevenLabs client = AsyncElevenLabs( api_key="YOUR_API_KEY", ) async def main() -> None: await client.flows.text_to_speech.get( generation_id="generation_id", ) asyncio.run(main()) """ _response = await self._raw_client.get(generation_id, request_options=request_options) return _response.data