@cartesia/cartesia-js 2.2.3 → 2.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/README.md +100 -7
  2. package/api/resources/apiStatus/client/Client.js +1 -1
  3. package/api/resources/auth/client/Client.js +1 -1
  4. package/api/resources/index.d.ts +2 -0
  5. package/api/resources/index.js +3 -1
  6. package/api/resources/infill/client/Client.js +1 -1
  7. package/api/resources/stt/client/Client.d.ts +28 -0
  8. package/api/resources/stt/client/Client.js +58 -0
  9. package/api/resources/stt/client/index.d.ts +1 -0
  10. package/api/resources/stt/client/index.js +5 -0
  11. package/api/resources/stt/index.d.ts +1 -0
  12. package/api/resources/stt/index.js +17 -0
  13. package/api/resources/stt/types/DoneMessage.d.ts +10 -0
  14. package/api/resources/stt/types/DoneMessage.js +5 -0
  15. package/api/resources/stt/types/ErrorMessage.d.ts +9 -0
  16. package/api/resources/stt/types/ErrorMessage.js +5 -0
  17. package/api/resources/stt/types/FlushDoneMessage.d.ts +10 -0
  18. package/api/resources/stt/types/FlushDoneMessage.js +5 -0
  19. package/api/resources/stt/types/StreamingTranscriptionResponse.d.ts +22 -0
  20. package/api/resources/stt/types/StreamingTranscriptionResponse.js +5 -0
  21. package/api/resources/stt/types/SttEncoding.d.ts +15 -0
  22. package/api/resources/stt/types/SttEncoding.js +14 -0
  23. package/api/resources/stt/types/TranscriptMessage.d.ts +22 -0
  24. package/api/resources/stt/types/TranscriptMessage.js +5 -0
  25. package/api/resources/stt/types/TranscriptionResponse.d.ts +14 -0
  26. package/api/resources/stt/types/TranscriptionResponse.js +5 -0
  27. package/api/resources/stt/types/TranscriptionWord.d.ts +11 -0
  28. package/api/resources/stt/types/TranscriptionWord.js +5 -0
  29. package/api/resources/stt/types/index.d.ts +8 -0
  30. package/api/resources/stt/types/index.js +24 -0
  31. package/api/resources/voices/client/Client.js +8 -8
  32. package/dist/api/resources/apiStatus/client/Client.js +1 -1
  33. package/dist/api/resources/auth/client/Client.js +1 -1
  34. package/dist/api/resources/index.d.ts +2 -0
  35. package/dist/api/resources/index.js +3 -1
  36. package/dist/api/resources/infill/client/Client.js +1 -1
  37. package/dist/api/resources/stt/client/Client.d.ts +28 -0
  38. package/dist/api/resources/stt/client/Client.js +58 -0
  39. package/dist/api/resources/stt/client/index.d.ts +1 -0
  40. package/dist/api/resources/stt/client/index.js +5 -0
  41. package/dist/api/resources/stt/index.d.ts +1 -0
  42. package/dist/api/resources/stt/index.js +17 -0
  43. package/dist/api/resources/stt/types/DoneMessage.d.ts +10 -0
  44. package/dist/api/resources/stt/types/DoneMessage.js +5 -0
  45. package/dist/api/resources/stt/types/ErrorMessage.d.ts +9 -0
  46. package/dist/api/resources/stt/types/ErrorMessage.js +5 -0
  47. package/dist/api/resources/stt/types/FlushDoneMessage.d.ts +10 -0
  48. package/dist/api/resources/stt/types/FlushDoneMessage.js +5 -0
  49. package/dist/api/resources/stt/types/StreamingTranscriptionResponse.d.ts +22 -0
  50. package/dist/api/resources/stt/types/StreamingTranscriptionResponse.js +5 -0
  51. package/dist/api/resources/stt/types/SttEncoding.d.ts +15 -0
  52. package/dist/api/resources/stt/types/SttEncoding.js +14 -0
  53. package/dist/api/resources/stt/types/TranscriptMessage.d.ts +22 -0
  54. package/dist/api/resources/stt/types/TranscriptMessage.js +5 -0
  55. package/dist/api/resources/stt/types/TranscriptionResponse.d.ts +14 -0
  56. package/dist/api/resources/stt/types/TranscriptionResponse.js +5 -0
  57. package/dist/api/resources/stt/types/TranscriptionWord.d.ts +11 -0
  58. package/dist/api/resources/stt/types/TranscriptionWord.js +5 -0
  59. package/dist/api/resources/stt/types/index.d.ts +8 -0
  60. package/dist/api/resources/stt/types/index.js +24 -0
  61. package/dist/api/resources/voices/client/Client.js +8 -8
  62. package/dist/serialization/resources/index.d.ts +2 -0
  63. package/dist/serialization/resources/index.js +3 -1
  64. package/dist/serialization/resources/stt/index.d.ts +1 -0
  65. package/dist/serialization/resources/stt/index.js +17 -0
  66. package/dist/serialization/resources/stt/types/DoneMessage.d.ts +12 -0
  67. package/dist/serialization/resources/stt/types/DoneMessage.js +43 -0
  68. package/dist/serialization/resources/stt/types/ErrorMessage.d.ts +13 -0
  69. package/dist/serialization/resources/stt/types/ErrorMessage.js +44 -0
  70. package/dist/serialization/resources/stt/types/FlushDoneMessage.d.ts +12 -0
  71. package/dist/serialization/resources/stt/types/FlushDoneMessage.js +43 -0
  72. package/dist/serialization/resources/stt/types/StreamingTranscriptionResponse.d.ts +26 -0
  73. package/dist/serialization/resources/stt/types/StreamingTranscriptionResponse.js +55 -0
  74. package/dist/serialization/resources/stt/types/SttEncoding.d.ts +10 -0
  75. package/dist/serialization/resources/stt/types/SttEncoding.js +41 -0
  76. package/dist/serialization/resources/stt/types/TranscriptMessage.d.ts +18 -0
  77. package/dist/serialization/resources/stt/types/TranscriptMessage.js +49 -0
  78. package/dist/serialization/resources/stt/types/TranscriptionResponse.d.ts +16 -0
  79. package/dist/serialization/resources/stt/types/TranscriptionResponse.js +47 -0
  80. package/dist/serialization/resources/stt/types/TranscriptionWord.d.ts +14 -0
  81. package/dist/serialization/resources/stt/types/TranscriptionWord.js +45 -0
  82. package/dist/serialization/resources/stt/types/index.d.ts +8 -0
  83. package/dist/serialization/resources/stt/types/index.js +24 -0
  84. package/dist/version.d.ts +1 -1
  85. package/dist/version.js +1 -1
  86. package/dist/wrapper/Client.d.ts +3 -0
  87. package/dist/wrapper/Client.js +5 -0
  88. package/dist/wrapper/StreamingSTTClient.d.ts +6 -0
  89. package/dist/wrapper/StreamingSTTClient.js +17 -0
  90. package/dist/wrapper/SttWebsocket.d.ts +29 -0
  91. package/dist/wrapper/SttWebsocket.js +198 -0
  92. package/dist/wrapper/Websocket.d.ts +1 -1
  93. package/dist/wrapper/Websocket.js +24 -16
  94. package/package.json +1 -1
  95. package/serialization/resources/index.d.ts +2 -0
  96. package/serialization/resources/index.js +3 -1
  97. package/serialization/resources/stt/index.d.ts +1 -0
  98. package/serialization/resources/stt/index.js +17 -0
  99. package/serialization/resources/stt/types/DoneMessage.d.ts +12 -0
  100. package/serialization/resources/stt/types/DoneMessage.js +43 -0
  101. package/serialization/resources/stt/types/ErrorMessage.d.ts +13 -0
  102. package/serialization/resources/stt/types/ErrorMessage.js +44 -0
  103. package/serialization/resources/stt/types/FlushDoneMessage.d.ts +12 -0
  104. package/serialization/resources/stt/types/FlushDoneMessage.js +43 -0
  105. package/serialization/resources/stt/types/StreamingTranscriptionResponse.d.ts +26 -0
  106. package/serialization/resources/stt/types/StreamingTranscriptionResponse.js +55 -0
  107. package/serialization/resources/stt/types/SttEncoding.d.ts +10 -0
  108. package/serialization/resources/stt/types/SttEncoding.js +41 -0
  109. package/serialization/resources/stt/types/TranscriptMessage.d.ts +18 -0
  110. package/serialization/resources/stt/types/TranscriptMessage.js +49 -0
  111. package/serialization/resources/stt/types/TranscriptionResponse.d.ts +16 -0
  112. package/serialization/resources/stt/types/TranscriptionResponse.js +47 -0
  113. package/serialization/resources/stt/types/TranscriptionWord.d.ts +14 -0
  114. package/serialization/resources/stt/types/TranscriptionWord.js +45 -0
  115. package/serialization/resources/stt/types/index.d.ts +8 -0
  116. package/serialization/resources/stt/types/index.js +24 -0
  117. package/version.d.ts +1 -1
  118. package/version.js +1 -1
  119. package/wrapper/Client.d.ts +3 -0
  120. package/wrapper/Client.js +5 -0
  121. package/wrapper/StreamingSTTClient.d.ts +6 -0
  122. package/wrapper/StreamingSTTClient.js +17 -0
  123. package/wrapper/SttWebsocket.d.ts +29 -0
  124. package/wrapper/SttWebsocket.js +198 -0
  125. package/wrapper/Websocket.d.ts +1 -1
  126. package/wrapper/Websocket.js +24 -16
