Skip to content

Commit

Permalink
add failsafe for no json in playht response
Browse files Browse the repository at this point in the history
  • Loading branch information
adnaans committed Jul 29, 2024
1 parent bf2fb43 commit 720eff6
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions vocode/streaming/synthesizer/play_ht_synthesizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,21 @@ async def create_speech_uncached(
timeout=ClientTimeout(total=15),
)
if not response.ok:
response_json = await response.json()
if response_json and "error_message" in response_json:
message = response_json["error_message"]
else:
message = f"Request to Play.HT failed with status code {str(response.status)}"

raise PlayHTV1APIError(
f"Play.ht API error status code {response.status}",
(await response.json()).get(
"error_message",
f"Request to Play.HT failed with status code {str(response.status)}",
),
message,
)
if response.status == 429 and attempt < max_backoff_retries - 1:
await asyncio.sleep(backoff_retry_delay)
backoff_retry_delay *= 2 # Exponentially increase delay
continue

if not response.ok:
raise PlayHTV1APIError(
f"Play.ht API error status code {response.status}",
(await response.json()).get(
"error_message",
f"Request to Play.HT failed with status code {str(response.status)}",
),
)

if self.experimental_streaming:
return SynthesisResult(
self.experimental_mp3_streaming_output_generator(
Expand Down

0 comments on commit 720eff6

Please sign in to comment.