# 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 AsyncRawAudioClient, RawAudioClient
from .types.audio_generate_request_callback_method import AudioGenerateRequestCallbackMethod
from .types.audio_generate_request_container import AudioGenerateRequestContainer
from .types.audio_generate_request_encoding import AudioGenerateRequestEncoding
from .types.audio_generate_request_model import AudioGenerateRequestModel

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


class AudioClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawAudioClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawAudioClient
        """
        return self._raw_client

    def generate(
        self,
        *,
        text: str,
        callback: typing.Optional[str] = None,
        callback_method: typing.Optional[AudioGenerateRequestCallbackMethod] = None,
        mip_opt_out: typing.Optional[bool] = None,
        tag: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        bit_rate: typing.Optional[float] = None,
        container: typing.Optional[AudioGenerateRequestContainer] = None,
        encoding: typing.Optional[AudioGenerateRequestEncoding] = None,
        model: typing.Optional[AudioGenerateRequestModel] = None,
        sample_rate: typing.Optional[float] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Iterator[bytes]:
        """
        Convert text into natural-sounding speech using Deepgram's TTS REST API

        Parameters
        ----------
        text : str
            The text content to be converted to speech

        callback : typing.Optional[str]
            URL to which we'll make the callback request

        callback_method : typing.Optional[AudioGenerateRequestCallbackMethod]
            HTTP method by which the callback request will be made

        mip_opt_out : typing.Optional[bool]
            Opts out requests from the Deepgram Model Improvement Program. Refer to our Docs for pricing impacts before setting this to true. https://dpgr.am/deepgram-mip

        tag : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Label your requests for the purpose of identification during usage reporting

        bit_rate : typing.Optional[float]
            The bitrate of the audio in bits per second. Choose from predefined ranges or specific values based on the encoding type.

        container : typing.Optional[AudioGenerateRequestContainer]
            Container specifies the file format wrapper for the output audio. The available options depend on the encoding type.

        encoding : typing.Optional[AudioGenerateRequestEncoding]
            Encoding allows you to specify the expected encoding of your audio output

        model : typing.Optional[AudioGenerateRequestModel]
            AI model used to process submitted text

        sample_rate : typing.Optional[float]
            Sample Rate specifies the sample rate for the output audio. Based on the encoding, different sample rates are supported. For some encodings, the sample rate is not configurable

        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]
            Successful text-to-speech transformation

        Examples
        --------
        from deepgram import DeepgramClient

        client = DeepgramClient(
            api_key="YOUR_API_KEY",
        )
        client.speak.v1.audio.generate(
            text="text",
        )
        """
        with self._raw_client.generate(
            text=text,
            callback=callback,
            callback_method=callback_method,
            mip_opt_out=mip_opt_out,
            tag=tag,
            bit_rate=bit_rate,
            container=container,
            encoding=encoding,
            model=model,
            sample_rate=sample_rate,
            request_options=request_options,
        ) as r:
            yield from r.data


class AsyncAudioClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawAudioClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawAudioClient
        """
        return self._raw_client

    async def generate(
        self,
        *,
        text: str,
        callback: typing.Optional[str] = None,
        callback_method: typing.Optional[AudioGenerateRequestCallbackMethod] = None,
        mip_opt_out: typing.Optional[bool] = None,
        tag: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        bit_rate: typing.Optional[float] = None,
        container: typing.Optional[AudioGenerateRequestContainer] = None,
        encoding: typing.Optional[AudioGenerateRequestEncoding] = None,
        model: typing.Optional[AudioGenerateRequestModel] = None,
        sample_rate: typing.Optional[float] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.AsyncIterator[bytes]:
        """
        Convert text into natural-sounding speech using Deepgram's TTS REST API

        Parameters
        ----------
        text : str
            The text content to be converted to speech

        callback : typing.Optional[str]
            URL to which we'll make the callback request

        callback_method : typing.Optional[AudioGenerateRequestCallbackMethod]
            HTTP method by which the callback request will be made

        mip_opt_out : typing.Optional[bool]
            Opts out requests from the Deepgram Model Improvement Program. Refer to our Docs for pricing impacts before setting this to true. https://dpgr.am/deepgram-mip

        tag : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Label your requests for the purpose of identification during usage reporting

        bit_rate : typing.Optional[float]
            The bitrate of the audio in bits per second. Choose from predefined ranges or specific values based on the encoding type.

        container : typing.Optional[AudioGenerateRequestContainer]
            Container specifies the file format wrapper for the output audio. The available options depend on the encoding type.

        encoding : typing.Optional[AudioGenerateRequestEncoding]
            Encoding allows you to specify the expected encoding of your audio output

        model : typing.Optional[AudioGenerateRequestModel]
            AI model used to process submitted text

        sample_rate : typing.Optional[float]
            Sample Rate specifies the sample rate for the output audio. Based on the encoding, different sample rates are supported. For some encodings, the sample rate is not configurable

        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]
            Successful text-to-speech transformation

        Examples
        --------
        import asyncio

        from deepgram import AsyncDeepgramClient

        client = AsyncDeepgramClient(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.speak.v1.audio.generate(
                text="text",
            )


        asyncio.run(main())
        """
        async with self._raw_client.generate(
            text=text,
            callback=callback,
            callback_method=callback_method,
            mip_opt_out=mip_opt_out,
            tag=tag,
            bit_rate=bit_rate,
            container=container,
            encoding=encoding,
            model=model,
            sample_rate=sample_rate,
            request_options=request_options,
        ) as r:
            async for _chunk in r.data:
                yield _chunk
