# 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 .raw_client import AsyncRawLightningClient, RawLightningClient
from .types.lightning_request_language import LightningRequestLanguage
from .types.lightning_request_output_format import LightningRequestOutputFormat
from ..types.sample_rate import SampleRate

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class LightningClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawLightningClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawLightningClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawLightningClient
        """
        return self._raw_client

    def synthesize_lightning_speech(
        self,
        *,
        text: str,
        voice_id: str,
        sample_rate: typing.Optional[SampleRate] = OMIT,
        speed: typing.Optional[float] = OMIT,
        language: typing.Optional[LightningRequestLanguage] = OMIT,
        output_format: typing.Optional[LightningRequestOutputFormat] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Iterator[bytes]:
        """
        Get speech for given text using the Waves API

        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[LightningRequestLanguage]
            Determines how numbers are spelled out. If set to 'en', numbers will be read as individual digits in English. If set to 'hi', numbers will be read as individual digits in Hindi.

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

        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.lightning.synthesize_lightning_speech(
            text="text",
            voice_id="voice_id",
        )
        """
        with self._raw_client.synthesize_lightning_speech(
            text=text,
            voice_id=voice_id,
            sample_rate=sample_rate,
            speed=speed,
            language=language,
            output_format=output_format,
            request_options=request_options,
        ) as r:
            yield from r.data


class AsyncLightningClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawLightningClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawLightningClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawLightningClient
        """
        return self._raw_client

    async def synthesize_lightning_speech(
        self,
        *,
        text: str,
        voice_id: str,
        sample_rate: typing.Optional[SampleRate] = OMIT,
        speed: typing.Optional[float] = OMIT,
        language: typing.Optional[LightningRequestLanguage] = OMIT,
        output_format: typing.Optional[LightningRequestOutputFormat] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.AsyncIterator[bytes]:
        """
        Get speech for given text using the Waves API

        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[LightningRequestLanguage]
            Determines how numbers are spelled out. If set to 'en', numbers will be read as individual digits in English. If set to 'hi', numbers will be read as individual digits in Hindi.

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

        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.lightning.synthesize_lightning_speech(
                text="text",
                voice_id="voice_id",
            )


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