Skip to content

Commit 4bfadf5

Browse files
Merge pull request #432 from dvonthenen/update-examples-latest-namespaces
Update examples latest namespaces
2 parents 40d1239 + 7e39230 commit 4bfadf5

File tree

27 files changed

+64
-106
lines changed

27 files changed

+64
-106
lines changed

deepgram/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
# speech-to-text
3636
from .clients import LiveClient, AsyncLiveClient # backward compat
3737
from .clients import (
38-
ListenRESTClient,
39-
AsyncListenRESTClient,
4038
ListenWebSocketClient,
4139
AsyncListenWebSocketClient,
4240
)
@@ -62,6 +60,10 @@
6260
from .clients import (
6361
PreRecordedClient,
6462
AsyncPreRecordedClient,
63+
) # backward compat
64+
from .clients import (
65+
ListenRESTClient,
66+
AsyncListenRESTClient,
6567
)
6668
from .clients import (
6769
ListenRESTOptions,

examples/advanced/prerecorded/direct_invocation/main.py renamed to examples/advanced/rest/direct_invocation/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from deepgram.utils import verboselogs
99
import traceback
1010

11-
from deepgram import ClientOptionsFromEnv, PrerecordedOptions, PreRecordedClient
11+
from deepgram import ClientOptionsFromEnv, PrerecordedOptions, ListenRESTClient
1212

1313
load_dotenv()
1414

@@ -19,13 +19,13 @@
1919

2020
def main():
2121
try:
22-
# STEP 1 Create a Deepgram PreRecordedClient using a specific config
22+
# STEP 1 Create a Deepgram ListenRESTClient using a specific config
2323
# config: ClientOptionsFromEnv = ClientOptionsFromEnv(
2424
# verbose=verboselogs.NOTICE,
2525
# )
26-
# asyncClient: PreRecordedClient = PreRecordedClient(config)
26+
# asyncClient: ListenRESTClient = ListenRESTClient(config)
2727
# OR just use the default config
28-
asyncClient: PreRecordedClient = PreRecordedClient(ClientOptionsFromEnv())
28+
asyncClient: ListenRESTClient = ListenRESTClient(ClientOptionsFromEnv())
2929

3030
# STEP 2 Call the transcribe_url method on the prerecorded class
3131
options: PrerecordedOptions = PrerecordedOptions(

examples/advanced/streaming/direct_invocation/main.py renamed to examples/advanced/websocket/direct_invocation/main.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import threading
1010

1111
from deepgram import (
12-
LiveClient,
12+
ListenWebSocketClient,
1313
ClientOptionsFromEnv,
1414
LiveTranscriptionEvents,
1515
LiveOptions,
@@ -23,13 +23,15 @@
2323

2424
def main():
2525
try:
26-
# STEP 1 Create a Deepgram LiveClient using a specific config
26+
# STEP 1 Create a Deepgram ListenWebSocketClient using a specific config
2727
# config: ClientOptionsFromEnv = ClientOptionsFromEnv(
2828
# verbose=verboselogs.DEBUG, options={"keepalive": "true"}
2929
# )
30-
# liveClient: LiveClient = LiveClient("", config)
30+
# liveClient: ListenWebSocketClient = ListenWebSocketClient("", config)
3131
# OR just use the default config
32-
liveClient: LiveClient = LiveClient(ClientOptionsFromEnv())
32+
liveClient: ListenWebSocketClient = ListenWebSocketClient(
33+
ClientOptionsFromEnv()
34+
)
3335

3436
def on_message(self, result, **kwargs):
3537
sentence = result.channel.alternatives[0].transcript

examples/advanced/streaming/microphone_inheritance/main.py renamed to examples/advanced/websocket/microphone_inheritance/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from deepgram import (
1111
ClientOptionsFromEnv,
1212
LiveTranscriptionEvents,
13-
LiveClient,
13+
ListenWebSocketClient,
1414
LiveOptions,
1515
Microphone,
1616
LiveResultResponse,
@@ -24,8 +24,8 @@
2424

2525

2626
# more complex example
27-
class MyLiveClient(LiveClient):
28-
def __init__(self, config: LiveClient):
27+
class MyLiveClient(ListenWebSocketClient):
28+
def __init__(self, config: ListenWebSocketClient):
2929
super().__init__(config)
3030
super().on(LiveTranscriptionEvents.Transcript, self.on_message)
3131
super().on(LiveTranscriptionEvents.Metadata, self.on_metadata)

examples/speech-to-text/rest/async_url/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
deepgram: DeepgramClient = DeepgramClient(API_KEY)
2626

2727

28-
# STEP 2 Call the transcribe_url method on the prerecorded class
28+
# STEP 2 Call the transcribe_url method on the rest class
2929
async def transcribe_url():
30-
url_response = await deepgram.listen.asyncprerecorded.v("1").transcribe_url(
30+
url_response = await deepgram.listen.asyncrest.v("1").transcribe_url(
3131
AUDIO_URL, options
3232
)
3333
return url_response

examples/speech-to-text/rest/callback/callback/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def main():
3333

3434
deepgram: DeepgramClient = DeepgramClient("", config)
3535

36-
# STEP 2 Call the transcribe_file method on the prerecorded class
36+
# STEP 2 Call the transcribe_file method on the rest class
3737
with open(AUDIO_FILE, "rb") as file:
3838
buffer_data = file.read()
3939

@@ -51,11 +51,11 @@ def main():
5151
utterances=True,
5252
)
5353

54-
response = deepgram.listen.prerecorded.v("1").transcribe_file_callback(
54+
response = deepgram.listen.rest.v("1").transcribe_file_callback(
5555
payload, CALL_BACK_URL, options=options
5656
)
5757
# For URL hosted audio files, comment out the above and uncomment the below
58-
# response = deepgram.listen.prerecorded.v("1").transcribe_url_callback(
58+
# response = deepgram.listen.rest.v("1").transcribe_url_callback(
5959
# payload, CALL_BACK_URL, options=options
6060
# )
6161
print(response.to_json(indent=4))

examples/speech-to-text/rest/file/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def main():
3131
# OR use defaults
3232
# deepgram: DeepgramClient = DeepgramClient()
3333

34-
# STEP 2 Call the transcribe_file method on the prerecorded class
34+
# STEP 2 Call the transcribe_file method on the rest class
3535
with open(AUDIO_FILE, "rb") as file:
3636
buffer_data = file.read()
3737

@@ -48,7 +48,7 @@ def main():
4848
)
4949

5050
before = datetime.now()
51-
response = deepgram.listen.prerecorded.v("1").transcribe_file(
51+
response = deepgram.listen.rest.v("1").transcribe_file(
5252
payload, options, timeout=httpx.Timeout(300.0, connect=10.0)
5353
)
5454
after = datetime.now()

examples/speech-to-text/rest/intent/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def main():
3030
# OR use defaults
3131
deepgram: DeepgramClient = DeepgramClient()
3232

33-
# STEP 2 Call the transcribe_file method on the prerecorded class
33+
# STEP 2 Call the transcribe_file method on the rest class
3434
with open(AUDIO_FILE, "rb") as file:
3535
buffer_data = file.read()
3636

@@ -47,7 +47,7 @@ def main():
4747
)
4848

4949
before = datetime.now()
50-
response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options)
50+
response = deepgram.listen.rest.v("1").transcribe_file(payload, options)
5151
after = datetime.now()
5252

5353
print(response.to_json(indent=4))

examples/speech-to-text/rest/legacy_dict_url/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ def main():
2525
# STEP 1 Create a Deepgram client using the API key from environment variables
2626
deepgram = DeepgramClient("", ClientOptionsFromEnv())
2727

28-
# STEP 2 Call the transcribe_url method on the prerecorded class
28+
# STEP 2 Call the transcribe_url method on the rest class
2929
options = {
3030
"mode": "nova-2",
3131
"smart_format": True,
3232
}
33-
response = deepgram.listen.prerecorded.v("1").transcribe_url(AUDIO_URL, options)
33+
response = deepgram.listen.rest.v("1").transcribe_url(AUDIO_URL, options)
3434
print(f"response: {response}\n\n")
3535
# print(f"metadata: {response['metadata']}\n\n")
3636
# print(

examples/speech-to-text/rest/sentiment/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def main():
3030
# OR use defaults
3131
deepgram: DeepgramClient = DeepgramClient()
3232

33-
# STEP 2 Call the transcribe_file method on the prerecorded class
33+
# STEP 2 Call the transcribe_file method on the rest class
3434
with open(AUDIO_FILE, "rb") as file:
3535
buffer_data = file.read()
3636

@@ -47,7 +47,7 @@ def main():
4747
)
4848

4949
before = datetime.now()
50-
response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options)
50+
response = deepgram.listen.rest.v("1").transcribe_file(payload, options)
5151
after = datetime.now()
5252

5353
print(response.to_json(indent=4))

examples/speech-to-text/rest/stream_file/main.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,16 @@ def main():
3333
# OR use defaults
3434
# deepgram = DeepgramClient()
3535

36-
# STEP 2 Call the transcribe_file method on the prerecorded class
37-
stream = open(AUDIO_FILE, "rb")
38-
39-
payload: StreamSource = {
40-
"stream": stream,
41-
}
42-
43-
options = PrerecordedOptions(
44-
model="nova-2",
45-
)
46-
47-
response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options)
48-
print(response.to_json(indent=4))
49-
50-
stream.close()
36+
# STEP 2 Call the transcribe_file method on the rest class
37+
with open(AUDIO_FILE, "rb") as stream:
38+
payload: StreamSource = {
39+
"stream": stream,
40+
}
41+
options = PrerecordedOptions(
42+
model="nova-2",
43+
)
44+
response = deepgram.listen.rest.v("1").transcribe_file(payload, options)
45+
print(response.to_json(indent=4))
5146

