# This file was auto-generated by Fern from our API Definition.

import typing

from .. import core
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.audio_model_info import AudioModelInfo
from ..types.diarize_response import DiarizeResponse
from ..types.emotion_detection_response import EmotionDetectionResponse
from ..types.speaker_identify_response import SpeakerIdentifyResponse
from ..types.topic_segment_response import TopicSegmentResponse
from ..types.transcribe_response import TranscribeResponse
from ..types.utterance import Utterance
from .raw_client import AsyncRawAudioServicesClient, RawAudioServicesClient

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


class AudioServicesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawAudioServicesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawAudioServicesClient
        """
        return self._raw_client

    def transcribe(
        self,
        *,
        audio_file: core.File,
        language: typing.Optional[str] = OMIT,
        word_timestamps: typing.Optional[bool] = OMIT,
        model: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TranscribeResponse:
        """
        Transcribe an audio file to text with timestamps.

        Parameters
        ----------
        audio_file : core.File
            See core.File for more documentation

        language : typing.Optional[str]
            Language code (e.g., en, de, fr). Auto-detected if omitted.

        word_timestamps : typing.Optional[bool]
            Include word-level timestamps in the response

        model : typing.Optional[str]
            Model key override. Uses platform default if omitted.

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

        Returns
        -------
        TranscribeResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.audio_services.transcribe()
        """
        _response = self._raw_client.transcribe(
            audio_file=audio_file,
            language=language,
            word_timestamps=word_timestamps,
            model=model,
            request_options=request_options,
        )
        return _response.data

    def diarize(
        self,
        *,
        audio_file: core.File,
        num_speakers: typing.Optional[int] = OMIT,
        model: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DiarizeResponse:
        """
        Segment audio by speaker identity.

        Parameters
        ----------
        audio_file : core.File
            See core.File for more documentation

        num_speakers : typing.Optional[int]
            Expected number of speakers (helps accuracy). Auto-detected if omitted.

        model : typing.Optional[str]
            Model key override. Uses platform default if omitted.

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

        Returns
        -------
        DiarizeResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.audio_services.diarize()
        """
        _response = self._raw_client.diarize(
            audio_file=audio_file, num_speakers=num_speakers, model=model, request_options=request_options
        )
        return _response.data

    def detect_emotion(
        self,
        *,
        audio_file: core.File,
        model: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EmotionDetectionResponse:
        """
        Detect the dominant emotion in a speech audio clip.

        Parameters
        ----------
        audio_file : core.File
            See core.File for more documentation

        model : typing.Optional[str]
            Model key override. Uses platform default if omitted.

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

        Returns
        -------
        EmotionDetectionResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.audio_services.detect_emotion()
        """
        _response = self._raw_client.detect_emotion(audio_file=audio_file, model=model, request_options=request_options)
        return _response.data

    def identify_speaker(
        self,
        *,
        audio_file: core.File,
        known_embeddings_json: typing.Optional[str] = OMIT,
        model: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SpeakerIdentifyResponse:
        """
        Identify a speaker by comparing against known voice embeddings, or extract a new embedding.

        Parameters
        ----------
        audio_file : core.File
            See core.File for more documentation

        known_embeddings_json : typing.Optional[str]
            JSON object mapping speaker names to embedding vectors, e.g. {"Alice": [0.1, ...]}. Omit to extract embedding only.

        model : typing.Optional[str]
            Model key override. Uses platform default if omitted.

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

        Returns
        -------
        SpeakerIdentifyResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.audio_services.identify_speaker()
        """
        _response = self._raw_client.identify_speaker(
            audio_file=audio_file,
            known_embeddings_json=known_embeddings_json,
            model=model,
            request_options=request_options,
        )
        return _response.data

    def synthesize(
        self,
        *,
        text: str,
        voice: typing.Optional[str] = OMIT,
        temperature: typing.Optional[float] = OMIT,
        repetition_penalty: typing.Optional[float] = OMIT,
        output_format: typing.Optional[str] = OMIT,
        model: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Convert text to speech audio.

        Parameters
        ----------
        text : str
            Text to synthesize. Supports emotion tags: <laugh>, <chuckle>, <sigh>, <cough>, <sniffle>, <groan>, <yawn>, <gasp>.

        voice : typing.Optional[str]
            Voice preset (tara, leah, jess, leo, dan, mia, zac, zoe)

        temperature : typing.Optional[float]
            Sampling temperature. Lower = more deterministic.

        repetition_penalty : typing.Optional[float]
            Repetition penalty factor

        output_format : typing.Optional[str]
            Audio output format (wav or mp3)

        model : typing.Optional[str]
            Model key override. Uses platform default if omitted.

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

        Returns
        -------
        typing.Any
            Audio file in the requested format

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.audio_services.synthesize(
            text="text",
        )
        """
        _response = self._raw_client.synthesize(
            text=text,
            voice=voice,
            temperature=temperature,
            repetition_penalty=repetition_penalty,
            output_format=output_format,
            model=model,
            request_options=request_options,
        )
        return _response.data

    def synthesize_stream(
        self,
        *,
        text: str,
        voice: typing.Optional[str] = OMIT,
        temperature: typing.Optional[float] = OMIT,
        repetition_penalty: typing.Optional[float] = OMIT,
        output_format: typing.Optional[str] = OMIT,
        model: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Convert text to speech audio with streaming output.

        Parameters
        ----------
        text : str
            Text to synthesize. Supports emotion tags: <laugh>, <chuckle>, <sigh>, <cough>, <sniffle>, <groan>, <yawn>, <gasp>.

        voice : typing.Optional[str]
            Voice preset (tara, leah, jess, leo, dan, mia, zac, zoe)

        temperature : typing.Optional[float]
            Sampling temperature. Lower = more deterministic.

        repetition_penalty : typing.Optional[float]
            Repetition penalty factor

        output_format : typing.Optional[str]
            Audio output format (wav or mp3)

        model : typing.Optional[str]
            Model key override. Uses platform default if omitted.

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

        Returns
        -------
        typing.Any
            Streaming audio in the requested format

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.audio_services.synthesize_stream(
            text="text",
        )
        """
        _response = self._raw_client.synthesize_stream(
            text=text,
            voice=voice,
            temperature=temperature,
            repetition_penalty=repetition_penalty,
            output_format=output_format,
            model=model,
            request_options=request_options,
        )
        return _response.data

    def segment_topics(
        self,
        *,
        utterances: typing.Sequence[Utterance],
        model: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TopicSegmentResponse:
        """
        Segment transcript utterances into coherent topics.

        Parameters
        ----------
        utterances : typing.Sequence[Utterance]
            List of utterances to segment into topics

        model : typing.Optional[str]
            Model key override. Uses platform default if omitted.

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

        Returns
        -------
        TopicSegmentResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos, Utterance

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.audio_services.segment_topics(
            utterances=[
                Utterance(
                    text="text",
                    start_ms=1,
                    end_ms=1,
                )
            ],
        )
        """
        _response = self._raw_client.segment_topics(utterances=utterances, model=model, request_options=request_options)
        return _response.data

    def list_audio_models(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[AudioModelInfo]:
        """
        List all available audio processing models and their categories.

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

        Returns
        -------
        typing.List[AudioModelInfo]
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.audio_services.list_audio_models()
        """
        _response = self._raw_client.list_audio_models(request_options=request_options)
        return _response.data


class AsyncAudioServicesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawAudioServicesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawAudioServicesClient
        """
        return self._raw_client

    async def transcribe(
        self,
        *,
        audio_file: core.File,
        language: typing.Optional[str] = OMIT,
        word_timestamps: typing.Optional[bool] = OMIT,
        model: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TranscribeResponse:
        """
        Transcribe an audio file to text with timestamps.

        Parameters
        ----------
        audio_file : core.File
            See core.File for more documentation

        language : typing.Optional[str]
            Language code (e.g., en, de, fr). Auto-detected if omitted.

        word_timestamps : typing.Optional[bool]
            Include word-level timestamps in the response

        model : typing.Optional[str]
            Model key override. Uses platform default if omitted.

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

        Returns
        -------
        TranscribeResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.audio_services.transcribe()


        asyncio.run(main())
        """
        _response = await self._raw_client.transcribe(
            audio_file=audio_file,
            language=language,
            word_timestamps=word_timestamps,
            model=model,
            request_options=request_options,
        )
        return _response.data

    async def diarize(
        self,
        *,
        audio_file: core.File,
        num_speakers: typing.Optional[int] = OMIT,
        model: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DiarizeResponse:
        """
        Segment audio by speaker identity.

        Parameters
        ----------
        audio_file : core.File
            See core.File for more documentation

        num_speakers : typing.Optional[int]
            Expected number of speakers (helps accuracy). Auto-detected if omitted.

        model : typing.Optional[str]
            Model key override. Uses platform default if omitted.

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

        Returns
        -------
        DiarizeResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.audio_services.diarize()


        asyncio.run(main())
        """
        _response = await self._raw_client.diarize(
            audio_file=audio_file, num_speakers=num_speakers, model=model, request_options=request_options
        )
        return _response.data

    async def detect_emotion(
        self,
        *,
        audio_file: core.File,
        model: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EmotionDetectionResponse:
        """
        Detect the dominant emotion in a speech audio clip.

        Parameters
        ----------
        audio_file : core.File
            See core.File for more documentation

        model : typing.Optional[str]
            Model key override. Uses platform default if omitted.

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

        Returns
        -------
        EmotionDetectionResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.audio_services.detect_emotion()


        asyncio.run(main())
        """
        _response = await self._raw_client.detect_emotion(
            audio_file=audio_file, model=model, request_options=request_options
        )
        return _response.data

    async def identify_speaker(
        self,
        *,
        audio_file: core.File,
        known_embeddings_json: typing.Optional[str] = OMIT,
        model: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SpeakerIdentifyResponse:
        """
        Identify a speaker by comparing against known voice embeddings, or extract a new embedding.

        Parameters
        ----------
        audio_file : core.File
            See core.File for more documentation

        known_embeddings_json : typing.Optional[str]
            JSON object mapping speaker names to embedding vectors, e.g. {"Alice": [0.1, ...]}. Omit to extract embedding only.

        model : typing.Optional[str]
            Model key override. Uses platform default if omitted.

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

        Returns
        -------
        SpeakerIdentifyResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.audio_services.identify_speaker()


        asyncio.run(main())
        """
        _response = await self._raw_client.identify_speaker(
            audio_file=audio_file,
            known_embeddings_json=known_embeddings_json,
            model=model,
            request_options=request_options,
        )
        return _response.data

    async def synthesize(
        self,
        *,
        text: str,
        voice: typing.Optional[str] = OMIT,
        temperature: typing.Optional[float] = OMIT,
        repetition_penalty: typing.Optional[float] = OMIT,
        output_format: typing.Optional[str] = OMIT,
        model: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Convert text to speech audio.

        Parameters
        ----------
        text : str
            Text to synthesize. Supports emotion tags: <laugh>, <chuckle>, <sigh>, <cough>, <sniffle>, <groan>, <yawn>, <gasp>.

        voice : typing.Optional[str]
            Voice preset (tara, leah, jess, leo, dan, mia, zac, zoe)

        temperature : typing.Optional[float]
            Sampling temperature. Lower = more deterministic.

        repetition_penalty : typing.Optional[float]
            Repetition penalty factor

        output_format : typing.Optional[str]
            Audio output format (wav or mp3)

        model : typing.Optional[str]
            Model key override. Uses platform default if omitted.

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

        Returns
        -------
        typing.Any
            Audio file in the requested format

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.audio_services.synthesize(
                text="text",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.synthesize(
            text=text,
            voice=voice,
            temperature=temperature,
            repetition_penalty=repetition_penalty,
            output_format=output_format,
            model=model,
            request_options=request_options,
        )
        return _response.data

    async def synthesize_stream(
        self,
        *,
        text: str,
        voice: typing.Optional[str] = OMIT,
        temperature: typing.Optional[float] = OMIT,
        repetition_penalty: typing.Optional[float] = OMIT,
        output_format: typing.Optional[str] = OMIT,
        model: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Convert text to speech audio with streaming output.

        Parameters
        ----------
        text : str
            Text to synthesize. Supports emotion tags: <laugh>, <chuckle>, <sigh>, <cough>, <sniffle>, <groan>, <yawn>, <gasp>.

        voice : typing.Optional[str]
            Voice preset (tara, leah, jess, leo, dan, mia, zac, zoe)

        temperature : typing.Optional[float]
            Sampling temperature. Lower = more deterministic.

        repetition_penalty : typing.Optional[float]
            Repetition penalty factor

        output_format : typing.Optional[str]
            Audio output format (wav or mp3)

        model : typing.Optional[str]
            Model key override. Uses platform default if omitted.

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

        Returns
        -------
        typing.Any
            Streaming audio in the requested format

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.audio_services.synthesize_stream(
                text="text",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.synthesize_stream(
            text=text,
            voice=voice,
            temperature=temperature,
            repetition_penalty=repetition_penalty,
            output_format=output_format,
            model=model,
            request_options=request_options,
        )
        return _response.data

    async def segment_topics(
        self,
        *,
        utterances: typing.Sequence[Utterance],
        model: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TopicSegmentResponse:
        """
        Segment transcript utterances into coherent topics.

        Parameters
        ----------
        utterances : typing.Sequence[Utterance]
            List of utterances to segment into topics

        model : typing.Optional[str]
            Model key override. Uses platform default if omitted.

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

        Returns
        -------
        TopicSegmentResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos, Utterance

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.audio_services.segment_topics(
                utterances=[
                    Utterance(
                        text="text",
                        start_ms=1,
                        end_ms=1,
                    )
                ],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.segment_topics(
            utterances=utterances, model=model, request_options=request_options
        )
        return _response.data

    async def list_audio_models(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[AudioModelInfo]:
        """
        List all available audio processing models and their categories.

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

        Returns
        -------
        typing.List[AudioModelInfo]
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.audio_services.list_audio_models()


        asyncio.run(main())
        """
        _response = await self._raw_client.list_audio_models(request_options=request_options)
        return _response.data
