-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTTS_retrieveTask.py
More file actions
43 lines (41 loc) · 1.24 KB
/
TTS_retrieveTask.py
File metadata and controls
43 lines (41 loc) · 1.24 KB
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
import json
from boto3 import client
def lambda_handler(event, context):
print(event['headers'])
try:
taskID = event['headers']['x-tts-taskid']
except:
return {
"statusCode": 400,
"body": "ERROR: TaskID not specified in the x-tts-taskid header."
}
polly_client = client('polly')
try:
synthesis_task = polly_client.get_speech_synthesis_task(TaskId=taskID)
except:
return {
"statusCode": 400,
"body": "ERROR: Invalid Task ID."
}
synthesis_task = synthesis_task['SynthesisTask']
command = synthesis_task['TaskStatus']
if synthesis_task['TaskStatus'] == 'scheduled' or synthesis_task['TaskStatus'] == 'inProgress':
return {
'statusCode': 302,
'body': 'Task scheduled'
}
elif synthesis_task['TaskStatus'] == 'completed':
return {
'statusCode': 200,
'body': str(synthesis_task['OutputUri'])
}
elif synthesis_task['TaskStatus'] == 'failed':
return {
'statusCode': 503,
'body': 'ERROR: Task failed'
}
else:
return {
'statusCode': 500,
'body': 'ERROR: Task failed'
}