5247
except Exception as e:
5348
print(f"Exception: {e}")

examples/speech-to-text/rest/summary/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def main():
3030
# OR use defaults
3131
deepgram: DeepgramClient = DeepgramClient()
3232

33-
# STEP 2 Call the transcribe_file method on the prerecorded class
33+
# STEP 2 Call the transcribe_file method on the rest class
3434
with open(AUDIO_FILE, "rb") as file:
3535
buffer_data = file.read()
3636

@@ -47,7 +47,7 @@ def main():
4747
)
4848

4949
before = datetime.now()
50-
response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options)
50+
response = deepgram.listen.rest.v("1").transcribe_file(payload, options)
5151
after = datetime.now()
5252

5353
print(response.to_json(indent=4))

examples/speech-to-text/rest/topic/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def main():
3030
# OR use defaults
3131
deepgram: DeepgramClient = DeepgramClient()
3232

33-
# STEP 2 Call the transcribe_file method on the prerecorded class
33+
# STEP 2 Call the transcribe_file method on the rest class
3434
with open(AUDIO_FILE, "rb") as file:
3535
buffer_data = file.read()
3636

@@ -47,7 +47,7 @@ def main():
4747
)
4848

4949
before = datetime.now()
50-
response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options)
50+
response = deepgram.listen.rest.v("1").transcribe_file(payload, options)
5151
after = datetime.now()
5252

