Skip to content
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

Using the non-async.io streaming api with add_timestamps can produce error #18

Open
robbie-anam opened this issue Jan 31, 2025 · 1 comment

Comments

@robbie-anam
Copy link
Contributor

When invoking the streaming api via:

output_stream = context.send(
                    model_id=self.model_id,
                    transcript=self.read_from_queue_generator(self.current_turn.metrics_context),
                    voice_id=self.voice_id,
                    output_format=self.output_format,
                    add_timestamps=True,
                )

                for chunk in output_stream:

The following error is thrown:

Traceback (most recent call last):
  File "<omitted>/lib/python3.11/site-packages/cartesia/_websocket.py", line 141, in send
    if response["data"]:
       ~~~~~~~~^^^^^^^^
KeyError: 'data'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/<omitted>", in run
    for chunk in output_stream:
  File "<omitted>/lib/python3.11/site-packages/cartesia/_websocket.py", line 169, in send
    raise RuntimeError(f"Failed to generate audio. {e}")

The code does not seem to be handling the case where "data" is not present. The culprit(s) are these lines of code in _websocket:
if response["data"]

You can demonstrate the issue by running a simple example:

response = {}
if response["data"]:
    print("Everything ok")

The "data" field is not meant to be present in word_timestamps responses.

@robbie-anam
Copy link
Contributor Author

I've opened a PR with a fix for this here: #19

chongzluong pushed a commit that referenced this issue Feb 3, 2025
#19)

This is a fix for this issue #18 

It provides a simple safety check for the presence of the "data" field
in a response before trying to access it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant