#No longer getting "done" flag
1 messages · Page 1 of 1 (latest)
the audio is still being synthesized correctly, just the final chunk doesn't have done set to true
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?
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?
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