@cartesia/cartesia-js 2.0.2 → 2.0.3

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 (484) hide show
  1. package/Client.js +13 -9
  2. package/README.md +1 -5
  3. package/api/index.js +17 -1
  4. package/api/resources/apiStatus/client/Client.js +33 -6
  5. package/api/resources/apiStatus/client/index.js +2 -1
  6. package/api/resources/apiStatus/index.js +18 -2
  7. package/api/resources/apiStatus/types/ApiInfo.js +2 -1
  8. package/api/resources/apiStatus/types/index.js +17 -1
  9. package/api/resources/embedding/index.js +17 -1
  10. package/api/resources/embedding/types/Embedding.js +2 -1
  11. package/api/resources/embedding/types/index.js +17 -1
  12. package/api/resources/index.js +41 -12
  13. package/api/resources/tts/client/Client.js +40 -10
  14. package/api/resources/tts/client/index.js +2 -1
  15. package/api/resources/tts/index.js +18 -2
  16. package/api/resources/tts/types/CancelContextRequest.js +2 -1
  17. package/api/resources/tts/types/ContextId.js +2 -1
  18. package/api/resources/tts/types/Controls.js +2 -1
  19. package/api/resources/tts/types/Emotion.js +4 -1
  20. package/api/resources/tts/types/GenerationRequest.js +2 -1
  21. package/api/resources/tts/types/Mp3OutputFormat.js +2 -1
  22. package/api/resources/tts/types/NaturalSpecifier.js +4 -1
  23. package/api/resources/tts/types/NumericalSpecifier.js +2 -1
  24. package/api/resources/tts/types/OutputFormat.js +2 -1
  25. package/api/resources/tts/types/RawEncoding.js +4 -1
  26. package/api/resources/tts/types/RawOutputFormat.js +2 -1
  27. package/api/resources/tts/types/Speed.js +2 -1
  28. package/api/resources/tts/types/SupportedLanguage.js +4 -1
  29. package/api/resources/tts/types/TtsRequest.js +2 -1
  30. package/api/resources/tts/types/TtsRequestEmbeddingSpecifier.js +2 -1
  31. package/api/resources/tts/types/TtsRequestIdSpecifier.js +2 -1
  32. package/api/resources/tts/types/TtsRequestVoiceSpecifier.js +2 -1
  33. package/api/resources/tts/types/WavOutputFormat.js +2 -1
  34. package/api/resources/tts/types/WebSocketBaseResponse.js +2 -1
  35. package/api/resources/tts/types/WebSocketChunkResponse.js +2 -1
  36. package/api/resources/tts/types/WebSocketDoneResponse.js +2 -1
  37. package/api/resources/tts/types/WebSocketErrorResponse.js +2 -1
  38. package/api/resources/tts/types/WebSocketRawOutputFormat.js +2 -1
  39. package/api/resources/tts/types/WebSocketRequest.js +2 -1
  40. package/api/resources/tts/types/WebSocketResponse.js +2 -1
  41. package/api/resources/tts/types/WebSocketStreamOptions.js +2 -1
  42. package/api/resources/tts/types/WebSocketTimestampsResponse.js +2 -1
  43. package/api/resources/tts/types/WebSocketTtsOutput.js +2 -1
  44. package/api/resources/tts/types/WebSocketTtsRequest.js +2 -1
  45. package/api/resources/tts/types/WordTimestamps.js +2 -1
  46. package/api/resources/tts/types/index.js +46 -30
  47. package/api/resources/voiceChanger/client/Client.js +40 -10
  48. package/api/resources/voiceChanger/client/index.js +17 -1
  49. package/api/resources/voiceChanger/client/requests/VoiceChangerBytesRequest.js +2 -1
  50. package/api/resources/voiceChanger/client/requests/VoiceChangerSseRequest.js +2 -1
  51. package/api/resources/voiceChanger/client/requests/index.js +2 -1
  52. package/api/resources/voiceChanger/index.js +18 -2
  53. package/api/resources/voiceChanger/types/OutputFormatContainer.js +4 -1
  54. package/api/resources/voiceChanger/types/StreamingResponse.js +2 -1
  55. package/api/resources/voiceChanger/types/index.js +18 -2
  56. package/api/resources/voices/client/Client.js +52 -22
  57. package/api/resources/voices/client/index.js +17 -1
  58. package/api/resources/voices/client/requests/CloneVoiceRequest.js +2 -1
  59. package/api/resources/voices/client/requests/index.js +2 -1
  60. package/api/resources/voices/index.js +18 -2
  61. package/api/resources/voices/types/BaseVoiceId.js +2 -1
  62. package/api/resources/voices/types/CloneMode.js +4 -1
  63. package/api/resources/voices/types/CreateVoiceRequest.js +2 -1
  64. package/api/resources/voices/types/EmbeddingResponse.js +2 -1
  65. package/api/resources/voices/types/EmbeddingSpecifier.js +2 -1
  66. package/api/resources/voices/types/Gender.js +4 -1
  67. package/api/resources/voices/types/IdSpecifier.js +2 -1
  68. package/api/resources/voices/types/LocalizeDialect.js +4 -1
  69. package/api/resources/voices/types/LocalizeTargetLanguage.js +4 -1
  70. package/api/resources/voices/types/LocalizeVoiceRequest.js +2 -1
  71. package/api/resources/voices/types/MixVoiceSpecifier.js +2 -1
  72. package/api/resources/voices/types/MixVoicesRequest.js +2 -1
  73. package/api/resources/voices/types/UpdateVoiceRequest.js +2 -1
  74. package/api/resources/voices/types/Voice.js +2 -1
  75. package/api/resources/voices/types/VoiceId.js +2 -1
  76. package/api/resources/voices/types/VoiceMetadata.js +2 -1
  77. package/api/resources/voices/types/Weight.js +2 -1
  78. package/api/resources/voices/types/index.js +33 -17
  79. package/core/fetcher/APIResponse.js +2 -1
  80. package/core/fetcher/Fetcher.js +18 -14
  81. package/core/fetcher/Supplier.js +4 -1
  82. package/core/fetcher/createRequestUrl.js +10 -3
  83. package/core/fetcher/getFetchFn.js +33 -6
  84. package/core/fetcher/getHeader.js +5 -1
  85. package/core/fetcher/getRequestBody.js +5 -1
  86. package/core/fetcher/getResponseBody.js +7 -3
  87. package/core/fetcher/index.js +9 -3
  88. package/core/fetcher/makeRequest.js +8 -4
  89. package/core/fetcher/requestWithRetries.js +5 -1
  90. package/core/fetcher/signals.js +7 -2
  91. package/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.js +5 -1
  92. package/core/fetcher/stream-wrappers/NodePre18StreamWrapper.js +5 -1
  93. package/core/fetcher/stream-wrappers/UndiciStreamWrapper.js +5 -1
  94. package/core/fetcher/stream-wrappers/chooseStreamWrapper.js +34 -7
  95. package/core/form-data-utils/FormDataWrapper.js +41 -11
  96. package/core/form-data-utils/index.js +17 -1
  97. package/core/index.js +34 -5
  98. package/core/runtime/index.js +5 -1
  99. package/core/runtime/runtime.js +4 -1
  100. package/core/schemas/Schema.js +4 -1
  101. package/core/schemas/builders/bigint/bigint.js +13 -9
  102. package/core/schemas/builders/bigint/index.js +5 -1
  103. package/core/schemas/builders/date/date.js +14 -10
  104. package/core/schemas/builders/date/index.js +5 -1
  105. package/core/schemas/builders/enum/enum.js +11 -7
  106. package/core/schemas/builders/enum/index.js +5 -1
  107. package/core/schemas/builders/index.js +30 -14
  108. package/core/schemas/builders/lazy/index.js +7 -2
  109. package/core/schemas/builders/lazy/lazy.js +11 -5
  110. package/core/schemas/builders/lazy/lazyObject.js +11 -7
  111. package/core/schemas/builders/list/index.js +5 -1
  112. package/core/schemas/builders/list/list.js +12 -8
  113. package/core/schemas/builders/literals/booleanLiteral.js +10 -6
  114. package/core/schemas/builders/literals/index.js +7 -2
  115. package/core/schemas/builders/literals/stringLiteral.js +10 -6
  116. package/core/schemas/builders/object/index.js +11 -3
  117. package/core/schemas/builders/object/object.js +38 -33
  118. package/core/schemas/builders/object/objectWithoutOptionalProperties.js +7 -3
  119. package/core/schemas/builders/object/property.js +7 -2
  120. package/core/schemas/builders/object/types.js +2 -1
  121. package/core/schemas/builders/object-like/getObjectLikeUtils.js +15 -10
  122. package/core/schemas/builders/object-like/index.js +6 -1
  123. package/core/schemas/builders/object-like/types.js +2 -1
  124. package/core/schemas/builders/primitives/any.js +6 -3
  125. package/core/schemas/builders/primitives/boolean.js +8 -5
  126. package/core/schemas/builders/primitives/index.js +13 -5
  127. package/core/schemas/builders/primitives/number.js +8 -5
  128. package/core/schemas/builders/primitives/string.js +8 -5
  129. package/core/schemas/builders/primitives/unknown.js +6 -3
  130. package/core/schemas/builders/record/index.js +5 -1
  131. package/core/schemas/builders/record/record.js +18 -14
  132. package/core/schemas/builders/record/types.js +2 -1
  133. package/core/schemas/builders/schema-utils/JsonError.js +7 -3
  134. package/core/schemas/builders/schema-utils/ParseError.js +7 -3
  135. package/core/schemas/builders/schema-utils/getSchemaUtils.js +15 -9
  136. package/core/schemas/builders/schema-utils/index.js +11 -3
  137. package/core/schemas/builders/schema-utils/stringifyValidationErrors.js +5 -1
  138. package/core/schemas/builders/set/index.js +5 -1
  139. package/core/schemas/builders/set/set.js +14 -10
  140. package/core/schemas/builders/undiscriminated-union/index.js +5 -1
  141. package/core/schemas/builders/undiscriminated-union/types.js +2 -1
  142. package/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.js +10 -6
  143. package/core/schemas/builders/union/discriminant.js +5 -1
  144. package/core/schemas/builders/union/index.js +7 -2
  145. package/core/schemas/builders/union/types.js +2 -1
  146. package/core/schemas/builders/union/union.js +18 -14
  147. package/core/schemas/index.js +17 -1
  148. package/core/schemas/utils/MaybePromise.js +2 -1
  149. package/core/schemas/utils/addQuestionMarksToNullableProperties.js +2 -1
  150. package/core/schemas/utils/createIdentitySchemaCreator.js +8 -4
  151. package/core/schemas/utils/entries.js +5 -1
  152. package/core/schemas/utils/filterObject.js +5 -1
  153. package/core/schemas/utils/getErrorMessageForIncorrectType.js +5 -1
  154. package/core/schemas/utils/isPlainObject.js +5 -1
  155. package/core/schemas/utils/keys.js +5 -1
  156. package/core/schemas/utils/maybeSkipValidation.js +5 -1
  157. package/core/schemas/utils/partition.js +5 -1
  158. package/core/streaming-fetcher/Stream.js +9 -4
  159. package/core/streaming-fetcher/index.js +5 -1
  160. package/core/websocket/events.js +9 -3
  161. package/core/websocket/index.js +17 -1
  162. package/core/websocket/ws.js +33 -6
  163. package/dist/Client.js +13 -9
  164. package/dist/api/index.js +17 -1
  165. package/dist/api/resources/apiStatus/client/Client.js +33 -6
  166. package/dist/api/resources/apiStatus/client/index.js +2 -1
  167. package/dist/api/resources/apiStatus/index.js +18 -2
  168. package/dist/api/resources/apiStatus/types/ApiInfo.js +2 -1
  169. package/dist/api/resources/apiStatus/types/index.js +17 -1
  170. package/dist/api/resources/embedding/index.js +17 -1
  171. package/dist/api/resources/embedding/types/Embedding.js +2 -1
  172. package/dist/api/resources/embedding/types/index.js +17 -1
  173. package/dist/api/resources/index.js +41 -12
  174. package/dist/api/resources/tts/client/Client.js +40 -10
  175. package/dist/api/resources/tts/client/index.js +2 -1
  176. package/dist/api/resources/tts/index.js +18 -2
  177. package/dist/api/resources/tts/types/CancelContextRequest.js +2 -1
  178. package/dist/api/resources/tts/types/ContextId.js +2 -1
  179. package/dist/api/resources/tts/types/Controls.js +2 -1
  180. package/dist/api/resources/tts/types/Emotion.js +4 -1
  181. package/dist/api/resources/tts/types/GenerationRequest.js +2 -1
  182. package/dist/api/resources/tts/types/Mp3OutputFormat.js +2 -1
  183. package/dist/api/resources/tts/types/NaturalSpecifier.js +4 -1
  184. package/dist/api/resources/tts/types/NumericalSpecifier.js +2 -1
  185. package/dist/api/resources/tts/types/OutputFormat.js +2 -1
  186. package/dist/api/resources/tts/types/RawEncoding.js +4 -1
  187. package/dist/api/resources/tts/types/RawOutputFormat.js +2 -1
  188. package/dist/api/resources/tts/types/Speed.js +2 -1
  189. package/dist/api/resources/tts/types/SupportedLanguage.js +4 -1
  190. package/dist/api/resources/tts/types/TtsRequest.js +2 -1
  191. package/dist/api/resources/tts/types/TtsRequestEmbeddingSpecifier.js +2 -1
  192. package/dist/api/resources/tts/types/TtsRequestIdSpecifier.js +2 -1
  193. package/dist/api/resources/tts/types/TtsRequestVoiceSpecifier.js +2 -1
  194. package/dist/api/resources/tts/types/WavOutputFormat.js +2 -1
  195. package/dist/api/resources/tts/types/WebSocketBaseResponse.js +2 -1
  196. package/dist/api/resources/tts/types/WebSocketChunkResponse.js +2 -1
  197. package/dist/api/resources/tts/types/WebSocketDoneResponse.js +2 -1
  198. package/dist/api/resources/tts/types/WebSocketErrorResponse.js +2 -1
  199. package/dist/api/resources/tts/types/WebSocketRawOutputFormat.js +2 -1
  200. package/dist/api/resources/tts/types/WebSocketRequest.js +2 -1
  201. package/dist/api/resources/tts/types/WebSocketResponse.js +2 -1
  202. package/dist/api/resources/tts/types/WebSocketStreamOptions.js +2 -1
  203. package/dist/api/resources/tts/types/WebSocketTimestampsResponse.js +2 -1
  204. package/dist/api/resources/tts/types/WebSocketTtsOutput.js +2 -1
  205. package/dist/api/resources/tts/types/WebSocketTtsRequest.js +2 -1
  206. package/dist/api/resources/tts/types/WordTimestamps.js +2 -1
  207. package/dist/api/resources/tts/types/index.js +46 -30
  208. package/dist/api/resources/voiceChanger/client/Client.js +40 -10
  209. package/dist/api/resources/voiceChanger/client/index.js +17 -1
  210. package/dist/api/resources/voiceChanger/client/requests/VoiceChangerBytesRequest.js +2 -1
  211. package/dist/api/resources/voiceChanger/client/requests/VoiceChangerSseRequest.js +2 -1
  212. package/dist/api/resources/voiceChanger/client/requests/index.js +2 -1
  213. package/dist/api/resources/voiceChanger/index.js +18 -2
  214. package/dist/api/resources/voiceChanger/types/OutputFormatContainer.js +4 -1
  215. package/dist/api/resources/voiceChanger/types/StreamingResponse.js +2 -1
  216. package/dist/api/resources/voiceChanger/types/index.js +18 -2
  217. package/dist/api/resources/voices/client/Client.js +52 -22
  218. package/dist/api/resources/voices/client/index.js +17 -1
  219. package/dist/api/resources/voices/client/requests/CloneVoiceRequest.js +2 -1
  220. package/dist/api/resources/voices/client/requests/index.js +2 -1
  221. package/dist/api/resources/voices/index.js +18 -2
  222. package/dist/api/resources/voices/types/BaseVoiceId.js +2 -1
  223. package/dist/api/resources/voices/types/CloneMode.js +4 -1
  224. package/dist/api/resources/voices/types/CreateVoiceRequest.js +2 -1
  225. package/dist/api/resources/voices/types/EmbeddingResponse.js +2 -1
  226. package/dist/api/resources/voices/types/EmbeddingSpecifier.js +2 -1
  227. package/dist/api/resources/voices/types/Gender.js +4 -1
  228. package/dist/api/resources/voices/types/IdSpecifier.js +2 -1
  229. package/dist/api/resources/voices/types/LocalizeDialect.js +4 -1
  230. package/dist/api/resources/voices/types/LocalizeTargetLanguage.js +4 -1
  231. package/dist/api/resources/voices/types/LocalizeVoiceRequest.js +2 -1
  232. package/dist/api/resources/voices/types/MixVoiceSpecifier.js +2 -1
  233. package/dist/api/resources/voices/types/MixVoicesRequest.js +2 -1
  234. package/dist/api/resources/voices/types/UpdateVoiceRequest.js +2 -1
  235. package/dist/api/resources/voices/types/Voice.js +2 -1
  236. package/dist/api/resources/voices/types/VoiceId.js +2 -1
  237. package/dist/api/resources/voices/types/VoiceMetadata.js +2 -1
  238. package/dist/api/resources/voices/types/Weight.js +2 -1
  239. package/dist/api/resources/voices/types/index.js +33 -17
  240. package/dist/core/fetcher/APIResponse.js +2 -1
  241. package/dist/core/fetcher/Fetcher.js +18 -14
  242. package/dist/core/fetcher/Supplier.js +4 -1
  243. package/dist/core/fetcher/createRequestUrl.js +10 -3
  244. package/dist/core/fetcher/getFetchFn.js +33 -6
  245. package/dist/core/fetcher/getHeader.js +5 -1
  246. package/dist/core/fetcher/getRequestBody.js +5 -1
  247. package/dist/core/fetcher/getResponseBody.js +7 -3
  248. package/dist/core/fetcher/index.js +9 -3
  249. package/dist/core/fetcher/makeRequest.js +8 -4
  250. package/dist/core/fetcher/requestWithRetries.js +5 -1
  251. package/dist/core/fetcher/signals.js +7 -2
  252. package/dist/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.js +5 -1
  253. package/dist/core/fetcher/stream-wrappers/NodePre18StreamWrapper.js +5 -1
  254. package/dist/core/fetcher/stream-wrappers/UndiciStreamWrapper.js +5 -1
  255. package/dist/core/fetcher/stream-wrappers/chooseStreamWrapper.js +34 -7
  256. package/dist/core/form-data-utils/FormDataWrapper.js +41 -11
  257. package/dist/core/form-data-utils/index.js +17 -1
  258. package/dist/core/index.js +34 -5
  259. package/dist/core/runtime/index.js +5 -1
  260. package/dist/core/runtime/runtime.js +4 -1
  261. package/dist/core/schemas/Schema.js +4 -1
  262. package/dist/core/schemas/builders/bigint/bigint.js +13 -9
  263. package/dist/core/schemas/builders/bigint/index.js +5 -1
  264. package/dist/core/schemas/builders/date/date.js +14 -10
  265. package/dist/core/schemas/builders/date/index.js +5 -1
  266. package/dist/core/schemas/builders/enum/enum.js +11 -7
  267. package/dist/core/schemas/builders/enum/index.js +5 -1
  268. package/dist/core/schemas/builders/index.js +30 -14
  269. package/dist/core/schemas/builders/lazy/index.js +7 -2
  270. package/dist/core/schemas/builders/lazy/lazy.js +11 -5
  271. package/dist/core/schemas/builders/lazy/lazyObject.js +11 -7
  272. package/dist/core/schemas/builders/list/index.js +5 -1
  273. package/dist/core/schemas/builders/list/list.js +12 -8
  274. package/dist/core/schemas/builders/literals/booleanLiteral.js +10 -6
  275. package/dist/core/schemas/builders/literals/index.js +7 -2
  276. package/dist/core/schemas/builders/literals/stringLiteral.js +10 -6
  277. package/dist/core/schemas/builders/object/index.js +11 -3
  278. package/dist/core/schemas/builders/object/object.js +38 -33
  279. package/dist/core/schemas/builders/object/objectWithoutOptionalProperties.js +7 -3
  280. package/dist/core/schemas/builders/object/property.js +7 -2
  281. package/dist/core/schemas/builders/object/types.js +2 -1
  282. package/dist/core/schemas/builders/object-like/getObjectLikeUtils.js +15 -10
  283. package/dist/core/schemas/builders/object-like/index.js +6 -1
  284. package/dist/core/schemas/builders/object-like/types.js +2 -1
  285. package/dist/core/schemas/builders/primitives/any.js +6 -3
  286. package/dist/core/schemas/builders/primitives/boolean.js +8 -5
  287. package/dist/core/schemas/builders/primitives/index.js +13 -5
  288. package/dist/core/schemas/builders/primitives/number.js +8 -5
  289. package/dist/core/schemas/builders/primitives/string.js +8 -5
  290. package/dist/core/schemas/builders/primitives/unknown.js +6 -3
  291. package/dist/core/schemas/builders/record/index.js +5 -1
  292. package/dist/core/schemas/builders/record/record.js +18 -14
  293. package/dist/core/schemas/builders/record/types.js +2 -1
  294. package/dist/core/schemas/builders/schema-utils/JsonError.js +7 -3
  295. package/dist/core/schemas/builders/schema-utils/ParseError.js +7 -3
  296. package/dist/core/schemas/builders/schema-utils/getSchemaUtils.js +15 -9
  297. package/dist/core/schemas/builders/schema-utils/index.js +11 -3
  298. package/dist/core/schemas/builders/schema-utils/stringifyValidationErrors.js +5 -1
  299. package/dist/core/schemas/builders/set/index.js +5 -1
  300. package/dist/core/schemas/builders/set/set.js +14 -10
  301. package/dist/core/schemas/builders/undiscriminated-union/index.js +5 -1
  302. package/dist/core/schemas/builders/undiscriminated-union/types.js +2 -1
  303. package/dist/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.js +10 -6
  304. package/dist/core/schemas/builders/union/discriminant.js +5 -1
  305. package/dist/core/schemas/builders/union/index.js +7 -2
  306. package/dist/core/schemas/builders/union/types.js +2 -1
  307. package/dist/core/schemas/builders/union/union.js +18 -14
  308. package/dist/core/schemas/index.js +17 -1
  309. package/dist/core/schemas/utils/MaybePromise.js +2 -1
  310. package/dist/core/schemas/utils/addQuestionMarksToNullableProperties.js +2 -1
  311. package/dist/core/schemas/utils/createIdentitySchemaCreator.js +8 -4
  312. package/dist/core/schemas/utils/entries.js +5 -1
  313. package/dist/core/schemas/utils/filterObject.js +5 -1
  314. package/dist/core/schemas/utils/getErrorMessageForIncorrectType.js +5 -1
  315. package/dist/core/schemas/utils/isPlainObject.js +5 -1
  316. package/dist/core/schemas/utils/keys.js +5 -1
  317. package/dist/core/schemas/utils/maybeSkipValidation.js +5 -1
  318. package/dist/core/schemas/utils/partition.js +5 -1
  319. package/dist/core/streaming-fetcher/Stream.js +9 -4
  320. package/dist/core/streaming-fetcher/index.js +5 -1
  321. package/dist/core/websocket/events.js +9 -3
  322. package/dist/core/websocket/index.js +17 -1
  323. package/dist/core/websocket/ws.js +33 -6
  324. package/dist/environments.js +4 -1
  325. package/dist/errors/CartesiaError.js +5 -1
  326. package/dist/errors/CartesiaTimeoutError.js +5 -1
  327. package/dist/errors/index.js +7 -2
  328. package/dist/index.js +34 -4
  329. package/dist/serialization/index.js +17 -1
  330. package/dist/serialization/resources/apiStatus/index.js +17 -1
  331. package/dist/serialization/resources/apiStatus/types/ApiInfo.js +28 -2
  332. package/dist/serialization/resources/apiStatus/types/index.js +17 -1
  333. package/dist/serialization/resources/embedding/index.js +17 -1
  334. package/dist/serialization/resources/embedding/types/Embedding.js +28 -2
  335. package/dist/serialization/resources/embedding/types/index.js +17 -1
  336. package/dist/serialization/resources/index.js +39 -10
  337. package/dist/serialization/resources/tts/index.js +17 -1
  338. package/dist/serialization/resources/tts/types/CancelContextRequest.js +30 -4
  339. package/dist/serialization/resources/tts/types/ContextId.js +28 -2
  340. package/dist/serialization/resources/tts/types/Controls.js +32 -6
  341. package/dist/serialization/resources/tts/types/Emotion.js +28 -2
  342. package/dist/serialization/resources/tts/types/GenerationRequest.js +36 -10
  343. package/dist/serialization/resources/tts/types/Mp3OutputFormat.js +28 -2
  344. package/dist/serialization/resources/tts/types/NaturalSpecifier.js +28 -2
  345. package/dist/serialization/resources/tts/types/NumericalSpecifier.js +28 -2
  346. package/dist/serialization/resources/tts/types/OutputFormat.js +34 -8
  347. package/dist/serialization/resources/tts/types/RawEncoding.js +28 -2
  348. package/dist/serialization/resources/tts/types/RawOutputFormat.js +30 -4
  349. package/dist/serialization/resources/tts/types/Speed.js +30 -4
  350. package/dist/serialization/resources/tts/types/SupportedLanguage.js +28 -2
  351. package/dist/serialization/resources/tts/types/TtsRequest.js +34 -8
  352. package/dist/serialization/resources/tts/types/TtsRequestEmbeddingSpecifier.js +32 -6
  353. package/dist/serialization/resources/tts/types/TtsRequestIdSpecifier.js +32 -6
  354. package/dist/serialization/resources/tts/types/TtsRequestVoiceSpecifier.js +30 -4
  355. package/dist/serialization/resources/tts/types/WavOutputFormat.js +29 -3
  356. package/dist/serialization/resources/tts/types/WebSocketBaseResponse.js +30 -4
  357. package/dist/serialization/resources/tts/types/WebSocketChunkResponse.js +30 -4
  358. package/dist/serialization/resources/tts/types/WebSocketDoneResponse.js +29 -3
  359. package/dist/serialization/resources/tts/types/WebSocketErrorResponse.js +30 -4
  360. package/dist/serialization/resources/tts/types/WebSocketRawOutputFormat.js +30 -4
  361. package/dist/serialization/resources/tts/types/WebSocketRequest.js +30 -4
  362. package/dist/serialization/resources/tts/types/WebSocketResponse.js +36 -10
  363. package/dist/serialization/resources/tts/types/WebSocketStreamOptions.js +28 -2
  364. package/dist/serialization/resources/tts/types/WebSocketTimestampsResponse.js +32 -6
  365. package/dist/serialization/resources/tts/types/WebSocketTtsOutput.js +32 -6
  366. package/dist/serialization/resources/tts/types/WebSocketTtsRequest.js +32 -6
  367. package/dist/serialization/resources/tts/types/WordTimestamps.js +28 -2
  368. package/dist/serialization/resources/tts/types/index.js +46 -30
  369. package/dist/serialization/resources/voiceChanger/index.js +17 -1
  370. package/dist/serialization/resources/voiceChanger/types/OutputFormatContainer.js +28 -2
  371. package/dist/serialization/resources/voiceChanger/types/StreamingResponse.js +34 -8
  372. package/dist/serialization/resources/voiceChanger/types/index.js +18 -2
  373. package/dist/serialization/resources/voices/client/index.js +27 -1
  374. package/dist/serialization/resources/voices/client/list.js +29 -3
  375. package/dist/serialization/resources/voices/index.js +18 -2
  376. package/dist/serialization/resources/voices/types/BaseVoiceId.js +5 -2
  377. package/dist/serialization/resources/voices/types/CloneMode.js +28 -2
  378. package/dist/serialization/resources/voices/types/CreateVoiceRequest.js +34 -8
  379. package/dist/serialization/resources/voices/types/EmbeddingResponse.js +30 -4
  380. package/dist/serialization/resources/voices/types/EmbeddingSpecifier.js +32 -6
  381. package/dist/serialization/resources/voices/types/Gender.js +28 -2
  382. package/dist/serialization/resources/voices/types/IdSpecifier.js +32 -6
  383. package/dist/serialization/resources/voices/types/LocalizeDialect.js +28 -2
  384. package/dist/serialization/resources/voices/types/LocalizeTargetLanguage.js +28 -2
  385. package/dist/serialization/resources/voices/types/LocalizeVoiceRequest.js +36 -10
  386. package/dist/serialization/resources/voices/types/MixVoiceSpecifier.js +30 -4
  387. package/dist/serialization/resources/voices/types/MixVoicesRequest.js +30 -4
  388. package/dist/serialization/resources/voices/types/UpdateVoiceRequest.js +28 -2
  389. package/dist/serialization/resources/voices/types/Voice.js +36 -10
  390. package/dist/serialization/resources/voices/types/VoiceId.js +28 -2
  391. package/dist/serialization/resources/voices/types/VoiceMetadata.js +32 -6
  392. package/dist/serialization/resources/voices/types/Weight.js +28 -2
  393. package/dist/serialization/resources/voices/types/index.js +33 -17
  394. package/dist/version.d.ts +1 -1
  395. package/dist/version.js +4 -1
  396. package/dist/wrapper/Client.js +8 -4
  397. package/dist/wrapper/StreamingTTSClient.js +11 -4
  398. package/dist/wrapper/WebPlayer.js +7 -3
  399. package/dist/wrapper/Websocket.d.ts +7 -24
  400. package/dist/wrapper/Websocket.js +101 -71
  401. package/dist/wrapper/source.d.ts +5 -4
  402. package/dist/wrapper/source.js +12 -6
  403. package/dist/wrapper/utils.js +28 -13
  404. package/environments.js +4 -1
  405. package/errors/CartesiaError.js +5 -1
  406. package/errors/CartesiaTimeoutError.js +5 -1
  407. package/errors/index.js +7 -2
  408. package/index.js +34 -4
  409. package/package.json +2 -2
  410. package/serialization/index.js +17 -1
  411. package/serialization/resources/apiStatus/index.js +17 -1
  412. package/serialization/resources/apiStatus/types/ApiInfo.js +28 -2
  413. package/serialization/resources/apiStatus/types/index.js +17 -1
  414. package/serialization/resources/embedding/index.js +17 -1
  415. package/serialization/resources/embedding/types/Embedding.js +28 -2
  416. package/serialization/resources/embedding/types/index.js +17 -1
  417. package/serialization/resources/index.js +39 -10
  418. package/serialization/resources/tts/index.js +17 -1
  419. package/serialization/resources/tts/types/CancelContextRequest.js +30 -4
  420. package/serialization/resources/tts/types/ContextId.js +28 -2
  421. package/serialization/resources/tts/types/Controls.js +32 -6
  422. package/serialization/resources/tts/types/Emotion.js +28 -2
  423. package/serialization/resources/tts/types/GenerationRequest.js +36 -10
  424. package/serialization/resources/tts/types/Mp3OutputFormat.js +28 -2
  425. package/serialization/resources/tts/types/NaturalSpecifier.js +28 -2
  426. package/serialization/resources/tts/types/NumericalSpecifier.js +28 -2
  427. package/serialization/resources/tts/types/OutputFormat.js +34 -8
  428. package/serialization/resources/tts/types/RawEncoding.js +28 -2
  429. package/serialization/resources/tts/types/RawOutputFormat.js +30 -4
  430. package/serialization/resources/tts/types/Speed.js +30 -4
  431. package/serialization/resources/tts/types/SupportedLanguage.js +28 -2
  432. package/serialization/resources/tts/types/TtsRequest.js +34 -8
  433. package/serialization/resources/tts/types/TtsRequestEmbeddingSpecifier.js +32 -6
  434. package/serialization/resources/tts/types/TtsRequestIdSpecifier.js +32 -6
  435. package/serialization/resources/tts/types/TtsRequestVoiceSpecifier.js +30 -4
  436. package/serialization/resources/tts/types/WavOutputFormat.js +29 -3
  437. package/serialization/resources/tts/types/WebSocketBaseResponse.js +30 -4
  438. package/serialization/resources/tts/types/WebSocketChunkResponse.js +30 -4
  439. package/serialization/resources/tts/types/WebSocketDoneResponse.js +29 -3
  440. package/serialization/resources/tts/types/WebSocketErrorResponse.js +30 -4
  441. package/serialization/resources/tts/types/WebSocketRawOutputFormat.js +30 -4
  442. package/serialization/resources/tts/types/WebSocketRequest.js +30 -4
  443. package/serialization/resources/tts/types/WebSocketResponse.js +36 -10
  444. package/serialization/resources/tts/types/WebSocketStreamOptions.js +28 -2
  445. package/serialization/resources/tts/types/WebSocketTimestampsResponse.js +32 -6
  446. package/serialization/resources/tts/types/WebSocketTtsOutput.js +32 -6
  447. package/serialization/resources/tts/types/WebSocketTtsRequest.js +32 -6
  448. package/serialization/resources/tts/types/WordTimestamps.js +28 -2
  449. package/serialization/resources/tts/types/index.js +46 -30
  450. package/serialization/resources/voiceChanger/index.js +17 -1
  451. package/serialization/resources/voiceChanger/types/OutputFormatContainer.js +28 -2
  452. package/serialization/resources/voiceChanger/types/StreamingResponse.js +34 -8
  453. package/serialization/resources/voiceChanger/types/index.js +18 -2
  454. package/serialization/resources/voices/client/index.js +27 -1
  455. package/serialization/resources/voices/client/list.js +29 -3
  456. package/serialization/resources/voices/index.js +18 -2
  457. package/serialization/resources/voices/types/BaseVoiceId.js +5 -2
  458. package/serialization/resources/voices/types/CloneMode.js +28 -2
  459. package/serialization/resources/voices/types/CreateVoiceRequest.js +34 -8
  460. package/serialization/resources/voices/types/EmbeddingResponse.js +30 -4
  461. package/serialization/resources/voices/types/EmbeddingSpecifier.js +32 -6
  462. package/serialization/resources/voices/types/Gender.js +28 -2
  463. package/serialization/resources/voices/types/IdSpecifier.js +32 -6
  464. package/serialization/resources/voices/types/LocalizeDialect.js +28 -2
  465. package/serialization/resources/voices/types/LocalizeTargetLanguage.js +28 -2
  466. package/serialization/resources/voices/types/LocalizeVoiceRequest.js +36 -10
  467. package/serialization/resources/voices/types/MixVoiceSpecifier.js +30 -4
  468. package/serialization/resources/voices/types/MixVoicesRequest.js +30 -4
  469. package/serialization/resources/voices/types/UpdateVoiceRequest.js +28 -2
  470. package/serialization/resources/voices/types/Voice.js +36 -10
  471. package/serialization/resources/voices/types/VoiceId.js +28 -2
  472. package/serialization/resources/voices/types/VoiceMetadata.js +32 -6
  473. package/serialization/resources/voices/types/Weight.js +28 -2
  474. package/serialization/resources/voices/types/index.js +33 -17
  475. package/version.d.ts +1 -1
  476. package/version.js +4 -1
  477. package/wrapper/Client.js +8 -4
  478. package/wrapper/StreamingTTSClient.js +11 -4
  479. package/wrapper/WebPlayer.js +7 -3
  480. package/wrapper/Websocket.d.ts +7 -24
  481. package/wrapper/Websocket.js +101 -71
  482. package/wrapper/source.d.ts +5 -4
  483. package/wrapper/source.js +12 -6
  484. package/wrapper/utils.js +28 -13
