diff --git a/deepgram/client.py b/deepgram/client.py index 46e5b6fe..7f8daf45 100644 --- a/deepgram/client.py +++ b/deepgram/client.py @@ -35,8 +35,6 @@ # speech-to-text from .clients import LiveClient, AsyncLiveClient # backward compat from .clients import ( - ListenRESTClient, - AsyncListenRESTClient, ListenWebSocketClient, AsyncListenWebSocketClient, ) @@ -62,6 +60,10 @@ from .clients import ( PreRecordedClient, AsyncPreRecordedClient, +) # backward compat +from .clients import ( + ListenRESTClient, + AsyncListenRESTClient, ) from .clients import ( ListenRESTOptions, diff --git a/examples/advanced/prerecorded/direct_invocation/main.py b/examples/advanced/rest/direct_invocation/main.py similarity index 78% rename from examples/advanced/prerecorded/direct_invocation/main.py rename to examples/advanced/rest/direct_invocation/main.py index 5d9201ce..452de4cb 100644 --- a/examples/advanced/prerecorded/direct_invocation/main.py +++ b/examples/advanced/rest/direct_invocation/main.py @@ -8,7 +8,7 @@ from deepgram.utils import verboselogs import traceback -from deepgram import ClientOptionsFromEnv, PrerecordedOptions, PreRecordedClient +from deepgram import ClientOptionsFromEnv, PrerecordedOptions, ListenRESTClient load_dotenv() @@ -19,13 +19,13 @@ def main(): try: - # STEP 1 Create a Deepgram PreRecordedClient using a specific config + # STEP 1 Create a Deepgram ListenRESTClient using a specific config # config: ClientOptionsFromEnv = ClientOptionsFromEnv( # verbose=verboselogs.NOTICE, # ) - # asyncClient: PreRecordedClient = PreRecordedClient(config) + # asyncClient: ListenRESTClient = ListenRESTClient(config) # OR just use the default config - asyncClient: PreRecordedClient = PreRecordedClient(ClientOptionsFromEnv()) + asyncClient: ListenRESTClient = ListenRESTClient(ClientOptionsFromEnv()) # STEP 2 Call the transcribe_url method on the prerecorded class options: PrerecordedOptions = PrerecordedOptions( diff --git a/examples/advanced/streaming/direct_invocation/main.py b/examples/advanced/websocket/direct_invocation/main.py similarity index 90% rename from examples/advanced/streaming/direct_invocation/main.py rename to examples/advanced/websocket/direct_invocation/main.py index 3cb6c947..47c6f2a8 100644 --- a/examples/advanced/streaming/direct_invocation/main.py +++ b/examples/advanced/websocket/direct_invocation/main.py @@ -9,7 +9,7 @@ import threading from deepgram import ( - LiveClient, + ListenWebSocketClient, ClientOptionsFromEnv, LiveTranscriptionEvents, LiveOptions, @@ -23,13 +23,15 @@ def main(): try: - # STEP 1 Create a Deepgram LiveClient using a specific config + # STEP 1 Create a Deepgram ListenWebSocketClient using a specific config # config: ClientOptionsFromEnv = ClientOptionsFromEnv( # verbose=verboselogs.DEBUG, options={"keepalive": "true"} # ) - # liveClient: LiveClient = LiveClient("", config) + # liveClient: ListenWebSocketClient = ListenWebSocketClient("", config) # OR just use the default config - liveClient: LiveClient = LiveClient(ClientOptionsFromEnv()) + liveClient: ListenWebSocketClient = ListenWebSocketClient( + ClientOptionsFromEnv() + ) def on_message(self, result, **kwargs): sentence = result.channel.alternatives[0].transcript diff --git a/examples/advanced/streaming/microphone_inheritance/README.md b/examples/advanced/websocket/microphone_inheritance/README.md similarity index 100% rename from examples/advanced/streaming/microphone_inheritance/README.md rename to examples/advanced/websocket/microphone_inheritance/README.md diff --git a/examples/advanced/streaming/microphone_inheritance/main.py b/examples/advanced/websocket/microphone_inheritance/main.py similarity index 96% rename from examples/advanced/streaming/microphone_inheritance/main.py rename to examples/advanced/websocket/microphone_inheritance/main.py index bc05e397..fedfcfbd 100644 --- a/examples/advanced/streaming/microphone_inheritance/main.py +++ b/examples/advanced/websocket/microphone_inheritance/main.py @@ -10,7 +10,7 @@ from deepgram import ( ClientOptionsFromEnv, LiveTranscriptionEvents, - LiveClient, + ListenWebSocketClient, LiveOptions, Microphone, LiveResultResponse, @@ -24,8 +24,8 @@ # more complex example -class MyLiveClient(LiveClient): - def __init__(self, config: LiveClient): +class MyLiveClient(ListenWebSocketClient): + def __init__(self, config: ListenWebSocketClient): super().__init__(config) super().on(LiveTranscriptionEvents.Transcript, self.on_message) super().on(LiveTranscriptionEvents.Metadata, self.on_metadata) diff --git a/examples/advanced/streaming/mute-microphone/main.py b/examples/advanced/websocket/mute-microphone/main.py similarity index 100% rename from examples/advanced/streaming/mute-microphone/main.py rename to examples/advanced/websocket/mute-microphone/main.py diff --git a/examples/speech-to-text/rest/async_url/main.py b/examples/speech-to-text/rest/async_url/main.py index ec9fd1e6..faae2756 100644 --- a/examples/speech-to-text/rest/async_url/main.py +++ b/examples/speech-to-text/rest/async_url/main.py @@ -25,9 +25,9 @@ deepgram: DeepgramClient = DeepgramClient(API_KEY) -# STEP 2 Call the transcribe_url method on the prerecorded class +# STEP 2 Call the transcribe_url method on the rest class async def transcribe_url(): - url_response = await deepgram.listen.asyncprerecorded.v("1").transcribe_url( + url_response = await deepgram.listen.asyncrest.v("1").transcribe_url( AUDIO_URL, options ) return url_response diff --git a/examples/speech-to-text/rest/callback/callback/main.py b/examples/speech-to-text/rest/callback/callback/main.py index 31fdd2f7..0a41fe35 100644 --- a/examples/speech-to-text/rest/callback/callback/main.py +++ b/examples/speech-to-text/rest/callback/callback/main.py @@ -33,7 +33,7 @@ def main(): deepgram: DeepgramClient = DeepgramClient("", config) - # STEP 2 Call the transcribe_file method on the prerecorded class + # STEP 2 Call the transcribe_file method on the rest class with open(AUDIO_FILE, "rb") as file: buffer_data = file.read() @@ -51,11 +51,11 @@ def main(): utterances=True, ) - response = deepgram.listen.prerecorded.v("1").transcribe_file_callback( + response = deepgram.listen.rest.v("1").transcribe_file_callback( payload, CALL_BACK_URL, options=options ) # For URL hosted audio files, comment out the above and uncomment the below - # response = deepgram.listen.prerecorded.v("1").transcribe_url_callback( + # response = deepgram.listen.rest.v("1").transcribe_url_callback( # payload, CALL_BACK_URL, options=options # ) print(response.to_json(indent=4)) diff --git a/examples/speech-to-text/rest/file/main.py b/examples/speech-to-text/rest/file/main.py index 7191e2d2..5cc1080c 100644 --- a/examples/speech-to-text/rest/file/main.py +++ b/examples/speech-to-text/rest/file/main.py @@ -31,7 +31,7 @@ def main(): # OR use defaults # deepgram: DeepgramClient = DeepgramClient() - # STEP 2 Call the transcribe_file method on the prerecorded class + # STEP 2 Call the transcribe_file method on the rest class with open(AUDIO_FILE, "rb") as file: buffer_data = file.read() @@ -48,7 +48,7 @@ def main(): ) before = datetime.now() - response = deepgram.listen.prerecorded.v("1").transcribe_file( + response = deepgram.listen.rest.v("1").transcribe_file( payload, options, timeout=httpx.Timeout(300.0, connect=10.0) ) after = datetime.now() diff --git a/examples/speech-to-text/rest/intent/main.py b/examples/speech-to-text/rest/intent/main.py index 940c19ba..df80e7b0 100644 --- a/examples/speech-to-text/rest/intent/main.py +++ b/examples/speech-to-text/rest/intent/main.py @@ -30,7 +30,7 @@ def main(): # OR use defaults deepgram: DeepgramClient = DeepgramClient() - # STEP 2 Call the transcribe_file method on the prerecorded class + # STEP 2 Call the transcribe_file method on the rest class with open(AUDIO_FILE, "rb") as file: buffer_data = file.read() @@ -47,7 +47,7 @@ def main(): ) before = datetime.now() - response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options) + response = deepgram.listen.rest.v("1").transcribe_file(payload, options) after = datetime.now() print(response.to_json(indent=4)) diff --git a/examples/speech-to-text/rest/legacy_dict_url/main.py b/examples/speech-to-text/rest/legacy_dict_url/main.py index 76b471f7..858fb947 100644 --- a/examples/speech-to-text/rest/legacy_dict_url/main.py +++ b/examples/speech-to-text/rest/legacy_dict_url/main.py @@ -25,12 +25,12 @@ def main(): # STEP 1 Create a Deepgram client using the API key from environment variables deepgram = DeepgramClient("", ClientOptionsFromEnv()) - # STEP 2 Call the transcribe_url method on the prerecorded class + # STEP 2 Call the transcribe_url method on the rest class options = { "mode": "nova-2", "smart_format": True, } - response = deepgram.listen.prerecorded.v("1").transcribe_url(AUDIO_URL, options) + response = deepgram.listen.rest.v("1").transcribe_url(AUDIO_URL, options) print(f"response: {response}\n\n") # print(f"metadata: {response['metadata']}\n\n") # print( diff --git a/examples/speech-to-text/rest/sentiment/main.py b/examples/speech-to-text/rest/sentiment/main.py index 74e7e256..feac70ee 100644 --- a/examples/speech-to-text/rest/sentiment/main.py +++ b/examples/speech-to-text/rest/sentiment/main.py @@ -30,7 +30,7 @@ def main(): # OR use defaults deepgram: DeepgramClient = DeepgramClient() - # STEP 2 Call the transcribe_file method on the prerecorded class + # STEP 2 Call the transcribe_file method on the rest class with open(AUDIO_FILE, "rb") as file: buffer_data = file.read() @@ -47,7 +47,7 @@ def main(): ) before = datetime.now() - response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options) + response = deepgram.listen.rest.v("1").transcribe_file(payload, options) after = datetime.now() print(response.to_json(indent=4)) diff --git a/examples/speech-to-text/rest/stream_file/main.py b/examples/speech-to-text/rest/stream_file/main.py index 92e31496..434a8277 100644 --- a/examples/speech-to-text/rest/stream_file/main.py +++ b/examples/speech-to-text/rest/stream_file/main.py @@ -33,21 +33,16 @@ def main(): # OR use defaults # deepgram = DeepgramClient() - # STEP 2 Call the transcribe_file method on the prerecorded class - stream = open(AUDIO_FILE, "rb") - - payload: StreamSource = { - "stream": stream, - } - - options = PrerecordedOptions( - model="nova-2", - ) - - response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options) - print(response.to_json(indent=4)) - - stream.close() + # STEP 2 Call the transcribe_file method on the rest class + with open(AUDIO_FILE, "rb") as stream: + payload: StreamSource = { + "stream": stream, + } + options = PrerecordedOptions( + model="nova-2", + ) + response = deepgram.listen.rest.v("1").transcribe_file(payload, options) + print(response.to_json(indent=4)) except Exception as e: print(f"Exception: {e}") diff --git a/examples/speech-to-text/rest/summary/main.py b/examples/speech-to-text/rest/summary/main.py index b3c379af..e5d05af1 100644 --- a/examples/speech-to-text/rest/summary/main.py +++ b/examples/speech-to-text/rest/summary/main.py @@ -30,7 +30,7 @@ def main(): # OR use defaults deepgram: DeepgramClient = DeepgramClient() - # STEP 2 Call the transcribe_file method on the prerecorded class + # STEP 2 Call the transcribe_file method on the rest class with open(AUDIO_FILE, "rb") as file: buffer_data = file.read() @@ -47,7 +47,7 @@ def main(): ) before = datetime.now() - response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options) + response = deepgram.listen.rest.v("1").transcribe_file(payload, options) after = datetime.now() print(response.to_json(indent=4)) diff --git a/examples/speech-to-text/rest/topic/main.py b/examples/speech-to-text/rest/topic/main.py index 0b7e4295..68ad728d 100644 --- a/examples/speech-to-text/rest/topic/main.py +++ b/examples/speech-to-text/rest/topic/main.py @@ -30,7 +30,7 @@ def main(): # OR use defaults deepgram: DeepgramClient = DeepgramClient() - # STEP 2 Call the transcribe_file method on the prerecorded class + # STEP 2 Call the transcribe_file method on the rest class with open(AUDIO_FILE, "rb") as file: buffer_data = file.read() @@ -47,7 +47,7 @@ def main(): ) before = datetime.now() - response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options) + response = deepgram.listen.rest.v("1").transcribe_file(payload, options) after = datetime.now() print(response.to_json(indent=4)) diff --git a/examples/speech-to-text/rest/url/main.py b/examples/speech-to-text/rest/url/main.py index dccc1420..85ebe16d 100644 --- a/examples/speech-to-text/rest/url/main.py +++ b/examples/speech-to-text/rest/url/main.py @@ -25,12 +25,12 @@ def main(): # STEP 1 Create a Deepgram client using the API key from environment variables deepgram: DeepgramClient = DeepgramClient("", ClientOptionsFromEnv()) - # STEP 2 Call the transcribe_url method on the prerecorded class + # STEP 2 Call the transcribe_url method on the rest class options: PrerecordedOptions = PrerecordedOptions( model="nova-2", smart_format=True, ) - response = deepgram.listen.prerecorded.v("1").transcribe_url(AUDIO_URL, options) + response = deepgram.listen.rest.v("1").transcribe_url(AUDIO_URL, options) print(f"response: {response}\n\n") # print(f"metadata: {response['metadata']}\n\n") # print( diff --git a/examples/speech-to-text/websocket/async_http/main.py b/examples/speech-to-text/websocket/async_http/main.py index a3c33059..cd5a20ec 100644 --- a/examples/speech-to-text/websocket/async_http/main.py +++ b/examples/speech-to-text/websocket/async_http/main.py @@ -44,7 +44,7 @@ async def main(): lambda: asyncio.create_task(shutdown(signal, loop, dg_connection)), ) - dg_connection = deepgram.listen.asynclive.v("1") + dg_connection = deepgram.listen.asyncwebsocket.v("1") async def on_open(self, open, **kwargs): print(f"\n\n{open}\n\n") diff --git a/examples/speech-to-text/websocket/async_microphone/main.py b/examples/speech-to-text/websocket/async_microphone/main.py index ce0d2b19..07554dae 100644 --- a/examples/speech-to-text/websocket/async_microphone/main.py +++ b/examples/speech-to-text/websocket/async_microphone/main.py @@ -43,10 +43,10 @@ async def main(): # otherwise, use default config # deepgram: DeepgramClient = DeepgramClient() - dg_connection = deepgram.listen.asynclive.v("1") + dg_connection = deepgram.listen.asyncwebsocket.v("1") async def on_open(self, open, **kwargs): - print(f"Connection Open") + print("Connection Open") async def on_message(self, result, **kwargs): global is_finals @@ -75,10 +75,10 @@ async def on_metadata(self, metadata, **kwargs): print(f"Metadata: {metadata}") async def on_speech_started(self, speech_started, **kwargs): - print(f"Speech Started") + print("Speech Started") async def on_utterance_end(self, utterance_end, **kwargs): - print(f"Utterance End") + print("Utterance End") global is_finals if len(is_finals) > 0: utterance = " ".join(is_finals) @@ -86,7 +86,7 @@ async def on_utterance_end(self, utterance_end, **kwargs): is_finals = [] async def on_close(self, close, **kwargs): - print(f"Connection Closed") + print("Connection Closed") async def on_error(self, error, **kwargs): print(f"Handled Error: {error}") diff --git a/examples/speech-to-text/websocket/http/main.py b/examples/speech-to-text/websocket/http/main.py index 1a3f5f4b..f26cec72 100644 --- a/examples/speech-to-text/websocket/http/main.py +++ b/examples/speech-to-text/websocket/http/main.py @@ -30,7 +30,7 @@ def main(): deepgram: DeepgramClient = DeepgramClient() # Create a websocket connection to Deepgram - dg_connection = deepgram.listen.live.v("1") + dg_connection = deepgram.listen.websocket.v("1") def on_open(self, open, **kwargs): print(f"\n\n{open}\n\n") diff --git a/examples/speech-to-text/websocket/legacy_dict_microphone/main.py b/examples/speech-to-text/websocket/legacy_dict_microphone/main.py index 2c95f931..e1023243 100644 --- a/examples/speech-to-text/websocket/legacy_dict_microphone/main.py +++ b/examples/speech-to-text/websocket/legacy_dict_microphone/main.py @@ -29,7 +29,7 @@ def main(): # otherwise, use default config deepgram = DeepgramClient() - dg_connection = deepgram.listen.live.v("1") + dg_connection = deepgram.listen.websocket.v("1") def on_open(self, open, **kwargs): print(f"\n\n{open}\n\n") diff --git a/examples/speech-to-text/websocket/microphone/main.py b/examples/speech-to-text/websocket/microphone/main.py index 083aaf42..576dfe01 100644 --- a/examples/speech-to-text/websocket/microphone/main.py +++ b/examples/speech-to-text/websocket/microphone/main.py @@ -31,10 +31,10 @@ def main(): # otherwise, use default config deepgram: DeepgramClient = DeepgramClient() - dg_connection = deepgram.listen.live.v("1") + dg_connection = deepgram.listen.websocket.v("1") def on_open(self, open, **kwargs): - print(f"Connection Open") + print("Connection Open") def on_message(self, result, **kwargs): global is_finals @@ -63,10 +63,10 @@ def on_metadata(self, metadata, **kwargs): print(f"Metadata: {metadata}") def on_speech_started(self, speech_started, **kwargs): - print(f"Speech Started") + print("Speech Started") def on_utterance_end(self, utterance_end, **kwargs): - print(f"Utterance End") + print("Utterance End") global is_finals if len(is_finals) > 0: utterance = " ".join(is_finals) @@ -74,7 +74,7 @@ def on_utterance_end(self, utterance_end, **kwargs): is_finals = [] def on_close(self, close, **kwargs): - print(f"Connection Closed") + print("Connection Closed") def on_error(self, error, **kwargs): print(f"Handled Error: {error}") diff --git a/examples/text-to-speech/rest/file/async_hello_world/main.py b/examples/text-to-speech/rest/file/async_hello_world/main.py index e24023f7..bc0f4411 100644 --- a/examples/text-to-speech/rest/file/async_hello_world/main.py +++ b/examples/text-to-speech/rest/file/async_hello_world/main.py @@ -29,7 +29,7 @@ async def main(): model="aura-asteria-en", ) - response = await deepgram.asyncspeak.v("1").save( + response = await deepgram.speak.asyncrest.v("1").save( filename, SPEAK_OPTIONS, options ) print(response.to_json(indent=4)) diff --git a/examples/text-to-speech/rest/file/hello_world/main.py b/examples/text-to-speech/rest/file/hello_world/main.py index c5b29557..0101140a 100644 --- a/examples/text-to-speech/rest/file/hello_world/main.py +++ b/examples/text-to-speech/rest/file/hello_world/main.py @@ -31,7 +31,7 @@ def main(): model="aura-asteria-en", ) - response = deepgram.speak.v("1").save(filename, SPEAK_OPTIONS, options) + response = deepgram.speak.rest.v("1").save(filename, SPEAK_OPTIONS, options) print(response.to_json(indent=4)) except Exception as e: diff --git a/examples/text-to-speech/rest/file/hello_world_new/main.py b/examples/text-to-speech/rest/file/hello_world_new/main.py deleted file mode 100644 index 96254593..00000000 --- a/examples/text-to-speech/rest/file/hello_world_new/main.py +++ /dev/null @@ -1,41 +0,0 @@ -# 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 dotenv import load_dotenv -import logging -from deepgram.utils import verboselogs - -from deepgram import ( - DeepgramClient, - ClientOptionsFromEnv, - SpeakOptions, -) - -load_dotenv() - -SPEAK_OPTIONS = {"text": "Hello world!"} -filename = "test.mp3" - - -def main(): - try: - # STEP 1 Create a Deepgram client using the API key from environment variables - deepgram = DeepgramClient( - api_key="", config=ClientOptionsFromEnv(verbose=verboselogs.SPAM) - ) - - # STEP 2 Call the save method on the speak property - options = SpeakOptions( - model="aura-asteria-en", - ) - - response = deepgram.speak.rest.v("1").save(filename, SPEAK_OPTIONS, options) - print(response.to_json(indent=4)) - - except Exception as e: - print(f"Exception: {e}") - - -if __name__ == "__main__": - main() diff --git a/examples/text-to-speech/rest/file/legacy_dict_hello_world/main.py b/examples/text-to-speech/rest/file/legacy_dict_hello_world/main.py index 74a2a8e0..939495b3 100644 --- a/examples/text-to-speech/rest/file/legacy_dict_hello_world/main.py +++ b/examples/text-to-speech/rest/file/legacy_dict_hello_world/main.py @@ -29,7 +29,7 @@ def main(): "model": "aura-asteria-en", } - response = deepgram.speak.v("1").save(filename, SPEAK_OPTIONS, options) + response = deepgram.speak.rest.v("1").save(filename, SPEAK_OPTIONS, options) print(response.to_json(indent=4)) except Exception as e: diff --git a/examples/text-to-speech/rest/file/woodchuck/main.py b/examples/text-to-speech/rest/file/woodchuck/main.py index 5358de0c..54f6badc 100644 --- a/examples/text-to-speech/rest/file/woodchuck/main.py +++ b/examples/text-to-speech/rest/file/woodchuck/main.py @@ -31,7 +31,7 @@ def main(): model="aura-asteria-en", ) - response = deepgram.speak.v("1").save(filename, SPEAK_OPTIONS, options) + response = deepgram.speak.rest.v("1").save(filename, SPEAK_OPTIONS, options) print(response.to_json(indent=4)) except Exception as e: diff --git a/examples/text-to-speech/websocket/interactive/main.py b/examples/text-to-speech/websocket/interactive/main.py index fecdbd2d..3082a09c 100644 --- a/examples/text-to-speech/websocket/interactive/main.py +++ b/examples/text-to-speech/websocket/interactive/main.py @@ -24,7 +24,7 @@ def main(): try: # example of setting up a client config. logging values: WARNING, VERBOSE, DEBUG, SPAM - config: DeepgramClientOptions = DeepgramClientOptions(verbose=verboselogs.SPAM) + config: DeepgramClientOptions = DeepgramClientOptions(verbose=verboselogs.DEBUG) deepgram: DeepgramClient = DeepgramClient("", config) # otherwise, use default config # deepgram: DeepgramClient = DeepgramClient()