5353
print(response.to_json(indent=4))

examples/speech-to-text/rest/url/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ def main():
2525
# STEP 1 Create a Deepgram client using the API key from environment variables
2626
deepgram: DeepgramClient = DeepgramClient("", ClientOptionsFromEnv())
2727

28-
# STEP 2 Call the transcribe_url method on the prerecorded class
28+
# STEP 2 Call the transcribe_url method on the rest class
2929
options: PrerecordedOptions = PrerecordedOptions(
3030
model="nova-2",
3131
smart_format=True,
3232
)
33-
response = deepgram.listen.prerecorded.v("1").transcribe_url(AUDIO_URL, options)
33+
response = deepgram.listen.rest.v("1").transcribe_url(AUDIO_URL, options)
3434
print(f"response: {response}\n\n")
3535
# print(f"metadata: {response['metadata']}\n\n")
3636
# print(

examples/speech-to-text/websocket/async_http/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async def main():
4444
lambda: asyncio.create_task(shutdown(signal, loop, dg_connection)),
4545
)
4646

47-
dg_connection = deepgram.listen.asynclive.v("1")
47+
dg_connection = deepgram.listen.asyncwebsocket.v("1")
4848

4949
async def on_open(self, open, **kwargs):
5050
print(f"\n\n{open}\n\n")

