From 2862f0b0d8db530a513dda6930fafffecc15d420 Mon Sep 17 00:00:00 2001 From: David vonThenen <12752197+dvonthenen@users.noreply.github.com> Date: Tue, 9 Jul 2024 12:39:47 -0700 Subject: [PATCH] Missing Exported Class Names --- deepgram/__init__.py | 16 ++++-- deepgram/client.py | 17 +++++-- deepgram/clients/__init__.py | 21 +++++--- deepgram/clients/listen/__init__.py | 5 ++ deepgram/clients/listen/client.py | 16 +++++- deepgram/clients/listen/v1/__init__.py | 5 +- deepgram/clients/listen/v1/rest/__init__.py | 2 + .../clients/listen/v1/rest/async_client.py | 49 ++++++++++--------- deepgram/clients/listen/v1/rest/client.py | 49 ++++++++++--------- deepgram/clients/listen/v1/rest/options.py | 3 ++ .../clients/listen/v1/websocket/__init__.py | 2 +- .../listen/v1/websocket/async_client.py | 10 ++-- .../clients/listen/v1/websocket/client.py | 10 ++-- .../clients/listen/v1/websocket/options.py | 3 ++ deepgram/clients/speak/__init__.py | 4 +- deepgram/clients/speak/client.py | 8 ++- deepgram/clients/speak/v1/__init__.py | 13 ++++- deepgram/clients/speak/v1/options.py | 6 ++- deepgram/clients/speak/v1/rest/__init__.py | 6 +++ .../clients/speak/v1/rest/async_client.py | 18 +++---- deepgram/clients/speak/v1/rest/client.py | 18 +++---- deepgram/clients/speak/v1/rest/helpers.py | 2 +- deepgram/clients/speak/v1/rest/options.py | 15 ++++++ .../clients/speak/v1/websocket/__init__.py | 1 + .../speak/v1/websocket/async_client.py | 10 ++-- deepgram/clients/speak/v1/websocket/client.py | 10 ++-- .../clients/speak/v1/websocket/options.py | 7 +++ .../websocket/async_interactive/main.py | 4 +- .../websocket/interactive/main.py | 4 +- 29 files changed, 216 insertions(+), 118 deletions(-) create mode 100644 deepgram/clients/speak/v1/rest/options.py create mode 100644 deepgram/clients/speak/v1/websocket/options.py diff --git a/deepgram/__init__.py b/deepgram/__init__.py index 040e82df..f5971186 100644 --- a/deepgram/__init__.py +++ b/deepgram/__init__.py @@ -46,10 +46,11 @@ ErrorResponse, ) -# live +# speect-to-text WS +from .client import LiveClient, AsyncLiveClient # backward compat +from .client import ListenWebSocketClient, AsyncListenWebSocketClient from .client import LiveTranscriptionEvents -from .client import LiveClient, AsyncLiveClient -from .client import LiveOptions +from .client import LiveOptions, ListenWebSocketOptions from .client import ( # OpenResponse, LiveResultResponse, @@ -62,11 +63,14 @@ ) # prerecorded -from .client import PreRecordedClient, AsyncPreRecordedClient +from .client import PreRecordedClient, AsyncPreRecordedClient # backward compat +from .client import ListenRESTClient, AsyncListenRESTClient from .client import ( + ListenRESTOptions, PrerecordedOptions, PreRecordedStreamSource, PrerecordedSource, + ListenRestSource, ) from .client import ( AsyncPrerecordedResponse, @@ -91,8 +95,10 @@ # speak from .client import ( SpeakOptions, + SpeakRESTOptions, + SpeakWebSocketOptions, # FileSource, - SpeakWebSocketSource, + SpeakRestSource, SpeakSource, ) from .client import SpeakWebSocketEvents diff --git a/deepgram/client.py b/deepgram/client.py index 50cc2449..46e5b6fe 100644 --- a/deepgram/client.py +++ b/deepgram/client.py @@ -32,9 +32,16 @@ # listen client from .clients import Listen, Read, Speak -# live -from .clients import LiveClient, AsyncLiveClient +# speech-to-text +from .clients import LiveClient, AsyncLiveClient # backward compat from .clients import ( + ListenRESTClient, + AsyncListenRESTClient, + ListenWebSocketClient, + AsyncListenWebSocketClient, +) +from .clients import ( + ListenWebSocketOptions, LiveOptions, LiveTranscriptionEvents, ) @@ -57,9 +64,11 @@ AsyncPreRecordedClient, ) from .clients import ( + ListenRESTOptions, PrerecordedOptions, PreRecordedStreamSource, PrerecordedSource, + ListenRestSource, ) # prerecorded client responses @@ -88,8 +97,10 @@ # speak from .clients import ( SpeakOptions, + SpeakRESTOptions, + SpeakWebSocketOptions, # FileSource, - SpeakWebSocketSource, + SpeakRestSource, SpeakSource, ) from .clients import SpeakWebSocketEvents diff --git a/deepgram/clients/__init__.py b/deepgram/clients/__init__.py index 11f59400..4043e57e 100644 --- a/deepgram/clients/__init__.py +++ b/deepgram/clients/__init__.py @@ -36,14 +36,18 @@ AsyncLiveClient, ) -# rest +# speech-to-text rest +from .listen import ListenRESTClient, AsyncListenRESTClient + ## input from .listen import ( + ListenRESTOptions, PrerecordedOptions, PreRecordedStreamSource, # UrlSource, # FileSource, PrerecordedSource, + ListenRestSource, ) ## output @@ -54,9 +58,12 @@ ) -# websocket +# speech-to-text websocket +from .listen import ListenWebSocketClient, AsyncListenWebSocketClient + ## input from .listen import ( + ListenWebSocketOptions, LiveOptions, ) @@ -93,18 +100,20 @@ SyncAnalyzeResponse, ) -# speak +# text-to-speech ## common from .speak import ( SpeakOptions, + SpeakRESTOptions, + SpeakWebSocketOptions, # FileSource, - SpeakWebSocketSource, + SpeakRestSource, SpeakSource, ) from .speak import SpeakWebSocketEvents -## speak REST +## text-to-speech REST from .speak import ( SpeakClient, # backward compat SpeakRESTClient, @@ -116,7 +125,7 @@ SpeakRESTResponse, ) -## speak WebSocket +## text-to-speech WebSocket from .speak import ( SpeakWebSocketClient, AsyncSpeakWebSocketClient, diff --git a/deepgram/clients/listen/__init__.py b/deepgram/clients/listen/__init__.py index 49faed2e..e7ed3952 100644 --- a/deepgram/clients/listen/__init__.py +++ b/deepgram/clients/listen/__init__.py @@ -16,11 +16,13 @@ # rest ## input from .client import ( + ListenRESTOptions, PrerecordedOptions, PreRecordedStreamSource, UrlSource, FileSource, PrerecordedSource, + ListenRestSource, ) ## output @@ -34,6 +36,7 @@ # websocket ## input from .client import ( + ListenWebSocketOptions, LiveOptions, ) @@ -51,6 +54,8 @@ # clients from .client import ( + ListenRESTClient, + AsyncListenRESTClient, ListenWebSocketClient, AsyncListenWebSocketClient, ) diff --git a/deepgram/clients/listen/client.py b/deepgram/clients/listen/client.py index 34cea6bd..ae769005 100644 --- a/deepgram/clients/listen/client.py +++ b/deepgram/clients/listen/client.py @@ -10,13 +10,17 @@ ListenRESTClient as ListenRESTClientLatest, AsyncListenRESTClient as AsyncListenRESTClientLatest, ) -from .v1 import PrerecordedOptions as PrerecordedOptionsLatest +from .v1 import ( + PrerecordedOptions as PrerecordedOptionsLatest, + ListenRESTOptions as ListenRESTOptionsLatest, +) from .v1 import ( UrlSource as UrlSourceLatest, FileSource as FileSourceLatest, PreRecordedStreamSource as PreRecordedStreamSourceLatest, PrerecordedSource as PrerecordedSourceLatest, + ListenRestSource as ListenRestSourceLatest, ) from .v1 import ( AsyncPrerecordedResponse as AsyncPrerecordedResponseLatest, @@ -29,7 +33,10 @@ ListenWebSocketClient as ListenWebSocketClientLatest, AsyncListenWebSocketClient as AsyncListenWebSocketClientLatest, ) -from .v1 import LiveOptions as LiveOptionsLatest, LiveOptions as SteamingOptionsLatest +from .v1 import ( + LiveOptions as LiveOptionsLatest, + ListenWebSocketOptions as ListenWebSocketOptionsLatest, +) from .v1 import ( OpenResponse as OpenResponseLatest, LiveResultResponse as LiveResultResponseLatest, @@ -53,11 +60,13 @@ # rest ## input +ListenRESTOptions = ListenRESTOptionsLatest PrerecordedOptions = PrerecordedOptionsLatest PreRecordedStreamSource = PreRecordedStreamSourceLatest UrlSource = UrlSourceLatest FileSource = FileSourceLatest PrerecordedSource = PrerecordedSourceLatest +ListenRestSource = ListenRestSourceLatest ## output AsyncPrerecordedResponse = AsyncPrerecordedResponseLatest @@ -67,6 +76,7 @@ # websocket ## input +ListenWebSocketOptions = ListenWebSocketOptionsLatest LiveOptions = LiveOptionsLatest ## output @@ -81,5 +91,7 @@ # clients +ListenRESTClient = ListenRESTClientLatest +AsyncListenRESTClient = AsyncListenRESTClientLatest ListenWebSocketClient = ListenWebSocketClientLatest AsyncListenWebSocketClient = AsyncListenWebSocketClientLatest diff --git a/deepgram/clients/listen/v1/__init__.py b/deepgram/clients/listen/v1/__init__.py index 6806412a..cdacfe44 100644 --- a/deepgram/clients/listen/v1/__init__.py +++ b/deepgram/clients/listen/v1/__init__.py @@ -16,12 +16,13 @@ # rest from .rest import ListenRESTClient, AsyncListenRESTClient -from .rest import PrerecordedOptions +from .rest import ListenRESTOptions, PrerecordedOptions from .rest import ( UrlSource, FileSource, PreRecordedStreamSource, PrerecordedSource, + ListenRestSource, ) from .rest import ( AsyncPrerecordedResponse, @@ -31,7 +32,7 @@ # websocket from .websocket import ListenWebSocketClient, AsyncListenWebSocketClient -from .websocket import LiveOptions, LiveOptions as SteamingOptions +from .websocket import LiveOptions, ListenWebSocketOptions from .websocket import ( OpenResponse, LiveResultResponse, diff --git a/deepgram/clients/listen/v1/rest/__init__.py b/deepgram/clients/listen/v1/rest/__init__.py index 56bd0d20..9fdba320 100644 --- a/deepgram/clients/listen/v1/rest/__init__.py +++ b/deepgram/clients/listen/v1/rest/__init__.py @@ -5,11 +5,13 @@ from .client import ListenRESTClient from .async_client import AsyncListenRESTClient from .options import ( + ListenRESTOptions, PrerecordedOptions, FileSource, UrlSource, PreRecordedStreamSource, PrerecordedSource, + ListenRestSource, ) from .response import ( AsyncPrerecordedResponse, diff --git a/deepgram/clients/listen/v1/rest/async_client.py b/deepgram/clients/listen/v1/rest/async_client.py index a84f0d33..4263cf25 100644 --- a/deepgram/clients/listen/v1/rest/async_client.py +++ b/deepgram/clients/listen/v1/rest/async_client.py @@ -14,6 +14,7 @@ from .helpers import is_buffer_source, is_readstream_source, is_url_source from .options import ( + ListenRESTOptions, PrerecordedOptions, FileSource, UrlSource, @@ -40,7 +41,7 @@ def __init__(self, config: DeepgramClientOptions): async def transcribe_url( self, source: UrlSource, - options: Optional[Union[Dict, PrerecordedOptions]] = None, + options: Optional[Union[Dict, ListenRESTOptions]] = None, addons: Optional[Dict] = None, headers: Optional[Dict] = None, timeout: Optional[httpx.Timeout] = None, @@ -51,7 +52,7 @@ async def transcribe_url( Args: source (UrlSource): The URL source of the audio to transcribe. - options (PrerecordedOptions): Additional options for the transcription (default is None). + options (ListenRESTOptions): Additional options for the transcription (default is None). endpoint (str): The API endpoint for the transcription (default is "v1/listen"). Returns: @@ -66,7 +67,7 @@ async def transcribe_url( isinstance(options, dict) and "callback" in options and options["callback"] is not None - ) or (isinstance(options, PrerecordedOptions) and options.callback is not None): + ) or (isinstance(options, ListenRESTOptions) and options.callback is not None): self._logger.debug("ListenRESTClient.transcribe_url LEAVE") return await self.transcribe_url_callback( source, @@ -86,15 +87,15 @@ async def transcribe_url( self._logger.debug("ListenRESTClient.transcribe_url LEAVE") raise DeepgramTypeError("Unknown transcription source type") - if isinstance(options, PrerecordedOptions) and not options.check(): + if isinstance(options, ListenRESTOptions) and not options.check(): self._logger.error("options.check failed") self._logger.debug("ListenRESTClient.transcribe_url LEAVE") raise DeepgramError("Fatal transcription options error") self._logger.info("url: %s", url) self._logger.info("source: %s", source) - if isinstance(options, PrerecordedOptions): - self._logger.info("PrerecordedOptions switching class -> dict") + if isinstance(options, ListenRESTOptions): + self._logger.info("ListenRESTOptions switching class -> dict") options = options.to_dict() self._logger.info("options: %s", options) self._logger.info("addons: %s", addons) @@ -118,7 +119,7 @@ async def transcribe_url_callback( self, source: UrlSource, callback: str, - options: Optional[Union[Dict, PrerecordedOptions]] = None, + options: Optional[Union[Dict, ListenRESTOptions]] = None, addons: Optional[Dict] = None, headers: Optional[Dict] = None, timeout: Optional[httpx.Timeout] = None, @@ -130,7 +131,7 @@ async def transcribe_url_callback( Args: source (UrlSource): The URL source of the audio to transcribe. callback (str): The callback URL where the transcription results will be sent. - options (PrerecordedOptions): Additional options for the transcription (default is None). + options (ListenRESTOptions): Additional options for the transcription (default is None). endpoint (str): The API endpoint for the transcription (default is "v1/listen"). Returns: @@ -144,7 +145,7 @@ async def transcribe_url_callback( url = f"{self._config.url}/{endpoint}" if options is None: options = {} - if isinstance(options, PrerecordedOptions): + if isinstance(options, ListenRESTOptions): options.callback = callback else: options["callback"] = callback @@ -155,15 +156,15 @@ async def transcribe_url_callback( self._logger.debug("ListenRESTClient.transcribe_url_callback LEAVE") raise DeepgramTypeError("Unknown transcription source type") - if isinstance(options, PrerecordedOptions) and not options.check(): + if isinstance(options, ListenRESTOptions) and not options.check(): self._logger.error("options.check failed") self._logger.debug("ListenRESTClient.transcribe_url_callback LEAVE") raise DeepgramError("Fatal transcription options error") self._logger.info("url: %s", url) self._logger.info("source: %s", source) - if isinstance(options, PrerecordedOptions): - self._logger.info("PrerecordedOptions switching class -> dict") + if isinstance(options, ListenRESTOptions): + self._logger.info("ListenRESTOptions switching class -> dict") options = options.to_dict() self._logger.info("options: %s", options) self._logger.info("addons: %s", addons) @@ -186,7 +187,7 @@ async def transcribe_url_callback( async def transcribe_file( self, source: FileSource, - options: Optional[Union[Dict, PrerecordedOptions]] = None, + options: Optional[Union[Dict, ListenRESTOptions]] = None, addons: Optional[Dict] = None, headers: Optional[Dict] = None, timeout: Optional[httpx.Timeout] = None, @@ -197,7 +198,7 @@ async def transcribe_file( Args: source (FileSource): The local file source of the audio to transcribe. - options (PrerecordedOptions): Additional options for the transcription (default is None). + options (ListenRESTOptions): Additional options for the transcription (default is None). endpoint (str): The API endpoint for the transcription (default is "v1/listen"). Returns: @@ -212,7 +213,7 @@ async def transcribe_file( isinstance(options, dict) and "callback" in options and options["callback"] is not None - ) or (isinstance(options, PrerecordedOptions) and options.callback is not None): + ) or (isinstance(options, ListenRESTOptions) and options.callback is not None): self._logger.debug("ListenRESTClient.transcribe_file LEAVE") return await self.transcribe_file_callback( source, @@ -234,14 +235,14 @@ async def transcribe_file( self._logger.debug("ListenRESTClient.transcribe_file LEAVE") raise DeepgramTypeError("Unknown transcription source type") - if isinstance(options, PrerecordedOptions) and not options.check(): + if isinstance(options, ListenRESTOptions) and not options.check(): self._logger.error("options.check failed") self._logger.debug("ListenRESTClient.transcribe_file LEAVE") raise DeepgramError("Fatal transcription options error") self._logger.info("url: %s", url) - if isinstance(options, PrerecordedOptions): - self._logger.info("PrerecordedOptions switching class -> dict") + if isinstance(options, ListenRESTOptions): + self._logger.info("ListenRESTOptions switching class -> dict") options = options.to_dict() self._logger.info("options: %s", options) self._logger.info("addons: %s", addons) @@ -265,7 +266,7 @@ async def transcribe_file_callback( self, source: FileSource, callback: str, - options: Optional[Union[Dict, PrerecordedOptions]] = None, + options: Optional[Union[Dict, ListenRESTOptions]] = None, addons: Optional[Dict] = None, headers: Optional[Dict] = None, timeout: Optional[httpx.Timeout] = None, @@ -277,7 +278,7 @@ async def transcribe_file_callback( Args: source (FileSource): The local file source of the audio to transcribe. callback (str): The callback URL where the transcription results will be sent. - options (PrerecordedOptions): Additional options for the transcription (default is None). + options (ListenRESTOptions): Additional options for the transcription (default is None). endpoint (str): The API endpoint for the transcription (default is "v1/listen"). Returns: @@ -291,7 +292,7 @@ async def transcribe_file_callback( url = f"{self._config.url}/{endpoint}" if options is None: options = {} - if isinstance(options, PrerecordedOptions): + if isinstance(options, ListenRESTOptions): options.callback = callback else: options["callback"] = callback @@ -304,14 +305,14 @@ async def transcribe_file_callback( self._logger.debug("ListenRESTClient.transcribe_file_callback LEAVE") raise DeepgramTypeError("Unknown transcription source type") - if isinstance(options, PrerecordedOptions) and not options.check(): + if isinstance(options, ListenRESTOptions) and not options.check(): self._logger.error("options.check failed") self._logger.debug("ListenRESTClient.transcribe_file_callback LEAVE") raise DeepgramError("Fatal transcription options error") self._logger.info("url: %s", url) - if isinstance(options, PrerecordedOptions): - self._logger.info("PrerecordedOptions switching class -> dict") + if isinstance(options, ListenRESTOptions): + self._logger.info("ListenRESTOptions switching class -> dict") options = options.to_dict() self._logger.info("options: %s", options) self._logger.info("addons: %s", addons) diff --git a/deepgram/clients/listen/v1/rest/client.py b/deepgram/clients/listen/v1/rest/client.py index 4e23f4d7..e2604f4b 100644 --- a/deepgram/clients/listen/v1/rest/client.py +++ b/deepgram/clients/listen/v1/rest/client.py @@ -14,6 +14,7 @@ from .helpers import is_buffer_source, is_readstream_source, is_url_source from .options import ( + ListenRESTOptions, PrerecordedOptions, FileSource, UrlSource, @@ -40,7 +41,7 @@ def __init__(self, config: DeepgramClientOptions): def transcribe_url( self, source: UrlSource, - options: Optional[Union[Dict, PrerecordedOptions]] = None, + options: Optional[Union[Dict, ListenRESTOptions]] = None, addons: Optional[Dict] = None, headers: Optional[Dict] = None, timeout: Optional[httpx.Timeout] = None, @@ -51,7 +52,7 @@ def transcribe_url( Args: source (UrlSource): The URL source of the audio to transcribe. - options (PrerecordedOptions): Additional options for the transcription (default is None). + options (ListenRESTOptions): Additional options for the transcription (default is None). endpoint (str): The API endpoint for the transcription (default is "v1/listen"). Returns: @@ -66,7 +67,7 @@ def transcribe_url( isinstance(options, dict) and "callback" in options and options["callback"] is not None - ) or (isinstance(options, PrerecordedOptions) and options.callback is not None): + ) or (isinstance(options, ListenRESTOptions) and options.callback is not None): self._logger.debug("ListenRESTClient.transcribe_url LEAVE") return self.transcribe_url_callback( source, @@ -86,15 +87,15 @@ def transcribe_url( self._logger.debug("ListenRESTClient.transcribe_url LEAVE") raise DeepgramTypeError("Unknown transcription source type") - if isinstance(options, PrerecordedOptions) and not options.check(): + if isinstance(options, ListenRESTOptions) and not options.check(): self._logger.error("options.check failed") self._logger.debug("ListenRESTClient.transcribe_url LEAVE") raise DeepgramError("Fatal transcription options error") self._logger.info("url: %s", url) self._logger.info("source: %s", source) - if isinstance(options, PrerecordedOptions): - self._logger.info("PrerecordedOptions switching class -> dict") + if isinstance(options, ListenRESTOptions): + self._logger.info("ListenRESTOptions switching class -> dict") options = options.to_dict() self._logger.info("options: %s", options) self._logger.info("addons: %s", addons) @@ -118,7 +119,7 @@ def transcribe_url_callback( self, source: UrlSource, callback: str, - options: Optional[Union[Dict, PrerecordedOptions]] = None, + options: Optional[Union[Dict, ListenRESTOptions]] = None, addons: Optional[Dict] = None, headers: Optional[Dict] = None, timeout: Optional[httpx.Timeout] = None, @@ -130,7 +131,7 @@ def transcribe_url_callback( Args: source (UrlSource): The URL source of the audio to transcribe. callback (str): The callback URL where the transcription results will be sent. - options (PrerecordedOptions): Additional options for the transcription (default is None). + options (ListenRESTOptions): Additional options for the transcription (default is None). endpoint (str): The API endpoint for the transcription (default is "v1/listen"). Returns: @@ -144,7 +145,7 @@ def transcribe_url_callback( url = f"{self._config.url}/{endpoint}" if options is None: options = {} - if isinstance(options, PrerecordedOptions): + if isinstance(options, ListenRESTOptions): options.callback = callback else: options["callback"] = callback @@ -155,15 +156,15 @@ def transcribe_url_callback( self._logger.debug("ListenRESTClient.transcribe_url_callback LEAVE") raise DeepgramTypeError("Unknown transcription source type") - if isinstance(options, PrerecordedOptions) and not options.check(): + if isinstance(options, ListenRESTOptions) and not options.check(): self._logger.error("options.check failed") self._logger.debug("ListenRESTClient.transcribe_url_callback LEAVE") raise DeepgramError("Fatal transcription options error") self._logger.info("url: %s", url) self._logger.info("source: %s", source) - if isinstance(options, PrerecordedOptions): - self._logger.info("PrerecordedOptions switching class -> dict") + if isinstance(options, ListenRESTOptions): + self._logger.info("ListenRESTOptions switching class -> dict") options = options.to_dict() self._logger.info("options: %s", options) self._logger.info("addons: %s", addons) @@ -186,7 +187,7 @@ def transcribe_url_callback( def transcribe_file( self, source: FileSource, - options: Optional[Union[Dict, PrerecordedOptions]] = None, + options: Optional[Union[Dict, ListenRESTOptions]] = None, addons: Optional[Dict] = None, headers: Optional[Dict] = None, timeout: Optional[httpx.Timeout] = None, @@ -197,7 +198,7 @@ def transcribe_file( Args: source (FileSource): The local file source of the audio to transcribe. - options (PrerecordedOptions): Additional options for the transcription (default is None). + options (ListenRESTOptions): Additional options for the transcription (default is None). endpoint (str): The API endpoint for the transcription (default is "v1/listen"). Returns: @@ -212,7 +213,7 @@ def transcribe_file( isinstance(options, dict) and "callback" in options and options["callback"] is not None - ) or (isinstance(options, PrerecordedOptions) and options.callback is not None): + ) or (isinstance(options, ListenRESTOptions) and options.callback is not None): self._logger.debug("ListenRESTClient.transcribe_file LEAVE") return self.transcribe_file_callback( source, @@ -235,14 +236,14 @@ def transcribe_file( self._logger.debug("ListenRESTClient.transcribe_file LEAVE") raise DeepgramTypeError("Unknown transcription source type") - if isinstance(options, PrerecordedOptions) and not options.check(): + if isinstance(options, ListenRESTOptions) and not options.check(): self._logger.error("options.check failed") self._logger.debug("ListenRESTClient.transcribe_file LEAVE") raise DeepgramError("Fatal transcription options error") self._logger.info("url: %s", url) - if isinstance(options, PrerecordedOptions): - self._logger.info("PrerecordedOptions switching class -> dict") + if isinstance(options, ListenRESTOptions): + self._logger.info("ListenRESTOptions switching class -> dict") options = options.to_dict() self._logger.info("options: %s", options) self._logger.info("addons: %s", addons) @@ -266,7 +267,7 @@ def transcribe_file_callback( self, source: FileSource, callback: str, - options: Optional[Union[Dict, PrerecordedOptions]] = None, + options: Optional[Union[Dict, ListenRESTOptions]] = None, addons: Optional[Dict] = None, headers: Optional[Dict] = None, timeout: Optional[httpx.Timeout] = None, @@ -278,7 +279,7 @@ def transcribe_file_callback( Args: source (FileSource): The local file source of the audio to transcribe. callback (str): The callback URL where the transcription results will be sent. - options (PrerecordedOptions): Additional options for the transcription (default is None). + options (ListenRESTOptions): Additional options for the transcription (default is None). endpoint (str): The API endpoint for the transcription (default is "v1/listen"). Returns: @@ -292,7 +293,7 @@ def transcribe_file_callback( url = f"{self._config.url}/{endpoint}" if options is None: options = {} - if isinstance(options, PrerecordedOptions): + if isinstance(options, ListenRESTOptions): options.callback = callback else: options["callback"] = callback @@ -305,14 +306,14 @@ def transcribe_file_callback( self._logger.debug("ListenRESTClient.transcribe_file_callback LEAVE") raise DeepgramTypeError("Unknown transcription source type") - if isinstance(options, PrerecordedOptions) and not options.check(): + if isinstance(options, ListenRESTOptions) and not options.check(): self._logger.error("options.check failed") self._logger.debug("ListenRESTClient.transcribe_file_callback LEAVE") raise DeepgramError("Fatal transcription options error") self._logger.info("url: %s", url) - if isinstance(options, PrerecordedOptions): - self._logger.info("PrerecordedOptions switching class -> dict") + if isinstance(options, ListenRESTOptions): + self._logger.info("ListenRESTOptions switching class -> dict") options = options.to_dict() self._logger.info("options: %s", options) self._logger.info("addons: %s", addons) diff --git a/deepgram/clients/listen/v1/rest/options.py b/deepgram/clients/listen/v1/rest/options.py index 16c52238..d3039a61 100644 --- a/deepgram/clients/listen/v1/rest/options.py +++ b/deepgram/clients/listen/v1/rest/options.py @@ -173,9 +173,12 @@ def check(self): return True +ListenRESTOptions = PrerecordedOptions + # PrerecordedSource for backwards compatibility PreRecordedStreamSource = StreamSource # UrlSource # FileSource PrerecordedSource = Union[UrlSource, FileSource] +ListenRestSource = PrerecordedSource diff --git a/deepgram/clients/listen/v1/websocket/__init__.py b/deepgram/clients/listen/v1/websocket/__init__.py index 75bd694f..4ddc1590 100644 --- a/deepgram/clients/listen/v1/websocket/__init__.py +++ b/deepgram/clients/listen/v1/websocket/__init__.py @@ -4,7 +4,7 @@ from .client import ListenWebSocketClient from .async_client import AsyncListenWebSocketClient -from .options import LiveOptions +from .options import LiveOptions, ListenWebSocketOptions from .....options import DeepgramClientOptions, ClientOptionsFromEnv from .response import ( OpenResponse, diff --git a/deepgram/clients/listen/v1/websocket/async_client.py b/deepgram/clients/listen/v1/websocket/async_client.py index 764fd531..caa52e44 100644 --- a/deepgram/clients/listen/v1/websocket/async_client.py +++ b/deepgram/clients/listen/v1/websocket/async_client.py @@ -27,7 +27,7 @@ ErrorResponse, UnhandledResponse, ) -from .options import LiveOptions +from .options import LiveOptions, ListenWebSocketOptions ONE_SECOND = 1 HALF_SECOND = 0.5 @@ -92,7 +92,7 @@ def __init__(self, config: DeepgramClientOptions): # pylint: disable=too-many-branches,too-many-statements async def start( self, - options: Optional[Union[LiveOptions, Dict]] = None, + options: Optional[Union[ListenWebSocketOptions, Dict]] = None, addons: Optional[Dict] = None, headers: Optional[Dict] = None, members: Optional[Dict] = None, @@ -108,7 +108,7 @@ async def start( self._logger.info("members: %s", members) self._logger.info("kwargs: %s", kwargs) - if isinstance(options, LiveOptions) and not options.check(): + if isinstance(options, ListenWebSocketOptions) and not options.check(): self._logger.error("options.check failed") self._logger.debug("AsyncListenWebSocketClient.start LEAVE") raise DeepgramError("Fatal transcription options error") @@ -126,8 +126,8 @@ async def start( else: self._kwargs = {} - if isinstance(options, LiveOptions): - self._logger.info("LiveOptions switching class -> dict") + if isinstance(options, ListenWebSocketOptions): + self._logger.info("ListenWebSocketOptions switching class -> dict") self._options = options.to_dict() elif options is not None: self._options = options diff --git a/deepgram/clients/listen/v1/websocket/client.py b/deepgram/clients/listen/v1/websocket/client.py index 7a07a5be..fe585ab9 100644 --- a/deepgram/clients/listen/v1/websocket/client.py +++ b/deepgram/clients/listen/v1/websocket/client.py @@ -27,7 +27,7 @@ ErrorResponse, UnhandledResponse, ) -from .options import LiveOptions +from .options import LiveOptions, ListenWebSocketOptions ONE_SECOND = 1 HALF_SECOND = 0.5 @@ -99,7 +99,7 @@ def __init__(self, config: DeepgramClientOptions): # pylint: disable=too-many-statements,too-many-branches def start( self, - options: Optional[Union[LiveOptions, Dict]] = None, + options: Optional[Union[ListenWebSocketOptions, Dict]] = None, addons: Optional[Dict] = None, headers: Optional[Dict] = None, members: Optional[Dict] = None, @@ -115,7 +115,7 @@ def start( self._logger.info("members: %s", members) self._logger.info("kwargs: %s", kwargs) - if isinstance(options, LiveOptions) and not options.check(): + if isinstance(options, ListenWebSocketOptions) and not options.check(): self._logger.error("options.check failed") self._logger.debug("ListenWebSocketClient.start LEAVE") raise DeepgramError("Fatal transcription options error") @@ -133,8 +133,8 @@ def start( else: self._kwargs = {} - if isinstance(options, LiveOptions): - self._logger.info("LiveOptions switching class -> dict") + if isinstance(options, ListenWebSocketOptions): + self._logger.info("ListenWebSocketOptions switching class -> dict") self._options = options.to_dict() elif options is not None: self._options = options diff --git a/deepgram/clients/listen/v1/websocket/options.py b/deepgram/clients/listen/v1/websocket/options.py index 667605dc..857c6634 100644 --- a/deepgram/clients/listen/v1/websocket/options.py +++ b/deepgram/clients/listen/v1/websocket/options.py @@ -141,3 +141,6 @@ def check(self): logger.setLevel(prev) return True + + +ListenWebSocketOptions = LiveOptions diff --git a/deepgram/clients/speak/__init__.py b/deepgram/clients/speak/__init__.py index 7e1dab7c..edf4d385 100644 --- a/deepgram/clients/speak/__init__.py +++ b/deepgram/clients/speak/__init__.py @@ -14,8 +14,10 @@ ) from .client import ( SpeakOptions, + SpeakRESTOptions, + SpeakWebSocketOptions, FileSource, - SpeakWebSocketSource, + SpeakRestSource, SpeakSource, ) from .client import ( diff --git a/deepgram/clients/speak/client.py b/deepgram/clients/speak/client.py index 629e6919..e429fba0 100644 --- a/deepgram/clients/speak/client.py +++ b/deepgram/clients/speak/client.py @@ -10,8 +10,10 @@ ) from .v1 import ( SpeakOptions as SpeakOptionsLatest, + SpeakRESTOptions as SpeakRESTOptionsLatest, + SpeakWebSocketOptions as SpeakWebSocketOptionsLatest, FileSource as FileSourceLatest, - SpeakWebSocketSource as SpeakWebSocketSourceLatest, + SpeakRestSource as SpeakRestSourceLatest, SpeakSource as SpeakSourceLatest, ) from .v1 import ( @@ -32,7 +34,9 @@ # input SpeakOptions = SpeakOptionsLatest -SpeakWebSocketSource = SpeakWebSocketSourceLatest +SpeakRESTOptions = SpeakRESTOptionsLatest +SpeakWebSocketOptions = SpeakWebSocketOptionsLatest +SpeakRestSource = SpeakRestSourceLatest FileSource = FileSourceLatest SpeakSource = SpeakSourceLatest diff --git a/deepgram/clients/speak/v1/__init__.py b/deepgram/clients/speak/v1/__init__.py index 6acfb7b1..b8fa18eb 100644 --- a/deepgram/clients/speak/v1/__init__.py +++ b/deepgram/clients/speak/v1/__init__.py @@ -2,7 +2,18 @@ # Use of this source code is governed by a MIT license that can be found in the LICENSE file. # SPDX-License-Identifier: MIT -from .options import SpeakOptions, FileSource, SpeakWebSocketSource, SpeakSource +from .options import ( + SpeakOptions, +) +from .rest import ( + SpeakRESTOptions, + SpeakRestSource, + SpeakSource, + FileSource, +) +from .websocket import ( + SpeakWebSocketOptions, +) from ....options import DeepgramClientOptions, ClientOptionsFromEnv # rest diff --git a/deepgram/clients/speak/v1/options.py b/deepgram/clients/speak/v1/options.py index edd6723a..0435986c 100644 --- a/deepgram/clients/speak/v1/options.py +++ b/deepgram/clients/speak/v1/options.py @@ -65,5 +65,7 @@ def check(self): return True -SpeakWebSocketSource = BufferedReader -SpeakSource = Union[FileSource, SpeakWebSocketSource] +SpeakRESTOptions = SpeakOptions + +SpeakSource = Union[FileSource, BufferedReader] +SpeakRestSource = SpeakSource diff --git a/deepgram/clients/speak/v1/rest/__init__.py b/deepgram/clients/speak/v1/rest/__init__.py index 956abf66..7024eaa9 100644 --- a/deepgram/clients/speak/v1/rest/__init__.py +++ b/deepgram/clients/speak/v1/rest/__init__.py @@ -5,3 +5,9 @@ from .client import SpeakRESTClient from .async_client import AsyncSpeakRESTClient from .response import SpeakRESTResponse +from .options import ( + SpeakRESTOptions, + SpeakSource, + SpeakRestSource, + FileSource, +) diff --git a/deepgram/clients/speak/v1/rest/async_client.py b/deepgram/clients/speak/v1/rest/async_client.py index a8fed0ad..de02b196 100644 --- a/deepgram/clients/speak/v1/rest/async_client.py +++ b/deepgram/clients/speak/v1/rest/async_client.py @@ -15,7 +15,7 @@ from ...errors import DeepgramError, DeepgramTypeError from .helpers import is_text_source -from ..options import SpeakOptions, FileSource +from .options import SpeakRESTOptions, FileSource from .response import SpeakRESTResponse @@ -38,7 +38,7 @@ def __init__(self, config: DeepgramClientOptions): async def stream( self, source: FileSource, - options: Optional[Union[Dict, SpeakOptions]] = None, + options: Optional[Union[Dict, SpeakRESTOptions]] = None, addons: Optional[Dict] = None, headers: Optional[Dict] = None, timeout: Optional[httpx.Timeout] = None, @@ -49,7 +49,7 @@ async def stream( Args: source (TextSource): The text source to speak. - options (SpeakOptions): Additional options for the ingest (default is None). + options (SpeakRESTOptions): Additional options for the ingest (default is None). addons (Dict): Additional options for the request (default is None). headers (Dict): Additional headers for the request (default is None). timeout (httpx.Timeout): The timeout for the request (default is None). @@ -71,15 +71,15 @@ async def stream( self._logger.debug("AsyncSpeakClient.stream LEAVE") raise DeepgramTypeError("Unknown speak source type") - if isinstance(options, SpeakOptions) and not options.check(): + if isinstance(options, SpeakRESTOptions) and not options.check(): self._logger.error("options.check failed") self._logger.debug("AsyncSpeakClient.stream LEAVE") raise DeepgramError("Fatal speak options error") self._logger.info("url: %s", url) self._logger.info("source: %s", source) - if isinstance(options, SpeakOptions): - self._logger.info("SpeakOptions switching class -> dict") + if isinstance(options, SpeakRESTOptions): + self._logger.info("SpeakRESTOptions switching class -> dict") options = options.to_dict() self._logger.info("options: %s", options) self._logger.info("addons: %s", addons) @@ -123,7 +123,7 @@ async def file( self, filename: str, source: FileSource, - options: Optional[Union[Dict, SpeakOptions]] = None, + options: Optional[Union[Dict, SpeakRESTOptions]] = None, addons: Optional[Dict] = None, timeout: Optional[httpx.Timeout] = None, endpoint: str = "v1/speak", @@ -144,7 +144,7 @@ async def save( self, filename: str, source: FileSource, - options: Optional[Union[Dict, SpeakOptions]] = None, + options: Optional[Union[Dict, SpeakRESTOptions]] = None, addons: Optional[Dict] = None, headers: Optional[Dict] = None, timeout: Optional[httpx.Timeout] = None, @@ -155,7 +155,7 @@ async def save( Args: source (TextSource): The text source to speak. - options (SpeakOptions): Additional options for the ingest (default is None). + options (SpeakRESTOptions): Additional options for the ingest (default is None). addons (Dict): Additional options for the request (default is None). headers (Dict): Additional headers for the request (default is None). timeout (httpx.Timeout): The timeout for the request (default is None). diff --git a/deepgram/clients/speak/v1/rest/client.py b/deepgram/clients/speak/v1/rest/client.py index afefa0cf..ae605cd2 100644 --- a/deepgram/clients/speak/v1/rest/client.py +++ b/deepgram/clients/speak/v1/rest/client.py @@ -14,7 +14,7 @@ from ...errors import DeepgramError, DeepgramTypeError from .helpers import is_text_source -from ..options import SpeakOptions, FileSource +from .options import SpeakRESTOptions, FileSource from .response import SpeakRESTResponse @@ -37,7 +37,7 @@ def __init__(self, config: DeepgramClientOptions): def stream( self, source: FileSource, - options: Optional[Union[Dict, SpeakOptions]] = None, + options: Optional[Union[Dict, SpeakRESTOptions]] = None, addons: Optional[Dict] = None, headers: Optional[Dict] = None, timeout: Optional[httpx.Timeout] = None, @@ -48,7 +48,7 @@ def stream( Args: source (TextSource): The text source to speak. - options (SpeakOptions): Additional options for the ingest (default is None). + options (SpeakRESTOptions): Additional options for the ingest (default is None). addons (Dict): Additional options for the request (default is None). headers (Dict): Additional headers for the request (default is None). timeout (httpx.Timeout): The timeout for the request (default is None). @@ -70,15 +70,15 @@ def stream( self._logger.debug("SpeakClient.stream LEAVE") raise DeepgramTypeError("Unknown speak source type") - if isinstance(options, SpeakOptions) and not options.check(): + if isinstance(options, SpeakRESTOptions) and not options.check(): self._logger.error("options.check failed") self._logger.debug("SpeakClient.stream LEAVE") raise DeepgramError("Fatal speak options error") self._logger.info("url: %s", url) self._logger.info("source: %s", source) - if isinstance(options, SpeakOptions): - self._logger.info("SpeakOptions switching class -> dict") + if isinstance(options, SpeakRESTOptions): + self._logger.info("SpeakRESTOptions switching class -> dict") options = options.to_dict() self._logger.info("options: %s", options) self._logger.info("addons: %s", addons) @@ -123,7 +123,7 @@ async def file( self, filename: str, source: FileSource, - options: Optional[Union[Dict, SpeakOptions]] = None, + options: Optional[Union[Dict, SpeakRESTOptions]] = None, addons: Optional[Dict] = None, timeout: Optional[httpx.Timeout] = None, endpoint: str = "v1/speak", @@ -144,7 +144,7 @@ def save( self, filename: str, source: FileSource, - options: Optional[Union[Dict, SpeakOptions]] = None, + options: Optional[Union[Dict, SpeakRESTOptions]] = None, addons: Optional[Dict] = None, headers: Optional[Dict] = None, timeout: Optional[httpx.Timeout] = None, @@ -155,7 +155,7 @@ def save( Args: source (TextSource): The text source to speak. - options (SpeakOptions): Additional options for the ingest (default is None). + options (SpeakRESTOptions): Additional options for the ingest (default is None). addons (Dict): Additional options for the request (default is None). headers (Dict): Additional headers for the request (default is None). timeout (httpx.Timeout): The timeout for the request (default is None). diff --git a/deepgram/clients/speak/v1/rest/helpers.py b/deepgram/clients/speak/v1/rest/helpers.py index 6b048bd5..3232c1e7 100644 --- a/deepgram/clients/speak/v1/rest/helpers.py +++ b/deepgram/clients/speak/v1/rest/helpers.py @@ -2,7 +2,7 @@ # Use of this source code is governed by a MIT license that can be found in the LICENSE file. # SPDX-License-Identifier: MIT -from ..options import SpeakSource +from .options import SpeakSource def is_text_source(provided_source: SpeakSource) -> bool: diff --git a/deepgram/clients/speak/v1/rest/options.py b/deepgram/clients/speak/v1/rest/options.py new file mode 100644 index 00000000..62e5ba31 --- /dev/null +++ b/deepgram/clients/speak/v1/rest/options.py @@ -0,0 +1,15 @@ +# Copyright 2024 Deepgram SDK contributors. All Rights Reserved. +# Use of this source code is governed by a MIT license that can be found in the LICENSE file. +# SPDX-License-Identifier: MIT + +from io import BufferedReader +from typing import Union + +from ....common import FileSource +from ..options import SpeakOptions + + +SpeakRESTOptions = SpeakOptions + +SpeakSource = Union[FileSource, BufferedReader] +SpeakRestSource = SpeakSource diff --git a/deepgram/clients/speak/v1/websocket/__init__.py b/deepgram/clients/speak/v1/websocket/__init__.py index f086c38a..e6698987 100644 --- a/deepgram/clients/speak/v1/websocket/__init__.py +++ b/deepgram/clients/speak/v1/websocket/__init__.py @@ -14,3 +14,4 @@ WarningResponse, ErrorResponse, ) +from .options import SpeakWebSocketOptions diff --git a/deepgram/clients/speak/v1/websocket/async_client.py b/deepgram/clients/speak/v1/websocket/async_client.py index c8d2362c..7baea70b 100644 --- a/deepgram/clients/speak/v1/websocket/async_client.py +++ b/deepgram/clients/speak/v1/websocket/async_client.py @@ -25,7 +25,7 @@ ErrorResponse, UnhandledResponse, ) -from ..options import SpeakOptions +from .options import SpeakWebSocketOptions class AsyncSpeakWebSocketClient: # pylint: disable=too-many-instance-attributes @@ -77,7 +77,7 @@ def __init__(self, config: DeepgramClientOptions): # pylint: disable=too-many-branches,too-many-statements async def start( self, - options: Optional[Union[SpeakOptions, Dict]] = None, + options: Optional[Union[SpeakWebSocketOptions, Dict]] = None, addons: Optional[Dict] = None, headers: Optional[Dict] = None, members: Optional[Dict] = None, @@ -93,7 +93,7 @@ async def start( self._logger.info("members: %s", members) self._logger.info("kwargs: %s", kwargs) - if isinstance(options, SpeakOptions) and not options.check(): + if isinstance(options, SpeakWebSocketOptions) and not options.check(): self._logger.error("options.check failed") self._logger.debug("SpeakStreamClient.start LEAVE") raise DeepgramError("Fatal text-to-speech options error") @@ -111,8 +111,8 @@ async def start( else: self._kwargs = {} - if isinstance(options, SpeakOptions): - self._logger.info("SpeakOptions switching class -> dict") + if isinstance(options, SpeakWebSocketOptions): + self._logger.info("SpeakWebSocketOptions switching class -> dict") self._options = options.to_dict() elif options is not None: self._options = options diff --git a/deepgram/clients/speak/v1/websocket/client.py b/deepgram/clients/speak/v1/websocket/client.py index 4637559d..831e04eb 100644 --- a/deepgram/clients/speak/v1/websocket/client.py +++ b/deepgram/clients/speak/v1/websocket/client.py @@ -26,7 +26,7 @@ ErrorResponse, UnhandledResponse, ) -from ..options import SpeakOptions +from .options import SpeakWebSocketOptions class SpeakWebSocketClient: # pylint: disable=too-many-instance-attributes @@ -81,7 +81,7 @@ def __init__(self, config: DeepgramClientOptions): # pylint: disable=too-many-statements,too-many-branches def start( self, - options: Optional[Union[SpeakOptions, Dict]] = None, + options: Optional[Union[SpeakWebSocketOptions, Dict]] = None, addons: Optional[Dict] = None, headers: Optional[Dict] = None, members: Optional[Dict] = None, @@ -97,7 +97,7 @@ def start( self._logger.info("members: %s", members) self._logger.info("kwargs: %s", kwargs) - if isinstance(options, SpeakOptions) and not options.check(): + if isinstance(options, SpeakWebSocketOptions) and not options.check(): self._logger.error("options.check failed") self._logger.debug("SpeakStreamClient.start LEAVE") raise DeepgramError("Fatal text-to-speech options error") @@ -115,8 +115,8 @@ def start( else: self._kwargs = {} - if isinstance(options, SpeakOptions): - self._logger.info("SpeakOptions switching class -> dict") + if isinstance(options, SpeakWebSocketOptions): + self._logger.info("SpeakWebSocketOptions switching class -> dict") self._options = options.to_dict() elif options is not None: self._options = options diff --git a/deepgram/clients/speak/v1/websocket/options.py b/deepgram/clients/speak/v1/websocket/options.py new file mode 100644 index 00000000..a5d78752 --- /dev/null +++ b/deepgram/clients/speak/v1/websocket/options.py @@ -0,0 +1,7 @@ +# Copyright 2024 Deepgram SDK contributors. All Rights Reserved. +# Use of this source code is governed by a MIT license that can be found in the LICENSE file. +# SPDX-License-Identifier: MIT + +from ..options import SpeakOptions + +SpeakWebSocketOptions = SpeakOptions diff --git a/examples/text-to-speech/websocket/async_interactive/main.py b/examples/text-to-speech/websocket/async_interactive/main.py index 0962d3b7..7e44a8e9 100644 --- a/examples/text-to-speech/websocket/async_interactive/main.py +++ b/examples/text-to-speech/websocket/async_interactive/main.py @@ -18,9 +18,7 @@ async def main(): try: # example of setting up a client config. logging values: WARNING, VERBOSE, DEBUG, SPAM - config: DeepgramClientOptions = DeepgramClientOptions( - url="api.beta.deepgram.com", verbose=verboselogs.DEBUG - ) + config: DeepgramClientOptions = DeepgramClientOptions(verbose=verboselogs.DEBUG) deepgram: DeepgramClient = DeepgramClient("", config) # otherwise, use default config # deepgram: DeepgramClient = DeepgramClient() diff --git a/examples/text-to-speech/websocket/interactive/main.py b/examples/text-to-speech/websocket/interactive/main.py index 3a560213..fecdbd2d 100644 --- a/examples/text-to-speech/websocket/interactive/main.py +++ b/examples/text-to-speech/websocket/interactive/main.py @@ -24,9 +24,7 @@ def main(): try: # example of setting up a client config. logging values: WARNING, VERBOSE, DEBUG, SPAM - config: DeepgramClientOptions = DeepgramClientOptions( - url="api.beta.deepgram.com", verbose=verboselogs.DEBUG - ) + config: DeepgramClientOptions = DeepgramClientOptions(verbose=verboselogs.SPAM) deepgram: DeepgramClient = DeepgramClient("", config) # otherwise, use default config # deepgram: DeepgramClient = DeepgramClient()