Wait and retry when there is a 429 error from Polly

pull/777/head
Larry 3 years ago
parent ef5ba78cfa
commit faaffb85fe

@ -1,6 +1,7 @@
import os import os
import random import random
import re import re
import time
import requests import requests
import sox import sox
@ -52,7 +53,12 @@ class POLLY:
) )
voice = str(os.getenv("VOICE")).capitalize() voice = str(os.getenv("VOICE")).capitalize()
body = {"voice": voice, "text": req_text, "service": "polly"} body = {"voice": voice, "text": req_text, "service": "polly"}
while True:
response = requests.post(self.url, data=body) response = requests.post(self.url, data=body)
print(response.status_code)
if response.status_code != 429:
break
time.sleep(20)
try: try:
voice_data = requests.get(response.json()["speak_url"]) voice_data = requests.get(response.json()["speak_url"])
with open(filename, "wb") as f: with open(filename, "wb") as f:

Loading…
Cancel
Save