Skip to content

Commit e58e806

Browse files
Fix jigsawstack-python.tts:
1. The bug stems from line 59 of jigsawstack.request.Request class, where the method perform verifies the response headers. 2. The response headers are useful for us to determine type of content received from the api as response. 3. Previously, Request.perform()::line 59 would accept a response of application/json type, or raise an "parsing" error otherwise. 4. Fix applied: Updated the boolean check to accept audio/wav. 5. Clarification: In JavaScript, a Blob represents raw binary data as a file-like object. In Python, binary responses (like audio data) are typically handled as a bytes object. 6. The response has to be written to a file :)
1 parent cf4c340 commit e58e806

File tree

2 files changed

+4
-40
lines changed

2 files changed

+4
-40
lines changed

jigsawstack/request.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def perform(self) -> Union[T, None]:
5656

5757
# this is a safety net, if we get here it means the JigsawStack API is having issues
5858
# and most likely the gateway is returning htmls
59-
if "application/json" not in resp.headers["content-type"]:
59+
if "application/json" not in resp.headers["content-type"] and "audio/wav" not in resp.headers["content-type"]:
6060
raise_for_code_and_type(
6161
code=500,
6262
message="Failed to parse JigsawStack API response. Please try again.",
@@ -72,6 +72,9 @@ def perform(self) -> Union[T, None]:
7272
err=error.get("error"),
7373
)
7474

75+
if "audio/wav" in resp.headers["content-type"]:
76+
return cast(T, resp) # we return the response object, instead of the json
77+
7578
return cast(T, resp.json())
7679

7780
def perform_file(self) -> Union[T, None]:

test_tts.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)