Skip to content

Commit 2bf98aa

Browse files
jpvajdanaomi-lgbt
andauthored
SDK Readme Improvements (#530)
* initial improvements * fix mdlint errors * more more lint fixes * more updates * more updates * additional updates * simplifies example * final updates * Update README.md Co-authored-by: Naomi <accounts+github@nhcarrigan.com> --------- Co-authored-by: Naomi <accounts+github@nhcarrigan.com>
1 parent 052aadd commit 2bf98aa

File tree

8 files changed

+696
-198
lines changed

8 files changed

+696
-198
lines changed

README.md

Lines changed: 635 additions & 151 deletions
Large diffs are not rendered by default.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved.
2+
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
3+
# SPDX-License-Identifier: MIT
4+
5+
import os
6+
from dotenv import load_dotenv
7+
import logging
8+
from deepgram.utils import verboselogs
9+
from datetime import datetime
10+
import httpx
11+
12+
from deepgram import (
13+
DeepgramClient,
14+
DeepgramClientOptions,
15+
PrerecordedOptions,
16+
UrlSource,
17+
)
18+
19+
load_dotenv()
20+
21+
# URL to the audio file to transcribe
22+
AUDIO_URL = "https://dpgr.am/spacewalk.wav" # Replace with your audio URL
23+
24+
25+
def main():
26+
try:
27+
# STEP 1 Create a Deepgram client using the API key in the environment variables
28+
config: DeepgramClientOptions = DeepgramClientOptions(
29+
verbose=verboselogs.SPAM,
30+
)
31+
deepgram: DeepgramClient = DeepgramClient("", config)
32+
# OR use defaults
33+
# deepgram: DeepgramClient = DeepgramClient()
34+
35+
# STEP 2 Call the transcribe_url method on the rest class
36+
payload: UrlSource = {
37+
"url": AUDIO_URL,
38+
}
39+
40+
options: PrerecordedOptions = PrerecordedOptions(
41+
model="nova-3",
42+
smart_format=True,
43+
)
44+
45+
before = datetime.now()
46+
response = deepgram.listen.rest.v("1").transcribe_url(
47+
payload, options, timeout=httpx.Timeout(300.0, connect=10.0)
48+
)
49+
after = datetime.now()
50+
51+
print(response.to_json(indent=4))
52+
print("")
53+
difference = after - before
54+
print(f"time: {difference.seconds}")
55+
56+
except Exception as e:
57+
print(f"Exception: {e}")
58+
59+
60+
if __name__ == "__main__":
61+
main()

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

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)