-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathinitiate_transcription.py
37 lines (30 loc) · 1.09 KB
/
initiate_transcription.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
import argparse
import os
import requests
import sys
import time
API_URL = "https://api.assemblyai.com/v2/"
CDN_URL = "https://cdn.assemblyai.com/"
def initiate_transcription(file_id):
"""Sends a request to the API to transcribe a specific
file that was previously uploaded to the API. This will
not immediately return the transcription because it takes
a moment for the service to analyze and perform the
transcription, so there is a different function to retrieve
the results.
"""
endpoint = "".join([API_URL, "transcript"])
json = {"audio_url": "".join([CDN_URL, "upload/{}".format(file_id)]), "content_safety": "true"}
headers = {
"authorization": os.getenv("ASSEMBLYAI_KEY"),
"content-type": "application/json"
}
response = requests.post(endpoint, json=json, headers=headers)
return response.json()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("file_id")
args = parser.parse_args()
file_id = args.file_id
response_json = initiate_transcription(file_id)
print(response_json)