#No longer getting "done" flag

1 messages · Page 1 of 1 (latest)

jolly sparrow
#

I created a test app a few weeks ago that uses the websocket API. Everything was working until I tried again today, and suddenly I'm no longer getting any chunks with "done" set to true.

#

the audio is still being synthesized correctly, just the final chunk doesn't have done set to true

upbeat turtle
#

Hi @jolly sparrow , thanks for bringing this to our attention. Could you send me an example snippet of how you're calling the websocket API?

jolly sparrow
#
Future<Stream<Uint8List>> synthesizeCartesia(String sentence) async {
    final socket = await WebSocket.connect(
        "wss://api.cartesia.ai/v0/audio/websocket?api_key=${apiKey}");
    final completer = Completer();
    String b64Audio = "";
    late Uint8List audio;

    final controller = StreamController<Uint8List>();

    late StreamSubscription messageListener;

    Timer? _timer;

    messageListener = socket.listen((messageEvent) async {
      _timer?.cancel();
      _timer = Timer(Duration(seconds: 1), () async {
        if (!controller.isClosed) {
          await messageListener.cancel();
          socket.close();
          controller.close();
        }
      });
      var chunk = jsonDecode(messageEvent);
      if (chunk.containsKey("error")) {
        throw Exception(chunk["error"]);
      }
      if (chunk.containsKey("data")) {
        controller.add(base64Decode(chunk["data"]));
      }
      if (chunk["done"] == true) {
        await messageListener.cancel();
        socket.close();
        controller.close();
      }
    });

    var encoded = jsonEncode({
      "context_id": DateTime.now().millisecondsSinceEpoch.toString(),
      "data": {
        "transcript": sentence.trim(),
        "model_id": "upbeat-moon",
        "voice": _voice,
      }
    });
    socket.add(encoded);

    return controller.stream;
  }
#

(this is after adding a manual 1 second timeout to account for the fact I wasn't getting an end chunk)

#

I received an email overnight saying that upbeat-moon is being deprecated, maybe it's not an issue with the newer model?

upbeat turtle
#

Ah I sent that email heh. Mmmm idt using the older model would affect anything. I'll play around with the snippet u sent and get back to you!

One initial thought though based on what i'm seeing is I think you're calling a deprecated version of the API. The current version is at /tts/websocket. You can read up on that here: https://docs.cartesia.ai/migration-guides/migrating-to-the-stable-api#websocket

Cartesia

Our stable API is now available. Our previous API (version 0) will be deprecated on June 17. All future deprecations will come with at least one month of deprecation notice.