# 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.get_audio_isolation_history_response_model import GetAudioIsolationHistoryResponseModel from .raw_client import AsyncRawAudioIsolationClient, RawAudioIsolationClient from .types.audio_isolation_request_file_format import AudioIsolationRequestFileFormat from .types.audio_isolation_stream_request_file_format import AudioIsolationStreamRequestFileFormat # this is used as the default value for optional parameters OMIT = typing.cast(typing.Any, ...) class AudioIsolationClient: def __init__(self, *, client_wrapper: SyncClientWrapper): self._raw_client = RawAudioIsolationClient(client_wrapper=client_wrapper) @property def with_raw_response(self) -> RawAudioIsolationClient: """ Retrieves a raw implementation of this client that returns raw responses. Returns ------- RawAudioIsolationClient """ return self._raw_client def convert( self, *, audio: core.File, file_format: typing.Optional[AudioIsolationRequestFileFormat] = OMIT, preview_b_64: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> typing.Iterator[bytes]: """ Removes background noise from audio. Parameters ---------- audio : core.File See core.File for more documentation file_format : typing.Optional[AudioIsolationRequestFileFormat] The format of input audio. Options are 'pcm_s16le_16' or 'other' For `pcm_s16le_16`, the input audio must be 16-bit PCM at a 16kHz sample rate, single channel (mono), and little-endian byte order. Latency will be lower than with passing an encoded waveform. preview_b_64 : typing.Optional[str] Optional preview image base64 for tracking this 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] Successful Response """ with self._raw_client.convert( audio=audio, file_format=file_format, preview_b_64=preview_b_64, request_options=request_options ) as r: yield from r.data def list( self, *, page_size: typing.Optional[int] = None, page: typing.Optional[int] = None, search: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None, ) -> GetAudioIsolationHistoryResponseModel: """ Returns a list of all your audio isolation generations. Parameters ---------- page_size : typing.Optional[int] How many history items to return at maximum. Defaults to 100. page : typing.Optional[int] Page number for search pagination (1-based). Only used when search is provided. search : typing.Optional[str] Optional search term used for filtering audio isolation history (title/text). request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- GetAudioIsolationHistoryResponseModel Successful Response Examples -------- from elevenlabs import ElevenLabs client = ElevenLabs( api_key="YOUR_API_KEY", ) client.audio_isolation.list( page_size=1, page=1, search="search", ) """ _response = self._raw_client.list( page_size=page_size, page=page, search=search, request_options=request_options ) return _response.data def delete(self, history_item_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None: """ Deletes a specific audio isolation history item and the associated media files. Parameters ---------- history_item_id : str Identifier of the audio isolation history item. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- None Examples -------- from elevenlabs import ElevenLabs client = ElevenLabs( api_key="YOUR_API_KEY", ) client.audio_isolation.delete( history_item_id="history_item_id", ) """ _response = self._raw_client.delete(history_item_id, request_options=request_options) return _response.data def stream( self, *, audio: core.File, file_format: typing.Optional[AudioIsolationStreamRequestFileFormat] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> typing.Iterator[bytes]: """ Removes background noise from audio. Parameters ---------- audio : core.File See core.File for more documentation file_format : typing.Optional[AudioIsolationStreamRequestFileFormat] The format of input audio. Options are 'pcm_s16le_16' or 'other' For `pcm_s16le_16`, the input audio must be 16-bit PCM at a 16kHz sample rate, single channel (mono), and little-endian byte order. Latency will be lower than with passing an encoded waveform. 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 Response """ with self._raw_client.stream(audio=audio, file_format=file_format, request_options=request_options) as r: yield from r.data class AsyncAudioIsolationClient: def __init__(self, *, client_wrapper: AsyncClientWrapper): self._raw_client = AsyncRawAudioIsolationClient(client_wrapper=client_wrapper) @property def with_raw_response(self) -> AsyncRawAudioIsolationClient: """ Retrieves a raw implementation of this client that returns raw responses. Returns ------- AsyncRawAudioIsolationClient """ return self._raw_client async def convert( self, *, audio: core.File, file_format: typing.Optional[AudioIsolationRequestFileFormat] = OMIT, preview_b_64: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> typing.AsyncIterator[bytes]: """ Removes background noise from audio. Parameters ---------- audio : core.File See core.File for more documentation file_format : typing.Optional[AudioIsolationRequestFileFormat] The format of input audio. Options are 'pcm_s16le_16' or 'other' For `pcm_s16le_16`, the input audio must be 16-bit PCM at a 16kHz sample rate, single channel (mono), and little-endian byte order. Latency will be lower than with passing an encoded waveform. preview_b_64 : typing.Optional[str] Optional preview image base64 for tracking this 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] Successful Response """ async with self._raw_client.convert( audio=audio, file_format=file_format, preview_b_64=preview_b_64, request_options=request_options ) as r: async for _chunk in r.data: yield _chunk async def list( self, *, page_size: typing.Optional[int] = None, page: typing.Optional[int] = None, search: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None, ) -> GetAudioIsolationHistoryResponseModel: """ Returns a list of all your audio isolation generations. Parameters ---------- page_size : typing.Optional[int] How many history items to return at maximum. Defaults to 100. page : typing.Optional[int] Page number for search pagination (1-based). Only used when search is provided. search : typing.Optional[str] Optional search term used for filtering audio isolation history (title/text). request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- GetAudioIsolationHistoryResponseModel Successful Response Examples -------- import asyncio from elevenlabs import AsyncElevenLabs client = AsyncElevenLabs( api_key="YOUR_API_KEY", ) async def main() -> None: await client.audio_isolation.list( page_size=1, page=1, search="search", ) asyncio.run(main()) """ _response = await self._raw_client.list( page_size=page_size, page=page, search=search, request_options=request_options ) return _response.data async def delete(self, history_item_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None: """ Deletes a specific audio isolation history item and the associated media files. Parameters ---------- history_item_id : str Identifier of the audio isolation history item. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- None Examples -------- import asyncio from elevenlabs import AsyncElevenLabs client = AsyncElevenLabs( api_key="YOUR_API_KEY", ) async def main() -> None: await client.audio_isolation.delete( history_item_id="history_item_id", ) asyncio.run(main()) """ _response = await self._raw_client.delete(history_item_id, request_options=request_options) return _response.data async def stream( self, *, audio: core.File, file_format: typing.Optional[AudioIsolationStreamRequestFileFormat] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> typing.AsyncIterator[bytes]: """ Removes background noise from audio. Parameters ---------- audio : core.File See core.File for more documentation file_format : typing.Optional[AudioIsolationStreamRequestFileFormat] The format of input audio. Options are 'pcm_s16le_16' or 'other' For `pcm_s16le_16`, the input audio must be 16-bit PCM at a 16kHz sample rate, single channel (mono), and little-endian byte order. Latency will be lower than with passing an encoded waveform. 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 Response """ async with self._raw_client.stream(audio=audio, file_format=file_format, request_options=request_options) as r: async for _chunk in r.data: yield _chunk