@@ -0,0 +1,198 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
45
+ if (kind === "m") throw new TypeError("Private method is not writable");
46
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
47
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
48
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
49
+ };
50
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
51
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
52
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
53
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
54
+ };
55
+ var _SttWebsocket_instances, _SttWebsocket_isConnected, _SttWebsocket_model, _SttWebsocket_language, _SttWebsocket_encoding, _SttWebsocket_sampleRate, _SttWebsocket_connectionPromise, _SttWebsocket_ensureConnected;
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ const core = __importStar(require("../core"));
58
+ const environments = __importStar(require("../environments"));
59
+ const websocket_1 = require("../core/websocket");
60
+ class SttWebsocket {
61
+ constructor({ model = "ink-whisper", language = "en", encoding = "pcm_s16le", sampleRate = 16000, }, options) {
62
+ _SttWebsocket_instances.add(this);
63
+ this.options = options;
64
+ _SttWebsocket_isConnected.set(this, false);
65
+ _SttWebsocket_model.set(this, void 0);
66
+ _SttWebsocket_language.set(this, void 0);
67
+ _SttWebsocket_encoding.set(this, void 0);
68
+ _SttWebsocket_sampleRate.set(this, void 0);
69
+ _SttWebsocket_connectionPromise.set(this, void 0);
70
+ __classPrivateFieldSet(this, _SttWebsocket_model, model, "f");
71
+ __classPrivateFieldSet(this, _SttWebsocket_language, language, "f");
72
+ __classPrivateFieldSet(this, _SttWebsocket_encoding, encoding, "f");
73
+ __classPrivateFieldSet(this, _SttWebsocket_sampleRate, sampleRate, "f");
74
+ }
75
+ send(audioData) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ var _a;
78
+ yield __classPrivateFieldGet(this, _SttWebsocket_instances, "m", _SttWebsocket_ensureConnected).call(this);
79
+ (_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(audioData);
80
+ });
81
+ }
82
+ finalize() {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ var _a;
85
+ yield __classPrivateFieldGet(this, _SttWebsocket_instances, "m", _SttWebsocket_ensureConnected).call(this);
86
+ (_a = this.socket) === null || _a === void 0 ? void 0 : _a.send("finalize");
87
+ });
88
+ }
89
+ done() {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ var _a;
92
+ yield __classPrivateFieldGet(this, _SttWebsocket_instances, "m", _SttWebsocket_ensureConnected).call(this);
93
+ (_a = this.socket) === null || _a === void 0 ? void 0 : _a.send("done");
94
+ });
95
+ }
96
+ onMessage(callback) {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ yield __classPrivateFieldGet(this, _SttWebsocket_instances, "m", _SttWebsocket_ensureConnected).call(this);
99
+ if (!this.socket) {
100
+ throw new Error("WebSocket failed to initialize after connection attempt.");
101
+ }
102
+ this.socket.addEventListener("message", (event) => {
103
+ try {
104
+ const data = JSON.parse(event.data);
105
+ const result = {
106
+ type: data.type,
107
+ requestId: data.request_id || "",
108
+ };
109
+ // Handle different message types according to stt.yml spec
110
+ if (data.type === "transcript") {
111
+ result.text = data.text || "";
112
+ result.isFinal = data.is_final || false;
113
+ result.duration = data.duration;
114
+ result.language = data.language;
115
+ }
116
+ else if (data.type === "flush_done") {
117
+ // Acknowledgment for finalize command
118
+ // Only requestId is needed for flush_done
119
+ }
120
+ else if (data.type === "done") {
121
+ // Acknowledgment for done command - session complete
122
+ // Only requestId is needed for done
123
+ }
124
+ else if (data.type === "error") {
125
+ result.message = data.message;
126
+ }
127
+ callback(result);
128
+ }
129
+ catch (error) {
130
+ callback({
131
+ type: "error",
132
+ requestId: "",
133
+ message: `Failed to parse message: ${error}`,
134
+ });
135
+ }
136
+ });
137
+ });
138
+ }
139
+ connect() {
140
+ return __awaiter(this, arguments, void 0, function* (connectOptions = {}) {
141
+ if (__classPrivateFieldGet(this, _SttWebsocket_isConnected, "f")) {
142
+ throw new Error("WebSocket is already connected.");
143
+ }
144
+ this.socket = new websocket_1.ReconnectingWebSocket(() => __awaiter(this, void 0, void 0, function* () {
145
+ var _a;
146
+ const baseUrl = ((_a = (yield core.Supplier.get(this.options.environment))) !== null && _a !== void 0 ? _a : environments.CartesiaEnvironment.Production).replace(/^https?:\/\//, "");
147
+ const params = {
148
+ model: __classPrivateFieldGet(this, _SttWebsocket_model, "f"),
149
+ cartesia_version: this.options.cartesiaVersion || "2024-06-10",
150
+ encoding: __classPrivateFieldGet(this, _SttWebsocket_encoding, "f"),
151
+ sample_rate: __classPrivateFieldGet(this, _SttWebsocket_sampleRate, "f").toString(),
152
+ };
153
+ if (__classPrivateFieldGet(this, _SttWebsocket_language, "f"))
154
+ params.language = __classPrivateFieldGet(this, _SttWebsocket_language, "f");
155
+ const apiKey = yield core.Supplier.get(this.options.apiKey);
156
+ if (apiKey) {
157
+ params.api_key = apiKey;
158
+ }
159
+ else if (connectOptions.accessToken) {
160
+ params.access_token = connectOptions.accessToken;
161
+ }
162
+ const queryString = Object.keys(params)
163
+ .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
164
+ .join('&');
165
+ return `wss://${baseUrl}/stt/websocket?${queryString}`;
166
+ }), undefined, connectOptions);
167
+ return new Promise((resolve, reject) => {
168
+ this.socket.onopen = () => {
169
+ __classPrivateFieldSet(this, _SttWebsocket_isConnected, true, "f");
170
+ resolve();
171
+ };
172
+ this.socket.onclose = () => {
173
+ __classPrivateFieldSet(this, _SttWebsocket_isConnected, false, "f");
174
+ };
175
+ this.socket.onerror = () => {
176
+ reject(new Error("WebSocket failed to connect."));
177
+ };
178
+ this.socket.reconnect();
179
+ });
180
+ });
181
+ }
182
+ disconnect() {
183
+ var _a;
184
+ (_a = this.socket) === null || _a === void 0 ? void 0 : _a.close();
185
+ __classPrivateFieldSet(this, _SttWebsocket_isConnected, false, "f");
186
+ }
187
+ }
188
+ _SttWebsocket_isConnected = new WeakMap(), _SttWebsocket_model = new WeakMap(), _SttWebsocket_language = new WeakMap(), _SttWebsocket_encoding = new WeakMap(), _SttWebsocket_sampleRate = new WeakMap(), _SttWebsocket_connectionPromise = new WeakMap(), _SttWebsocket_instances = new WeakSet(), _SttWebsocket_ensureConnected = function _SttWebsocket_ensureConnected() {
189
+ return __awaiter(this, void 0, void 0, function* () {
190
+ if (__classPrivateFieldGet(this, _SttWebsocket_isConnected, "f"))
191
+ return;
192
+ if (!__classPrivateFieldGet(this, _SttWebsocket_connectionPromise, "f")) {
193
+ __classPrivateFieldSet(this, _SttWebsocket_connectionPromise, this.connect(), "f");
194
+ }
195
+ yield __classPrivateFieldGet(this, _SttWebsocket_connectionPromise, "f");
196
+ });
197
+ };
198
+ exports.default = SttWebsocket;
@@ -25,7 +25,7 @@ export default class Websocket {
25
25
  source: Source;
26
26
  stop: unknown;
27
27
  }>;
28
- continue(inputs: WebSocketTtsRequest): void;
28
+ continue(inputs: WebSocketTtsRequest): Promise<void>;
29
29
  /**
30
30
  * Authenticate and connect to a Cartesia streaming WebSocket.
31
31
  *
@@ -55,7 +55,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
55
55
  var __importDefault = (this && this.__importDefault) || function (mod) {
56
56
  return (mod && mod.__esModule) ? mod : { "default": mod };
57
57
  };
58
- var _Websocket_instances, _Websocket_isConnected, _Websocket_sampleRate, _Websocket_container, _Websocket_encoding, _Websocket_generateId;
58
+ var _Websocket_instances, _Websocket_isConnected, _Websocket_sampleRate, _Websocket_container, _Websocket_encoding, _Websocket_connectionPromise, _Websocket_ensureConnected, _Websocket_generateId;
59
59
  Object.defineProperty(exports, "__esModule", { value: true });
60
60
  const core = __importStar(require("../core"));
61
61
  const environments = __importStar(require("../environments"));
@@ -74,6 +74,7 @@ class Websocket {
74
74
  _Websocket_sampleRate.set(this, void 0);
75
75
  _Websocket_container.set(this, void 0);
76
76
  _Websocket_encoding.set(this, void 0);
77
+ _Websocket_connectionPromise.set(this, void 0);
77
78
  __classPrivateFieldSet(this, _Websocket_sampleRate, sampleRate, "f");
78
79
  __classPrivateFieldSet(this, _Websocket_container, container !== null && container !== void 0 ? container : "raw", "f");
79
80
  __classPrivateFieldSet(this, _Websocket_encoding, encoding !== null && encoding !== void 0 ? encoding : "pcm_f32le", "f");
@@ -91,9 +92,7 @@ class Websocket {
91
92
  send(inputs_1) {
92
93
  return __awaiter(this, arguments, void 0, function* (inputs, { timeout = 0 } = {}) {
93
94
  var _a, _b, _c, _d;
94
- if (!__classPrivateFieldGet(this, _Websocket_isConnected, "f")) {
95
- throw new Error("Not connected to WebSocket. Call .connect() first.");
96
- }
95
+ yield __classPrivateFieldGet(this, _Websocket_instances, "m", _Websocket_ensureConnected).call(this);
97
96
  if (!inputs.contextId) {
98
97
  inputs.contextId = __classPrivateFieldGet(this, _Websocket_instances, "m", _Websocket_generateId).call(this);
99
98
  }
@@ -153,17 +152,17 @@ class Websocket {
153
152
  });
154
153
  }
155
154
  continue(inputs) {
156
- var _a;
157
- if (!__classPrivateFieldGet(this, _Websocket_isConnected, "f")) {
158
- throw new Error("Not connected to WebSocket. Call .connect() first.");
159
- }
160
- if (!inputs.contextId) {
161
- throw new Error("context_id is required to continue a context.");
162
- }
163
- if (!inputs.outputFormat) {
164
- inputs.outputFormat = (0, utils_1.resolveOutputFormat)(__classPrivateFieldGet(this, _Websocket_container, "f"), __classPrivateFieldGet(this, _Websocket_encoding, "f"), __classPrivateFieldGet(this, _Websocket_sampleRate, "f"));
165
- }
166
- (_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(Object.assign({ continue: true }, serializers.WebSocketTtsRequest.jsonOrThrow(inputs, { unrecognizedObjectKeys: "strip" }))));
155
+ return __awaiter(this, void 0, void 0, function* () {
156
+ var _a;
157
+ yield __classPrivateFieldGet(this, _Websocket_instances, "m", _Websocket_ensureConnected).call(this);
158
+ if (!inputs.contextId) {
159
+ throw new Error("context_id is required to continue a context.");
160
+ }
161
+ if (!inputs.outputFormat) {
162
+ inputs.outputFormat = (0, utils_1.resolveOutputFormat)(__classPrivateFieldGet(this, _Websocket_container, "f"), __classPrivateFieldGet(this, _Websocket_encoding, "f"), __classPrivateFieldGet(this, _Websocket_sampleRate, "f"));
163
+ }
164
+ (_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(Object.assign({ continue: true }, serializers.WebSocketTtsRequest.jsonOrThrow(inputs, { unrecognizedObjectKeys: "strip" }))));
165
+ });
167
166
  }
168
167
  /**
169
168
  * Authenticate and connect to a Cartesia streaming WebSocket.
@@ -226,7 +225,16 @@ class Websocket {
226
225
  (_a = this.socket) === null || _a === void 0 ? void 0 : _a.close();
227
226
  }
228
227
  }
229
- _Websocket_isConnected = new WeakMap(), _Websocket_sampleRate = new WeakMap(), _Websocket_container = new WeakMap(), _Websocket_encoding = new WeakMap(), _Websocket_instances = new WeakSet(), _Websocket_generateId = function _Websocket_generateId() {
228
+ _Websocket_isConnected = new WeakMap(), _Websocket_sampleRate = new WeakMap(), _Websocket_container = new WeakMap(), _Websocket_encoding = new WeakMap(), _Websocket_connectionPromise = new WeakMap(), _Websocket_instances = new WeakSet(), _Websocket_ensureConnected = function _Websocket_ensureConnected() {
229
+ return __awaiter(this, void 0, void 0, function* () {
230
+ if (__classPrivateFieldGet(this, _Websocket_isConnected, "f"))
231
+ return;
232
+ if (!__classPrivateFieldGet(this, _Websocket_connectionPromise, "f")) {
233
+ __classPrivateFieldSet(this, _Websocket_connectionPromise, this.connect(), "f");
234
+ }
235
+ yield __classPrivateFieldGet(this, _Websocket_connectionPromise, "f");
236
+ });
237
+ }, _Websocket_generateId = function _Websocket_generateId() {
230
238
  return (0, human_id_1.humanId)({
231
239
  separator: "-",
232
240
  capitalize: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cartesia/cartesia-js",
3
- "version": "2.2.3",
3
+ "version": "2.2.5",
4
4
  "private": false,
5
5
  "repository": "https://github.com/cartesia-ai/cartesia-js",
6
6
  "main": "./index.js",
@@ -4,6 +4,8 @@ export * as auth from "./auth";
4
4
  export * from "./auth/types";
5
5
  export * as embedding from "./embedding";
6
6
  export * from "./embedding/types";
7
+ export * as stt from "./stt";
8
+ export * from "./stt/types";
7
9
  export * as tts from "./tts";
8
10
  export * from "./tts/types";
9
11
  export * as voiceChanger from "./voiceChanger";
@@ -36,13 +36,15 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
36
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.voices = exports.voiceChanger = exports.tts = exports.embedding = exports.auth = exports.apiStatus = void 0;
39
+ exports.voices = exports.voiceChanger = exports.tts = exports.stt = exports.embedding = exports.auth = exports.apiStatus = void 0;
40
40
  exports.apiStatus = __importStar(require("./apiStatus"));
41
41
  __exportStar(require("./apiStatus/types"), exports);
42
42
  exports.auth = __importStar(require("./auth"));
43
43
  __exportStar(require("./auth/types"), exports);
44
44
  exports.embedding = __importStar(require("./embedding"));
45
45
  __exportStar(require("./embedding/types"), exports);
46
+ exports.stt = __importStar(require("./stt"));
47
+ __exportStar(require("./stt/types"), exports);
46
48
  exports.tts = __importStar(require("./tts"));
47
49
  __exportStar(require("./tts/types"), exports);
48
50
  exports.voiceChanger = __importStar(require("./voiceChanger"));
@@ -0,0 +1 @@
1
+ export * from "./types";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,12 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ import * as serializers from "../../../index";
5
+ import * as Cartesia from "../../../../api/index";
6
+ import * as core from "../../../../core";
7
+ export declare const DoneMessage: core.serialization.ObjectSchema<serializers.DoneMessage.Raw, Cartesia.DoneMessage>;
8
+ export declare namespace DoneMessage {
9
+ interface Raw {
10
+ request_id: string;
11
+ }
12
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ /**
3
+ * This file was auto-generated by Fern from our API Definition.
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.DoneMessage = void 0;
40
+ const core = __importStar(require("../../../../core"));
41
+ exports.DoneMessage = core.serialization.object({
42
+ requestId: core.serialization.property("request_id", core.serialization.string()),
43
+ });
@@ -0,0 +1,13 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ import * as serializers from "../../../index";
5
+ import * as Cartesia from "../../../../api/index";
6
+ import * as core from "../../../../core";
7
+ export declare const ErrorMessage: core.serialization.ObjectSchema<serializers.ErrorMessage.Raw, Cartesia.ErrorMessage>;
8
+ export declare namespace ErrorMessage {
9
+ interface Raw {
10
+ request_id?: string | null;
11
+ message: string;
12
+ }
13
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**
3
+ * This file was auto-generated by Fern from our API Definition.
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.ErrorMessage = void 0;
40
+ const core = __importStar(require("../../../../core"));
41
+ exports.ErrorMessage = core.serialization.object({
42
+ requestId: core.serialization.property("request_id", core.serialization.string().optional()),
43
+ message: core.serialization.string(),
44
+ });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ import * as serializers from "../../../index";
5
+ import * as Cartesia from "../../../../api/index";
6
+ import * as core from "../../../../core";
7
+ export declare const FlushDoneMessage: core.serialization.ObjectSchema<serializers.FlushDoneMessage.Raw, Cartesia.FlushDoneMessage>;
8
+ export declare namespace FlushDoneMessage {
9
+ interface Raw {
10
+ request_id: string;
11
+ }
12
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ /**
3
+ * This file was auto-generated by Fern from our API Definition.
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.FlushDoneMessage = void 0;
40
+ const core = __importStar(require("../../../../core"));
41
+ exports.FlushDoneMessage = core.serialization.object({
42
+ requestId: core.serialization.property("request_id", core.serialization.string()),
43
+ });
@@ -0,0 +1,26 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ import * as serializers from "../../../index";
5
+ import * as Cartesia from "../../../../api/index";
6
+ import * as core from "../../../../core";
7
+ import { TranscriptMessage } from "./TranscriptMessage";
8
+ import { FlushDoneMessage } from "./FlushDoneMessage";
9
+ import { DoneMessage } from "./DoneMessage";
10
+ import { ErrorMessage } from "./ErrorMessage";
11
+ export declare const StreamingTranscriptionResponse: core.serialization.Schema<serializers.StreamingTranscriptionResponse.Raw, Cartesia.StreamingTranscriptionResponse>;
12
+ export declare namespace StreamingTranscriptionResponse {
13
+ type Raw = StreamingTranscriptionResponse.Transcript | StreamingTranscriptionResponse.FlushDone | StreamingTranscriptionResponse.Done | StreamingTranscriptionResponse.Error;
14
+ interface Transcript extends TranscriptMessage.Raw {
15
+ type: "transcript";
16
+ }
17
+ interface FlushDone extends FlushDoneMessage.Raw {
18
+ type: "flush_done";
19
+ }
20
+ interface Done extends DoneMessage.Raw {
21
+ type: "done";
22
+ }
23
+ interface Error extends ErrorMessage.Raw {
24
+ type: "error";
25
+ }
26
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ /**
3
+ * This file was auto-generated by Fern from our API Definition.
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.StreamingTranscriptionResponse = void 0;
40
+ const core = __importStar(require("../../../../core"));
41
+ const TranscriptMessage_1 = require("./TranscriptMessage");
42
+ const FlushDoneMessage_1 = require("./FlushDoneMessage");
43
+ const DoneMessage_1 = require("./DoneMessage");
44
+ const ErrorMessage_1 = require("./ErrorMessage");
45
+ exports.StreamingTranscriptionResponse = core.serialization
46
+ .union("type", {
47
+ transcript: TranscriptMessage_1.TranscriptMessage,
48
+ flush_done: FlushDoneMessage_1.FlushDoneMessage,
49
+ done: DoneMessage_1.DoneMessage,
50
+ error: ErrorMessage_1.ErrorMessage,
51
+ })
52
+ .transform({
53
+ transform: (value) => value,
54
+ untransform: (value) => value,
55
+ });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ import * as serializers from "../../../index";
5
+ import * as Cartesia from "../../../../api/index";
6
+ import * as core from "../../../../core";
7
+ export declare const SttEncoding: core.serialization.Schema<serializers.SttEncoding.Raw, Cartesia.SttEncoding>;
8
+ export declare namespace SttEncoding {
9
+ type Raw = "pcm_s16le" | "pcm_s32le" | "pcm_f16le" | "pcm_f32le" | "pcm_mulaw" | "pcm_alaw";
10
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /**
3
+ * This file was auto-generated by Fern from our API Definition.
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.SttEncoding = void 0;
40
+ const core = __importStar(require("../../../../core"));
41
+ exports.SttEncoding = core.serialization.enum_(["pcm_s16le", "pcm_s32le", "pcm_f16le", "pcm_f32le", "pcm_mulaw", "pcm_alaw"]);