@@ -1,3 +1,27 @@
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
1
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -18,17 +42,21 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
18
42
  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");
19
43
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
44
  };
45
+ var __importDefault = (this && this.__importDefault) || function (mod) {
46
+ return (mod && mod.__esModule) ? mod : { "default": mod };
47
+ };
21
48
  var _Websocket_instances, _Websocket_isConnected, _Websocket_sampleRate, _Websocket_container, _Websocket_encoding, _Websocket_generateId;
22
- import * as core from "../core";
23
- import * as environments from "../environments";
24
- import * as serializers from "../serialization";
25
- import Emittery from "emittery";
26
- import { humanId } from "human-id";
27
- import { ReconnectingWebSocket } from "../core/websocket";
28
- import { base64ToArray, resolveOutputFormat, createMessageHandlerForContextId, getEmitteryCallbacks, isSentinel, } from "./utils";
29
- import Source from "./source";
30
- import qs from "qs";
31
- export default class Websocket {
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ const core = __importStar(require("../core"));
51
+ const environments = __importStar(require("../environments"));
52
+ const serializers = __importStar(require("../serialization"));
53
+ const emittery_1 = __importDefault(require("emittery"));
54
+ const human_id_1 = require("human-id");
55
+ const websocket_1 = require("../core/websocket");
56
+ const utils_1 = require("./utils");
57
+ const source_1 = __importDefault(require("./source"));
58
+ const qs_1 = __importDefault(require("qs"));
59
+ class Websocket {
32
60
  constructor({ sampleRate, container, encoding }, options) {
33
61
  this.options = options;
34
62
  _Websocket_instances.add(this);
@@ -49,69 +77,70 @@ export default class Websocket {
49
77
  * If set to `0`, the stream will not time out.
50
78
  * @returns A Source object that can be passed to a Player to play the audio.
51
79
  * @returns An Emittery instance that emits messages from the WebSocket.
52
- * @returns An abort function that can be called to cancel the stream.
53
80
  */
54
81
  send(inputs, { timeout = 0 } = {}) {
55
82
  var _a, _b, _c, _d;
56
- if (!__classPrivateFieldGet(this, _Websocket_isConnected, "f")) {
57
- throw new Error("Not connected to WebSocket. Call .connect() first.");
58
- }
59
- if (!inputs.contextId) {
60
- inputs.contextId = __classPrivateFieldGet(this, _Websocket_instances, "m", _Websocket_generateId).call(this);
61
- }
62
- if (!inputs.outputFormat) {
63
- inputs.outputFormat = resolveOutputFormat(__classPrivateFieldGet(this, _Websocket_container, "f"), __classPrivateFieldGet(this, _Websocket_encoding, "f"), __classPrivateFieldGet(this, _Websocket_sampleRate, "f"));
64
- }
65
- (_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(serializers.WebSocketTtsRequest.jsonOrThrow(inputs, { unrecognizedObjectKeys: "strip" })));
66
- const emitter = new Emittery();
67
- const source = new Source({
68
- sampleRate: __classPrivateFieldGet(this, _Websocket_sampleRate, "f"),
69
- encoding: __classPrivateFieldGet(this, _Websocket_encoding, "f"),
70
- container: __classPrivateFieldGet(this, _Websocket_container, "f"),
71
- });
72
- // Used to signal that the stream is complete, either because the
73
- // WebSocket has closed, or because the stream has finished.
74
- const streamCompleteController = new AbortController();
75
- // Set a timeout.
76
- let timeoutId = null;
77
- if (timeout > 0) {
78
- timeoutId = setTimeout(streamCompleteController.abort, timeout);
79
- }
80
- const handleMessage = createMessageHandlerForContextId(inputs.contextId, ({ chunk, message, data }) => __awaiter(this, void 0, void 0, function* () {
81
- emitter.emit("message", message);
82
- if (data.type === "timestamps" && data.wordTimestamps) {
83
- emitter.emit("timestamps", data.wordTimestamps);
84
- return;
85
- }
86
- if (isSentinel(chunk)) {
87
- yield source.close();
88
- streamCompleteController.abort();
89
- return;
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ if (!__classPrivateFieldGet(this, _Websocket_isConnected, "f")) {
85
+ throw new Error("Not connected to WebSocket. Call .connect() first.");
90
86
  }
91
- if (timeoutId) {
92
- clearTimeout(timeoutId);
93
- timeoutId = setTimeout(streamCompleteController.abort, timeout);
87
+ if (!inputs.contextId) {
88
+ inputs.contextId = __classPrivateFieldGet(this, _Websocket_instances, "m", _Websocket_generateId).call(this);
94
89
  }
95
- if (!chunk) {
96
- return;
90
+ if (!inputs.outputFormat) {
91
+ inputs.outputFormat = (0, utils_1.resolveOutputFormat)(__classPrivateFieldGet(this, _Websocket_container, "f"), __classPrivateFieldGet(this, _Websocket_encoding, "f"), __classPrivateFieldGet(this, _Websocket_sampleRate, "f"));
97
92
  }
98
- yield source.enqueue(base64ToArray([chunk], __classPrivateFieldGet(this, _Websocket_encoding, "f")));
99
- }));
100
- (_b = this.socket) === null || _b === void 0 ? void 0 : _b.addEventListener("message", handleMessage);
101
- (_c = this.socket) === null || _c === void 0 ? void 0 : _c.addEventListener("close", () => {
102
- streamCompleteController.abort();
103
- });
104
- (_d = this.socket) === null || _d === void 0 ? void 0 : _d.addEventListener("error", () => {
105
- streamCompleteController.abort();
106
- });
107
- streamCompleteController.signal.addEventListener("abort", () => {
108
- source.close();
109
- if (timeoutId) {
110
- clearTimeout(timeoutId);
93
+ (_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(serializers.WebSocketTtsRequest.jsonOrThrow(inputs, { unrecognizedObjectKeys: "strip" })));
94
+ const emitter = new emittery_1.default();
95
+ const source = new source_1.default({
96
+ sampleRate: __classPrivateFieldGet(this, _Websocket_sampleRate, "f"),
97
+ encoding: __classPrivateFieldGet(this, _Websocket_encoding, "f"),
98
+ container: __classPrivateFieldGet(this, _Websocket_container, "f"),
99
+ });
100
+ // Used to signal that the stream is complete, either because the
101
+ // WebSocket has closed, or because the stream has finished.
102
+ const streamCompleteController = new AbortController();
103
+ // Set a timeout.
104
+ let timeoutId = null;
105
+ if (timeout > 0) {
106
+ timeoutId = setTimeout(streamCompleteController.abort, timeout);
111
107
  }
112
- emitter.clearListeners();
108
+ const handleMessage = (0, utils_1.createMessageHandlerForContextId)(inputs.contextId, ({ chunk, message, data }) => __awaiter(this, void 0, void 0, function* () {
109
+ emitter.emit("message", message);
110
+ if (data.type === "timestamps" && data.wordTimestamps) {
111
+ emitter.emit("timestamps", data.wordTimestamps);
112
+ return;
113
+ }
114
+ if ((0, utils_1.isSentinel)(chunk)) {
115
+ yield source.close();
116
+ streamCompleteController.abort();
117
+ return;
118
+ }
119
+ if (timeoutId) {
120
+ clearTimeout(timeoutId);
121
+ timeoutId = setTimeout(streamCompleteController.abort, timeout);
122
+ }
123
+ if (!chunk) {
124
+ return;
125
+ }
126
+ yield source.enqueue((0, utils_1.base64ToArray)([chunk], __classPrivateFieldGet(this, _Websocket_encoding, "f")));
127
+ }));
128
+ (_b = this.socket) === null || _b === void 0 ? void 0 : _b.addEventListener("message", handleMessage);
129
+ (_c = this.socket) === null || _c === void 0 ? void 0 : _c.addEventListener("close", () => {
130
+ streamCompleteController.abort();
131
+ });
132
+ (_d = this.socket) === null || _d === void 0 ? void 0 : _d.addEventListener("error", () => {
133
+ streamCompleteController.abort();
134
+ });
135
+ streamCompleteController.signal.addEventListener("abort", () => {
136
+ source.close();
137
+ if (timeoutId) {
138
+ clearTimeout(timeoutId);
139
+ }
140
+ emitter.clearListeners();
141
+ });
142
+ return Object.assign(Object.assign({ source }, (0, utils_1.getEmitteryCallbacks)(emitter)), { stop: streamCompleteController.abort.bind(streamCompleteController) });
113
143
  });
114
- return Object.assign(Object.assign({ source }, getEmitteryCallbacks(emitter)), { stop: streamCompleteController.abort.bind(streamCompleteController) });
115
144
  }
116
145
  continue(inputs) {
117
146
  var _a;
@@ -122,7 +151,7 @@ export default class Websocket {
122
151
  throw new Error("context_id is required to continue a context.");
123
152
  }
124
153
  if (!inputs.outputFormat) {
125
- inputs.outputFormat = resolveOutputFormat(__classPrivateFieldGet(this, _Websocket_container, "f"), __classPrivateFieldGet(this, _Websocket_encoding, "f"), __classPrivateFieldGet(this, _Websocket_sampleRate, "f"));
154
+ inputs.outputFormat = (0, utils_1.resolveOutputFormat)(__classPrivateFieldGet(this, _Websocket_container, "f"), __classPrivateFieldGet(this, _Websocket_encoding, "f"), __classPrivateFieldGet(this, _Websocket_sampleRate, "f"));
126
155
  }
127
156
  (_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(Object.assign({ continue: true }, serializers.WebSocketTtsRequest.jsonOrThrow(inputs, { unrecognizedObjectKeys: "strip" }))));
128
157
  }
@@ -137,15 +166,15 @@ export default class Websocket {
137
166
  if (__classPrivateFieldGet(this, _Websocket_isConnected, "f")) {
138
167
  throw new Error("WebSocket is already connected.");
139
168
  }
140
- const emitter = new Emittery();
141
- this.socket = new ReconnectingWebSocket(() => __awaiter(this, void 0, void 0, function* () {
169
+ const emitter = new emittery_1.default();
170
+ this.socket = new websocket_1.ReconnectingWebSocket(() => __awaiter(this, void 0, void 0, function* () {
142
171
  var _a;
143
172
  const baseUrl = ((_a = (yield core.Supplier.get(this.options.environment))) !== null && _a !== void 0 ? _a : environments.CartesiaEnvironment.Production).replace(/^https?:\/\//, "");
144
173
  const params = {
145
174
  api_key: this.options.apiKey,
146
175
  cartesia_version: this.options.cartesiaVersion,
147
176
  };
148
- return `wss://${baseUrl}/tts/websocket${qs.stringify(params, { addQueryPrefix: true })}`;
177
+ return `wss://${baseUrl}/tts/websocket${qs_1.default.stringify(params, { addQueryPrefix: true })}`;
149
178
  }), undefined, options);
150
179
  this.socket.reconnect();
151
180
  this.socket.onopen = () => {
@@ -159,7 +188,7 @@ export default class Websocket {
159
188
  return new Promise((resolve, reject) => {
160
189
  var _a, _b, _c;
161
190
  (_a = this.socket) === null || _a === void 0 ? void 0 : _a.addEventListener("open", () => {
162
- resolve(getEmitteryCallbacks(emitter));
191
+ resolve((0, utils_1.getEmitteryCallbacks)(emitter));
163
192
  });
164
193
  const aborter = new AbortController();
165
194
  (_b = this.socket) === null || _b === void 0 ? void 0 : _b.addEventListener("error", () => {
@@ -181,8 +210,9 @@ export default class Websocket {
181
210
  (_a = this.socket) === null || _a === void 0 ? void 0 : _a.close();
182
211
  }
183
212
  }
213
+ exports.default = Websocket;
184
214
  _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() {
185
- return humanId({
215
+ return (0, human_id_1.humanId)({
186
216
  separator: "-",
187
217
  capitalize: false,
188
218
  });
@@ -1,11 +1,12 @@
1
+ import Emittery from "emittery";
1
2
  import { RawEncoding } from "../api";
2
3
  import { SourceEventData, TypedArray } from "./utils";
3
4
  export default class Source {
4
5
  #private;
5
- on: <Name extends keyof import("emittery").OmnipresentEventData | keyof SourceEventData>(eventName: Name | readonly Name[], listener: (eventData: (SourceEventData & import("emittery").OmnipresentEventData)[Name]) => void | Promise<void>) => import("emittery").UnsubscribeFunction;
6
- once: <Name extends keyof import("emittery").OmnipresentEventData | keyof SourceEventData>(eventName: Name | readonly Name[]) => import("emittery").EmitteryOncePromise<(SourceEventData & import("emittery").OmnipresentEventData)[Name]>;
7
- events: <Name extends keyof SourceEventData>(eventName: Name | readonly Name[]) => AsyncIterableIterator<SourceEventData[Name]>;
8
- off: <Name extends keyof import("emittery").OmnipresentEventData | keyof SourceEventData>(eventName: Name | readonly Name[], listener: (eventData: (SourceEventData & import("emittery").OmnipresentEventData)[Name]) => void | Promise<void>) => void;
6
+ on: Emittery<SourceEventData>["on"];
7
+ once: Emittery<SourceEventData>["once"];
8
+ events: Emittery<SourceEventData>["events"];
9
+ off: Emittery<SourceEventData>["off"];
9
10
  /**
10
11
  * Create a new Source.
11
12
  *
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -18,10 +19,14 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
18
19
  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");
19
20
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
21
  };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
21
25
  var _Source_instances, _Source_emitter, _Source_buffer, _Source_readIndex, _Source_writeIndex, _Source_closed, _Source_sampleRate, _Source_encoding, _Source_container, _Source_createBuffer;
22
- import Emittery from "emittery";
23
- import { ENCODING_MAP } from "./utils";
24
- export default class Source {
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ const emittery_1 = __importDefault(require("emittery"));
28
+ const utils_1 = require("./utils");
29
+ class Source {
25
30
  /**
26
31
  * Create a new Source.
27
32
  *
@@ -30,7 +35,7 @@ export default class Source {
30
35
  */
31
36
  constructor({ sampleRate, encoding, container }) {
32
37
  _Source_instances.add(this);
33
- _Source_emitter.set(this, new Emittery());
38
+ _Source_emitter.set(this, new emittery_1.default());
34
39
  _Source_buffer.set(this, void 0);
35
40
  _Source_readIndex.set(this, 0);
36
41
  _Source_writeIndex.set(this, 0);
@@ -41,7 +46,7 @@ export default class Source {
41
46
  this.on = __classPrivateFieldGet(this, _Source_emitter, "f").on.bind(__classPrivateFieldGet(this, _Source_emitter, "f"));
42
47
  this.once = __classPrivateFieldGet(this, _Source_emitter, "f").once.bind(__classPrivateFieldGet(this, _Source_emitter, "f"));
43
48
  this.events = __classPrivateFieldGet(this, _Source_emitter, "f").events.bind(__classPrivateFieldGet(this, _Source_emitter, "f"));
44
- this.off = __classPrivateFieldGet(this, _Source_emitter, "f").off.bind(__classPrivateFieldGet(this, _Source_emitter, "f"));
49
+ this.off = __classPrivateFieldGet(this, _Source_emitter, "f").off.bind(__classPrivateFieldGet(this, _Source_emitter, "f").off);
45
50
  __classPrivateFieldSet(this, _Source_sampleRate, sampleRate, "f");
46
51
  __classPrivateFieldSet(this, _Source_encoding, encoding, "f");
47
52
  __classPrivateFieldSet(this, _Source_container, container, "f");
@@ -167,7 +172,8 @@ export default class Source {
167
172
  });
168
173
  }
169
174
  }
175
+ exports.default = Source;
170
176
  _Source_emitter = new WeakMap(), _Source_buffer = new WeakMap(), _Source_readIndex = new WeakMap(), _Source_writeIndex = new WeakMap(), _Source_closed = new WeakMap(), _Source_sampleRate = new WeakMap(), _Source_encoding = new WeakMap(), _Source_container = new WeakMap(), _Source_instances = new WeakSet(), _Source_createBuffer = function _Source_createBuffer(size) {
171
- const { arrayType: ArrayType } = ENCODING_MAP[__classPrivateFieldGet(this, _Source_encoding, "f")];
177
+ const { arrayType: ArrayType } = utils_1.ENCODING_MAP[__classPrivateFieldGet(this, _Source_encoding, "f")];
172
178
  return new ArrayType(size);
173
179
  };
@@ -1,5 +1,11 @@
1
- import base64 from "base64-js";
2
- export const ENCODING_MAP = {
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getEmitteryCallbacks = exports.isComplete = exports.filterSentinel = exports.isSentinel = exports.getSentinel = exports.createMessageHandlerForContextId = exports.playAudioBuffer = exports.base64ToArray = exports.resolveOutputFormat = exports.ENCODING_MAP = void 0;
7
+ const base64_js_1 = __importDefault(require("base64-js"));
8
+ exports.ENCODING_MAP = {
3
9
  pcm_f32le: { arrayType: Float32Array, bytesPerElement: 4 },
4
10
  pcm_s16le: { arrayType: Int16Array, bytesPerElement: 2 },
5
11
  pcm_alaw: { arrayType: Uint8Array, bytesPerElement: 1 },
@@ -13,7 +19,7 @@ export const ENCODING_MAP = {
13
19
  * @param sampleRate - The sample rate of the audio.
14
20
  * @returns The output format for the WebSocket request.
15
21
  */
16
- export function resolveOutputFormat(container, encoding, sampleRate) {
22
+ function resolveOutputFormat(container, encoding, sampleRate) {
17
23
  switch (container) {
18
24
  case "wav":
19
25
  return {
@@ -38,6 +44,7 @@ export function resolveOutputFormat(container, encoding, sampleRate) {
38
44
  throw new Error(`Unsupported container type: ${container}`);
39
45
  }
40
46
  }
47
+ exports.resolveOutputFormat = resolveOutputFormat;
41
48
  /**
42
49
  * Convert base64-encoded audio buffer(s) to a TypedArray.
43
50
  *
@@ -46,9 +53,9 @@ export function resolveOutputFormat(container, encoding, sampleRate) {
46
53
  * @param encoding The encoding of the audio buffer(s).
47
54
  * @returns The audio buffer(s) as a TypedArray.
48
55
  */
49
- export function base64ToArray(b64, encoding) {
50
- const byteArrays = filterSentinel(b64).map((b) => base64.toByteArray(b));
51
- const { arrayType: ArrayType, bytesPerElement } = ENCODING_MAP[encoding];
56
+ function base64ToArray(b64, encoding) {
57
+ const byteArrays = filterSentinel(b64).map((b) => base64_js_1.default.toByteArray(b));
58
+ const { arrayType: ArrayType, bytesPerElement } = exports.ENCODING_MAP[encoding];
52
59
  const totalLength = byteArrays.reduce((acc, arr) => acc + arr.length / bytesPerElement, 0);
53
60
  const result = new ArrayType(totalLength);
54
61
  let offset = 0;
@@ -59,6 +66,7 @@ export function base64ToArray(b64, encoding) {
59
66
  }
60
67
  return result;
61
68
  }
69
+ exports.base64ToArray = base64ToArray;
62
70
  /**
63
71
  * Schedule an audio buffer to play at a given time in the passed context.
64
72
  *
@@ -68,7 +76,7 @@ export function base64ToArray(b64, encoding) {
68
76
  * @param sampleRate The sample rate of the audio.
69
77
  * @returns A promise that resolves when the audio has finished playing.
70
78
  */
71
- export function playAudioBuffer(floats, context, startAt, sampleRate) {
79
+ function playAudioBuffer(floats, context, startAt, sampleRate) {
72
80
  const source = context.createBufferSource();
73
81
  const buffer = context.createBuffer(1, floats.length, sampleRate);
74
82
  buffer.getChannelData(0).set(floats);
@@ -81,6 +89,7 @@ export function playAudioBuffer(floats, context, startAt, sampleRate) {
81
89
  };
82
90
  });
83
91
  }
92
+ exports.playAudioBuffer = playAudioBuffer;
84
93
  /**
85
94
  * Unwraps a chunk of audio data from a message event and calls the
86
95
  * handler with it if the context ID matches.
@@ -89,7 +98,7 @@ export function playAudioBuffer(floats, context, startAt, sampleRate) {
89
98
  * @param handler The handler to call with the chunk of audio data.
90
99
  * @returns A message event handler.
91
100
  */
92
- export function createMessageHandlerForContextId(contextId, handler) {
101
+ function createMessageHandlerForContextId(contextId, handler) {
93
102
  return (event) => {
94
103
  if (typeof event.data !== "string") {
95
104
  return; // Ignore non-string messages.
@@ -109,46 +118,51 @@ export function createMessageHandlerForContextId(contextId, handler) {
109
118
  handler({ chunk, message: event.data, data: message });
110
119
  };
111
120
  }
121
+ exports.createMessageHandlerForContextId = createMessageHandlerForContextId;
112
122
  /**
113
123
  * Get a sentinel value that indicates the end of a stream.
114
124
  * @returns A sentinel value to indicate the end of a stream.
115
125
  */
116
- export function getSentinel() {
126
+ function getSentinel() {
117
127
  return null;
118
128
  }
129
+ exports.getSentinel = getSentinel;
119
130
  /**
120
131
  * Check if a chunk is a sentinel value (i.e. null).
121
132
  *
122
133
  * @param chunk
123
134
  * @returns Whether the chunk is a sentinel value.
124
135
  */
125
- export function isSentinel(x) {
136
+ function isSentinel(x) {
126
137
  return x === getSentinel();
127
138
  }
139
+ exports.isSentinel = isSentinel;
128
140
  /**
129
141
  * Filter out null values from a collection.
130
142
  *
131
143
  * @param collection The collection to filter.
132
144
  * @returns The collection with null values removed.
133
145
  */
134
- export function filterSentinel(collection) {
146
+ function filterSentinel(collection) {
135
147
  return collection.filter((x) => !isSentinel(x));
136
148
  }
149
+ exports.filterSentinel = filterSentinel;
137
150
  /**
138
151
  * Check if an array of chunks is complete by testing if the last chunk is a sentinel
139
152
  * value (i.e. null).
140
153
  * @param chunk
141
154
  * @returns Whether the array of chunks is complete.
142
155
  */
143
- export function isComplete(chunks) {
156
+ function isComplete(chunks) {
144
157
  return isSentinel(chunks[chunks.length - 1]);
145
158
  }
159
+ exports.isComplete = isComplete;
146
160
  /**
147
161
  * Get user-facing emitter callbacks for an Emittery instance.
148
162
  * @param emitter The Emittery instance to get callbacks for.
149
163
  * @returns User-facing emitter callbacks.
150
164
  */
151
- export function getEmitteryCallbacks(emitter) {
165
+ function getEmitteryCallbacks(emitter) {
152
166
  return {
153
167
  on: emitter.on.bind(emitter),
154
168
  off: emitter.off.bind(emitter),
@@ -156,3 +170,4 @@ export function getEmitteryCallbacks(emitter) {
156
170
  events: emitter.events.bind(emitter),
157
171
  };
158
172
  }
173
+ exports.getEmitteryCallbacks = getEmitteryCallbacks;
package/environments.js CHANGED
@@ -1,6 +1,9 @@
1
+ "use strict";
1
2
  /**
2
3
  * This file was auto-generated by Fern from our API Definition.
3
4
  */
4
- export const CartesiaEnvironment = {
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CartesiaEnvironment = void 0;
7
+ exports.CartesiaEnvironment = {
5
8
  Production: "https://api.cartesia.ai",
6
9
  };
@@ -1,7 +1,10 @@
1
+ "use strict";
1
2
  /**
2
3
  * This file was auto-generated by Fern from our API Definition.
3
4
  */
4
- export class CartesiaError extends Error {
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CartesiaError = void 0;
7
+ class CartesiaError extends Error {
5
8
  constructor({ message, statusCode, body }) {
6
9
  super(buildMessage({ message, statusCode, body }));
7
10
  Object.setPrototypeOf(this, CartesiaError.prototype);
@@ -13,6 +16,7 @@ export class CartesiaError extends Error {
13
16
  }
14
17
  }
15
18
  }
19
+ exports.CartesiaError = CartesiaError;
16
20
  function buildMessage({ message, statusCode, body, }) {
17
21
  let lines = [];
18
22
  if (message != null) {
@@ -1,9 +1,13 @@
1
+ "use strict";
1
2
  /**
2
3
  * This file was auto-generated by Fern from our API Definition.
3
4
  */
4
- export class CartesiaTimeoutError extends Error {
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CartesiaTimeoutError = void 0;
7
+ class CartesiaTimeoutError extends Error {
5
8
  constructor() {
6
9
  super("Timeout");
7
10
  Object.setPrototypeOf(this, CartesiaTimeoutError.prototype);
8
11
  }
9
12
  }
13
+ exports.CartesiaTimeoutError = CartesiaTimeoutError;
package/errors/index.js CHANGED
@@ -1,2 +1,7 @@
1
- export { CartesiaError } from "./CartesiaError";
2
- export { CartesiaTimeoutError } from "./CartesiaTimeoutError";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CartesiaTimeoutError = exports.CartesiaError = void 0;
4
+ var CartesiaError_1 = require("./CartesiaError");
5
+ Object.defineProperty(exports, "CartesiaError", { enumerable: true, get: function () { return CartesiaError_1.CartesiaError; } });
6
+ var CartesiaTimeoutError_1 = require("./CartesiaTimeoutError");
7
+ Object.defineProperty(exports, "CartesiaTimeoutError", { enumerable: true, get: function () { return CartesiaTimeoutError_1.CartesiaTimeoutError; } });
package/index.js CHANGED
@@ -1,4 +1,34 @@
1
- export * as Cartesia from "./api";
2
- export { CartesiaClient } from "./wrapper/Client";
3
- export { CartesiaEnvironment } from "./environments";
4
- export { CartesiaError, CartesiaTimeoutError } from "./errors";
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.CartesiaTimeoutError = exports.CartesiaError = exports.CartesiaEnvironment = exports.CartesiaClient = exports.Cartesia = void 0;
27
+ exports.Cartesia = __importStar(require("./api"));
28
+ var Client_1 = require("./wrapper/Client");
29
+ Object.defineProperty(exports, "CartesiaClient", { enumerable: true, get: function () { return Client_1.CartesiaClient; } });
30
+ var environments_1 = require("./environments");
31
+ Object.defineProperty(exports, "CartesiaEnvironment", { enumerable: true, get: function () { return environments_1.CartesiaEnvironment; } });
32
+ var errors_1 = require("./errors");
33
+ Object.defineProperty(exports, "CartesiaError", { enumerable: true, get: function () { return errors_1.CartesiaError; } });
34
+ Object.defineProperty(exports, "CartesiaTimeoutError", { enumerable: true, get: function () { return errors_1.CartesiaTimeoutError; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cartesia/cartesia-js",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "private": false,
5
5
  "repository": "https://github.com/cartesia-ai/cartesia-js",
6
6
  "main": "./index.js",
@@ -19,7 +19,7 @@
19
19
  "qs": "6.11.2",
20
20
  "readable-stream": "^4.5.2",
21
21
  "form-data-encoder": "^4.0.2",
22
- "emittery": "^1.0.3",
22
+ "emittery": "^0.13.1",
23
23
  "human-id": "^4.1.1",
24
24
  "ws": "^8.15.13"
25
25
  },
@@ -1 +1,17 @@
1
- export * from "./resources";
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("./resources"), exports);
@@ -1 +1,17 @@
1
- export * from "./types";
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);
@@ -1,8 +1,34 @@
1
+ "use strict";
1
2
  /**
2
3
  * This file was auto-generated by Fern from our API Definition.
3
4
  */
4
- import * as core from "../../../../core";
5
- export const ApiInfo = core.serialization.object({
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 (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.ApiInfo = void 0;
30
+ const core = __importStar(require("../../../../core"));
31
+ exports.ApiInfo = core.serialization.object({
6
32
  ok: core.serialization.boolean(),
7
33
  version: core.serialization.string(),
8
34
  });