-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtts_worker.py
46 lines (37 loc) · 902 Bytes
/
tts_worker.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
import boto3
import os
import time
# Create SQS client
sqs = boto3.client('sqs')
queue_url = 'https://sqs.us-east-2.amazonaws.com/842599995920/holidaybear.fifo'
counter = 0
while True:
# Receive message from SQS queue
response = sqs.receive_message(
QueueUrl=queue_url,
MaxNumberOfMessages=1,
MessageAttributeNames=[
'All'
],
VisibilityTimeout=30,
WaitTimeSeconds=0
)
try:
print "Reading message..."
message = response['Messages'][0]
receipt_handle = message['ReceiptHandle']
# Delete received message from queue
sqs.delete_message(
QueueUrl=queue_url,
ReceiptHandle=receipt_handle
)
print message
os.system("espeak '{}'".format(message['Body']))
counter = 0
print('Received and deleted message: %s' % message)
except:
counter += 1
if counter > 500:
time.sleep(2)
print "No messages. Re-reading."
continue