-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeepgramAPI.py
32 lines (25 loc) · 896 Bytes
/
deepgramAPI.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
from deepgram import Deepgram
import asyncio, json, os
def test():
dg_key = '7f065218f997c7ae17151100cb616c59a281a793'
dg = Deepgram(dg_key)
MIMETYPE = 'wav'
DIRECTORY = 'audio'
audio_file = 'combined.wav'
options = {
"punctuate": True,
"model": 'general',
"tier": 'enhanced'
}
with open(f"{DIRECTORY}/{audio_file}", "rb") as f:
source = {"buffer": f, "mimetype":'audio/'+MIMETYPE}
res = dg.transcription.sync_prerecorded(source, options)
with open(f"./{audio_file[:-4]}.json", "w") as transcript:
json.dump(res, transcript)
OUTPUT = 'combined.json'
with open(OUTPUT, "r") as file:
data = json.load(file)
result = data['results']['channels'][0]['alternatives'][0]['transcript']
result = result.split('.')
for sentence in result:
return(sentence)