generated from deepgram/oss-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathmain.py
45 lines (33 loc) · 1.14 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Copyright 2023-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
import asyncio
import os
from dotenv import load_dotenv
from deepgram import DeepgramClient, PrerecordedOptions
load_dotenv()
API_KEY = os.getenv("DEEPGRAM_API_KEY")
AUDIO_URL = {
"url": "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav"
}
options: PrerecordedOptions = PrerecordedOptions(
model="nova-2",
smart_format=True,
summarize="v2",
)
# STEP 1 Create a Deepgram client using the API key (optional - add config options)
deepgram: DeepgramClient = DeepgramClient(API_KEY)
# STEP 2 Call the transcribe_url method on the rest class
async def transcribe_url():
url_response = await deepgram.listen.asyncrest.v("1").transcribe_url(
AUDIO_URL, options
)
return url_response
async def main():
try:
response = await transcribe_url()
print(response.to_json(indent=4))
except Exception as e:
print(f"Exception: {e}")
if __name__ == "__main__":
asyncio.run(main())