From faaffb85fe3dfaa3ba7fcedca38a31eb7d5b661b Mon Sep 17 00:00:00 2001 From: Larry Date: Thu, 30 Jun 2022 23:30:40 -0700 Subject: [PATCH] Wait and retry when there is a 429 error from Polly --- TTS/POLLY.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/TTS/POLLY.py b/TTS/POLLY.py index da1fae0..0b426c9 100644 --- a/TTS/POLLY.py +++ b/TTS/POLLY.py @@ -1,6 +1,7 @@ import os import random import re +import time import requests import sox @@ -52,7 +53,12 @@ class POLLY: ) voice = str(os.getenv("VOICE")).capitalize() body = {"voice": voice, "text": req_text, "service": "polly"} - response = requests.post(self.url, data=body) + while True: + response = requests.post(self.url, data=body) + print(response.status_code) + if response.status_code != 429: + break + time.sleep(20) try: voice_data = requests.get(response.json()["speak_url"]) with open(filename, "wb") as f: