# 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.lightning_v31request_language import LightningV31RequestLanguage
from ..types.lightning_v31request_output_format import LightningV31RequestOutputFormat
from ..types.sample_rate import SampleRate
from .raw_client import AsyncRawTextToSpeechClient, RawTextToSpeechClient

# 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 synthesize_lightning_v31speech(
        self,
        *,
        text: str,
        voice_id: str,
        sample_rate: typing.Optional[SampleRate] = OMIT,
        speed: typing.Optional[float] = OMIT,
        language: typing.Optional[LightningV31RequestLanguage] = OMIT,
        output_format: typing.Optional[LightningV31RequestOutputFormat] = OMIT,
        pronunciation_dicts: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Iterator[bytes]:
        """
        Converts provided text to speech using the Lightning V3.1 model.

        Parameters
        ----------
        text : str
            The text to convert to speech.

        voice_id : str
            The voice identifier to use for speech generation.

        sample_rate : typing.Optional[SampleRate]
            The sample rate for the generated audio.

        speed : typing.Optional[float]
            The speed of the generated speech.

        language : typing.Optional[LightningV31RequestLanguage]
            Determines how numbers are spelled out. If set to 'en', numbers will be read in English. If set to 'hi', numbers will be read in Hindi.

        output_format : typing.Optional[LightningV31RequestOutputFormat]
            The format of the output audio.

        pronunciation_dicts : typing.Optional[typing.Sequence[str]]
            The IDs of the pronunciation dictionaries to use for speech generation.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Returns
        -------
        typing.Iterator[bytes]
            Synthesized speech retrieved successfully.

        Examples
        --------
        from smallestai import SmallestAI

        client = SmallestAI(
            token="YOUR_TOKEN",
        )
        client.waves.text_to_speech.synthesize_lightning_v31speech(
            text="text",
            voice_id="voice_id",
        )
        """
        with self._raw_client.synthesize_lightning_v31speech(
            text=text,
            voice_id=voice_id,
            sample_rate=sample_rate,
            speed=speed,
            language=language,
            output_format=output_format,
            pronunciation_dicts=pronunciation_dicts,
            request_options=request_options,
        ) as r:
            yield from r.data

    def stream_lightning_v31speech(
        self,
        *,
        text: str,
        voice_id: str,
        sample_rate: typing.Optional[SampleRate] = OMIT,
        speed: typing.Optional[float] = OMIT,
        language: typing.Optional[LightningV31RequestLanguage] = OMIT,
        output_format: typing.Optional[LightningV31RequestOutputFormat] = OMIT,
        pronunciation_dicts: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Iterator[typing.Any]:
        """
        Converts provided text to speech using the Lightning V3.1 model with streaming response.

        Parameters
        ----------
        text : str
            The text to convert to speech.

        voice_id : str
            The voice identifier to use for speech generation.

        sample_rate : typing.Optional[SampleRate]
            The sample rate for the generated audio.

        speed : typing.Optional[float]
            The speed of the generated speech.

        language : typing.Optional[LightningV31RequestLanguage]
            Determines how numbers are spelled out. If set to 'en', numbers will be read in English. If set to 'hi', numbers will be read in Hindi.

        output_format : typing.Optional[LightningV31RequestOutputFormat]
            The format of the output audio.

        pronunciation_dicts : typing.Optional[typing.Sequence[str]]
            The IDs of the pronunciation dictionaries to use for speech generation.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Yields
        ------
        typing.Iterator[typing.Any]
            Synthesized speech retrieved successfully.

        Examples
        --------
        from smallestai import SmallestAI

        client = SmallestAI(
            token="YOUR_TOKEN",
        )
        response = client.waves.text_to_speech.stream_lightning_v31speech(
            text="text",
            voice_id="voice_id",
        )
        for chunk in response:
            yield chunk
        """
        with self._raw_client.stream_lightning_v31speech(
            text=text,
            voice_id=voice_id,
            sample_rate=sample_rate,
            speed=speed,
            language=language,
            output_format=output_format,
            pronunciation_dicts=pronunciation_dicts,
            request_options=request_options,
        ) as r:
            yield from r.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 synthesize_lightning_v31speech(
        self,
        *,
        text: str,
        voice_id: str,
        sample_rate: typing.Optional[SampleRate] = OMIT,
        speed: typing.Optional[float] = OMIT,
        language: typing.Optional[LightningV31RequestLanguage] = OMIT,
        output_format: typing.Optional[LightningV31RequestOutputFormat] = OMIT,
        pronunciation_dicts: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.AsyncIterator[bytes]:
        """
        Converts provided text to speech using the Lightning V3.1 model.

        Parameters
        ----------
        text : str
            The text to convert to speech.

        voice_id : str
            The voice identifier to use for speech generation.

        sample_rate : typing.Optional[SampleRate]
            The sample rate for the generated audio.

        speed : typing.Optional[float]
            The speed of the generated speech.

        language : typing.Optional[LightningV31RequestLanguage]
            Determines how numbers are spelled out. If set to 'en', numbers will be read in English. If set to 'hi', numbers will be read in Hindi.

        output_format : typing.Optional[LightningV31RequestOutputFormat]
            The format of the output audio.

        pronunciation_dicts : typing.Optional[typing.Sequence[str]]
            The IDs of the pronunciation dictionaries to use for speech generation.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Returns
        -------
        typing.AsyncIterator[bytes]
            Synthesized speech retrieved successfully.

        Examples
        --------
        import asyncio

        from smallestai import AsyncSmallestAI

        client = AsyncSmallestAI(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.waves.text_to_speech.synthesize_lightning_v31speech(
                text="text",
                voice_id="voice_id",
            )


        asyncio.run(main())
        """
        async with self._raw_client.synthesize_lightning_v31speech(
            text=text,
            voice_id=voice_id,
            sample_rate=sample_rate,
            speed=speed,
            language=language,
            output_format=output_format,
            pronunciation_dicts=pronunciation_dicts,
            request_options=request_options,
        ) as r:
            async for _chunk in r.data:
                yield _chunk

    async def stream_lightning_v31speech(
        self,
        *,
        text: str,
        voice_id: str,
        sample_rate: typing.Optional[SampleRate] = OMIT,
        speed: typing.Optional[float] = OMIT,
        language: typing.Optional[LightningV31RequestLanguage] = OMIT,
        output_format: typing.Optional[LightningV31RequestOutputFormat] = OMIT,
        pronunciation_dicts: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.AsyncIterator[typing.Any]:
        """
        Converts provided text to speech using the Lightning V3.1 model with streaming response.

        Parameters
        ----------
        text : str
            The text to convert to speech.

        voice_id : str
            The voice identifier to use for speech generation.

        sample_rate : typing.Optional[SampleRate]
            The sample rate for the generated audio.

        speed : typing.Optional[float]
            The speed of the generated speech.

        language : typing.Optional[LightningV31RequestLanguage]
            Determines how numbers are spelled out. If set to 'en', numbers will be read in English. If set to 'hi', numbers will be read in Hindi.

        output_format : typing.Optional[LightningV31RequestOutputFormat]
            The format of the output audio.

        pronunciation_dicts : typing.Optional[typing.Sequence[str]]
            The IDs of the pronunciation dictionaries to use for speech generation.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Yields
        ------
        typing.AsyncIterator[typing.Any]
            Synthesized speech retrieved successfully.

        Examples
        --------
        import asyncio

        from smallestai import AsyncSmallestAI

        client = AsyncSmallestAI(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            response = await client.waves.text_to_speech.stream_lightning_v31speech(
                text="text",
                voice_id="voice_id",
            )
            async for chunk in response:
                yield chunk


        asyncio.run(main())
        """
        async with self._raw_client.stream_lightning_v31speech(
            text=text,
            voice_id=voice_id,
            sample_rate=sample_rate,
            speed=speed,
            language=language,
            output_format=output_format,
            pronunciation_dicts=pronunciation_dicts,
            request_options=request_options,
        ) as r:
            async for _chunk in r.data:
                yield _chunk
