Skip to content

Commit

Permalink
Update Examples Using Latest Class Names
Browse files Browse the repository at this point in the history
  • Loading branch information
davidvonthenen committed Jul 9, 2024
1 parent e8ef6b9 commit 8f95024
Show file tree
Hide file tree
Showing 25 changed files with 43 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import threading

from deepgram import (
LiveClient,
ListenWebSocketClient,
ClientOptionsFromEnv,
LiveTranscriptionEvents,
LiveOptions,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from deepgram import (
ClientOptionsFromEnv,
LiveTranscriptionEvents,
LiveClient,
ListenWebSocketClient,
LiveOptions,
Microphone,
LiveResultResponse,
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions examples/speech-to-text/rest/async_url/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions examples/speech-to-text/rest/callback/callback/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions examples/speech-to-text/rest/file/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions examples/speech-to-text/rest/intent/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions examples/speech-to-text/rest/legacy_dict_url/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions examples/speech-to-text/rest/sentiment/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions examples/speech-to-text/rest/stream_file/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def main():
# OR use defaults
# deepgram = DeepgramClient()

# STEP 2 Call the transcribe_file method on the prerecorded class
# STEP 2 Call the transcribe_file method on the rest class
stream = open(AUDIO_FILE, "rb")

payload: StreamSource = {
Expand All @@ -44,7 +44,7 @@ def main():
model="nova-2",
)

response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options)
response = deepgram.listen.rest.v("1").transcribe_file(payload, options)
print(response.to_json(indent=4))

stream.close()
Expand Down
4 changes: 2 additions & 2 deletions examples/speech-to-text/rest/summary/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions examples/speech-to-text/rest/topic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions examples/speech-to-text/rest/url/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion examples/speech-to-text/websocket/async_http/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion examples/speech-to-text/websocket/async_microphone/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ 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")
Expand Down
2 changes: 1 addition & 1 deletion examples/speech-to-text/websocket/http/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion examples/speech-to-text/websocket/microphone/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ 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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion examples/text-to-speech/rest/file/hello_world/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
41 changes: 0 additions & 41 deletions examples/text-to-speech/rest/file/hello_world_new/main.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/text-to-speech/rest/file/woodchuck/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8f95024

Please sign in to comment.