Skip to content

Fix/jigsawstack-python-audio-tts #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 2, 2025
Merged

Fix/jigsawstack-python-audio-tts #36

merged 3 commits into from
Mar 2, 2025

Conversation

Khurdhula-Harshavardhan
Copy link
Collaborator

@Khurdhula-Harshavardhan Khurdhula-Harshavardhan commented Mar 1, 2025

Bug

  1. Parsing error, since the response is always expected to be of content-type application/json.
  2. The TTS endpoint returns content-type of audio/wav.

Fix Applied

  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 determining the type of content received from the api as the 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 :)

Below is an successful call:

from jigsawstack import JigsawStack

jigsawstack = JigsawStack(
    api_key="your_api_key", # not required if already set as an environment variable.
)

response = jigsawstack.audio.text_to_speech(
    {
        "text": "Hi, this is Harsha a founding member of Jigsawstack. \
        I am an Applied AI Engineer and Researcher, \
        happy to answer any questions you might have towards our smoll models!",
    }
)

with open("output.mp3", "wb") as f:  
    f.write(response.content)

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 :)
@Khurdhula-Harshavardhan Khurdhula-Harshavardhan added the bug Something isn't working label Mar 1, 2025
@yoeven yoeven merged commit 20f6ce5 into main Mar 2, 2025
@Khurdhula-Harshavardhan Khurdhula-Harshavardhan deleted the fix/jigsawstack-audio-tts branch March 7, 2025 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants