generated from deepgram/oss-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 65
/
main.py
52 lines (42 loc) · 1.38 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
46
47
48
49
50
51
52
# 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 os
from dotenv import load_dotenv
import logging
from deepgram.utils import verboselogs
from datetime import datetime, timedelta
from io import BufferedReader
from deepgram import DeepgramClientOptions
import logging
from deepgram import (
DeepgramClient,
DeepgramClientOptions,
StreamSource,
PrerecordedOptions,
)
load_dotenv()
AUDIO_FILE = "preamble.wav"
def main():
try:
# STEP 1 Create a Deepgram client using the API key in the environment variables
config = DeepgramClientOptions(
verbose=verboselogs.SPAM,
)
deepgram = DeepgramClient("", config)
# OR use defaults
# deepgram = DeepgramClient()
# 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}")
if __name__ == "__main__":
main()