examples/speech-to-text/websocket/async_microphone/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ async def main():
4343
# otherwise, use default config
4444
# deepgram: DeepgramClient = DeepgramClient()
4545

46-
dg_connection = deepgram.listen.asynclive.v("1")
46+
dg_connection = deepgram.listen.asyncwebsocket.v("1")
4747

4848
async def on_open(self, open, **kwargs):
49-
print(f"Connection Open")
49+
print("Connection Open")
5050

5151
async def on_message(self, result, **kwargs):
5252
global is_finals
@@ -75,18 +75,18 @@ async def on_metadata(self, metadata, **kwargs):
7575
print(f"Metadata: {metadata}")
7676

7777
async def on_speech_started(self, speech_started, **kwargs):
78-
print(f"Speech Started")
78+
print("Speech Started")
7979

8080
async def on_utterance_end(self, utterance_end, **kwargs):
81-
print(f"Utterance End")
81+
print("Utterance End")
8282
global is_finals
8383
if len(is_finals) > 0:
8484
utterance = " ".join(is_finals)
8585
print(f"Utterance End: {utterance}")
8686
is_finals = []
8787

8888
async def on_close(self, close, **kwargs):
89-
print(f"Connection Closed")
89+
print("Connection Closed")
9090

9191
async def on_error(self, error, **kwargs):
9292
print(f"Handled Error: {error}")

examples/speech-to-text/websocket/http/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def main():
3030
deepgram: DeepgramClient = DeepgramClient()
3131

3232
# Create a websocket connection to Deepgram
33-
dg_connection = deepgram.listen.live.v("1")
33+
dg_connection = deepgram.listen.websocket.v("1")
3434

3535
def on_open(self, open, **kwargs):
3636
print(f"\n\n{open}\n\n")

examples/speech-to-text/websocket/legacy_dict_microphone/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def main():
2929
# otherwise, use default config
3030
deepgram = DeepgramClient()
3131

32-
dg_connection = deepgram.listen.live.v("1")
32+
dg_connection = deepgram.listen.websocket.v("1")
3333

3434
def on_open(self, open, **kwargs):
3535
print(f"\n\n{open}\n\n")

examples/speech-to-text/websocket/microphone/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ def main():
3131
# otherwise, use default config
3232
deepgram: DeepgramClient = DeepgramClient()
3333

34-
dg_connection = deepgram.listen.live.v("1")
34+
dg_connection = deepgram.listen.websocket.v("1")
3535

3636
def on_open(self, open, **kwargs):
37-
print(f"Connection Open")
37+
print("Connection Open")
3838

3939
def on_message(self, result, **kwargs):
4040
global is_finals
@@ -63,18 +63,18 @@ def on_metadata(self, metadata, **kwargs):
6363
print(f"Metadata: {metadata}")
6464

6565
def on_speech_started(self, speech_started, **kwargs):
66-
print(f"Speech Started")
66+
print("Speech Started")
6767

6868
def on_utterance_end(self, utterance_end, **kwargs):
69-
print(f"Utterance End")
69+
print("Utterance End")
7070
global is_finals
7171
if len(is_finals) > 0:
7272
utterance = " ".join(is_finals)
7373
print(f"Utterance End: {utterance}")
7474
is_finals = []
7575

7676
def on_close(self, close, **kwargs):
77-
print(f"Connection Closed")
77+
print("Connection Closed")
7878

7979
def on_error(self, error, **kwargs):
8080
print(f"Handled Error: {error}")

examples/text-to-speech/rest/file/async_hello_world/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async def main():
2929
model="aura-asteria-en",
3030
)
3131

32-
response = await deepgram.asyncspeak.v("1").save(
32+
response = await deepgram.speak.asyncrest.v("1").save(
3333
filename, SPEAK_OPTIONS, options
3434
)
3535
print(response.to_json(indent=4))

examples/text-to-speech/rest/file/hello_world/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def main():
3131
model="aura-asteria-en",
3232
)
3333

34-
response = deepgram.speak.v("1").save(filename, SPEAK_OPTIONS, options)
34+
response = deepgram.speak.rest.v("1").save(filename, SPEAK_OPTIONS, options)
3535
print(response.to_json(indent=4))
3636

3737
except Exception as e:

0 commit comments

Comments
 (0)