-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathget_transcription.py
More file actions
30 lines (24 loc) · 953 Bytes
/
get_transcription.py
File metadata and controls
30 lines (24 loc) · 953 Bytes
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
import argparse
import os
import requests
API_URL = "https://api.assemblyai.com/v2/"
def get_transcription(transcription_id):
"""Requests the transcription from the API and returns the JSON
response."""
endpoint = "".join([API_URL, "transcript/{}".format(transcription_id)])
headers = {"authorization": os.getenv('ASSEMBLYAI_KEY')}
response = requests.get(endpoint, headers=headers)
return response.json()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("transcription_id")
args = parser.parse_args()
transcription_id = args.transcription_id
response_json = get_transcription(transcription_id)
print(response_json)
if response_json['status'] == "completed":
for word in response_json['words']:
print(word['text'], end=" ")
else:
print("current status of transcription request: {}".format(
response_json['status']))