cartesia-ai / cartesia-python

The official Cartesia client for Python.
MIT License
23 stars 2 forks source link

Adding Cancellation requests to websockets #7

Open jay2jp opened 2 weeks ago

jay2jp commented 2 weeks ago

WebSocket Cancellation Implementation

Added cancellation functionality to the WebSocket implementation, following the Cartesia API documentation.

Changes

  1. Added new cancel method to _WebSocket class that implements the cancellation API described in: https://docs.cartesia.ai/api-reference/tts/working-with-web-sockets/contexts#cancelling-requests

  2. Created separate request handling for cancellation to maintain API clarity:

    • Created new _construct_tts_request_cancel function to handle cancel requests
    • Kept cancellation separate from send method to preserve required parameters (model_id, transcript, output_format)
    • This aligns with the API's OR condition described in https://docs.cartesia.ai/api-reference/tts/tts#send

Implementation Notes

Documentation

i have added lines towards the end of the read me showing how this works