@deepgram/sdk 3.3.5 → 3.4.1

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 (295) hide show
  1. package/README.md +129 -9
  2. package/dist/main/DeepgramClient.d.ts +65 -12
  3. package/dist/main/DeepgramClient.d.ts.map +1 -1
  4. package/dist/main/DeepgramClient.js +73 -18
  5. package/dist/main/DeepgramClient.js.map +1 -1
  6. package/dist/main/index.d.ts +13 -4
  7. package/dist/main/index.d.ts.map +1 -1
  8. package/dist/main/index.js +18 -8
  9. package/dist/main/index.js.map +1 -1
  10. package/dist/main/lib/constants.d.ts +16 -7
  11. package/dist/main/lib/constants.d.ts.map +1 -1
  12. package/dist/main/lib/constants.js +26 -9
  13. package/dist/main/lib/constants.js.map +1 -1
  14. package/dist/main/lib/enums/LiveConnectionState.d.ts +5 -0
  15. package/dist/main/lib/enums/LiveConnectionState.d.ts.map +1 -1
  16. package/dist/main/lib/enums/LiveConnectionState.js +5 -0
  17. package/dist/main/lib/enums/LiveConnectionState.js.map +1 -1
  18. package/dist/main/lib/enums/LiveTranscriptionEvents.d.ts +24 -3
  19. package/dist/main/lib/enums/LiveTranscriptionEvents.d.ts.map +1 -1
  20. package/dist/main/lib/enums/LiveTranscriptionEvents.js +23 -2
  21. package/dist/main/lib/enums/LiveTranscriptionEvents.js.map +1 -1
  22. package/dist/main/lib/enums/index.d.ts +2 -2
  23. package/dist/main/lib/enums/index.d.ts.map +1 -1
  24. package/dist/main/lib/enums/index.js +16 -5
  25. package/dist/main/lib/enums/index.js.map +1 -1
  26. package/dist/main/lib/fetch.d.ts +19 -1
  27. package/dist/main/lib/fetch.d.ts.map +1 -1
  28. package/dist/main/lib/fetch.js +19 -1
  29. package/dist/main/lib/fetch.js.map +1 -1
  30. package/dist/main/lib/helpers.d.ts +9 -5
  31. package/dist/main/lib/helpers.d.ts.map +1 -1
  32. package/dist/main/lib/helpers.js +82 -7
  33. package/dist/main/lib/helpers.js.map +1 -1
  34. package/dist/main/lib/types/CreateProjectKeySchema.d.ts +0 -1
  35. package/dist/main/lib/types/CreateProjectKeySchema.d.ts.map +1 -1
  36. package/dist/main/lib/types/DeepgramClientOptions.d.ts +75 -8
  37. package/dist/main/lib/types/DeepgramClientOptions.d.ts.map +1 -1
  38. package/dist/main/lib/types/Fetch.d.ts +3 -13
  39. package/dist/main/lib/types/Fetch.d.ts.map +1 -1
  40. package/dist/main/lib/types/LiveConfigOptions.d.ts +6 -3
  41. package/dist/main/lib/types/LiveConfigOptions.d.ts.map +1 -1
  42. package/dist/main/lib/types/TranscriptionSchema.d.ts +0 -1
  43. package/dist/main/lib/types/TranscriptionSchema.d.ts.map +1 -1
  44. package/dist/main/lib/types/UpdateProjectMemberScopeSchema.d.ts +1 -1
  45. package/dist/main/lib/types/UpdateProjectMemberScopeSchema.d.ts.map +1 -1
  46. package/dist/main/lib/types/UpdateProjectSchema.d.ts +0 -1
  47. package/dist/main/lib/types/UpdateProjectSchema.d.ts.map +1 -1
  48. package/dist/main/lib/types/index.d.ts +39 -39
  49. package/dist/main/lib/types/index.d.ts.map +1 -1
  50. package/dist/main/lib/types/index.js +53 -0
  51. package/dist/main/lib/types/index.js.map +1 -1
  52. package/dist/main/lib/version.d.ts +1 -1
  53. package/dist/main/lib/version.js +1 -1
  54. package/dist/main/packages/AbstractClient.d.ts +63 -10
  55. package/dist/main/packages/AbstractClient.d.ts.map +1 -1
  56. package/dist/main/packages/AbstractClient.js +103 -50
  57. package/dist/main/packages/AbstractClient.js.map +1 -1
  58. package/dist/main/packages/AbstractLiveClient.d.ts +114 -0
  59. package/dist/main/packages/AbstractLiveClient.d.ts.map +1 -0
  60. package/dist/main/packages/AbstractLiveClient.js +238 -0
  61. package/dist/main/packages/AbstractLiveClient.js.map +1 -0
  62. package/dist/main/packages/AbstractRestClient.d.ts +105 -0
  63. package/dist/main/packages/AbstractRestClient.d.ts.map +1 -0
  64. package/dist/main/packages/AbstractRestClient.js +185 -0
  65. package/dist/main/packages/AbstractRestClient.js.map +1 -0
  66. package/dist/main/packages/ListenClient.d.ts +21 -4
  67. package/dist/main/packages/ListenClient.d.ts.map +1 -1
  68. package/dist/main/packages/ListenClient.js +25 -5
  69. package/dist/main/packages/ListenClient.js.map +1 -1
  70. package/dist/main/packages/ListenLiveClient.d.ts +58 -0
  71. package/dist/main/packages/ListenLiveClient.d.ts.map +1 -0
  72. package/dist/main/packages/ListenLiveClient.js +119 -0
  73. package/dist/main/packages/ListenLiveClient.js.map +1 -0
  74. package/dist/main/packages/ListenRestClient.d.ts +57 -0
  75. package/dist/main/packages/ListenRestClient.d.ts.map +1 -0
  76. package/dist/main/packages/ListenRestClient.js +167 -0
  77. package/dist/main/packages/ListenRestClient.js.map +1 -0
  78. package/dist/main/packages/ManageRestClient.d.ts +286 -0
  79. package/dist/main/packages/ManageRestClient.d.ts.map +1 -0
  80. package/dist/main/packages/ManageRestClient.js +628 -0
  81. package/dist/main/packages/ManageRestClient.js.map +1 -0
  82. package/dist/main/packages/ReadRestClient.d.ts +57 -0
  83. package/dist/main/packages/ReadRestClient.d.ts.map +1 -0
  84. package/dist/main/packages/ReadRestClient.js +165 -0
  85. package/dist/main/packages/ReadRestClient.js.map +1 -0
  86. package/dist/main/packages/SelfHostedRestClient.d.ts +47 -0
  87. package/dist/main/packages/SelfHostedRestClient.d.ts.map +1 -0
  88. package/dist/main/packages/SelfHostedRestClient.js +120 -0
  89. package/dist/main/packages/SelfHostedRestClient.js.map +1 -0
  90. package/dist/main/packages/SpeakRestClient.d.ts +36 -0
  91. package/dist/main/packages/SpeakRestClient.d.ts.map +1 -0
  92. package/dist/main/packages/SpeakRestClient.js +84 -0
  93. package/dist/main/packages/SpeakRestClient.js.map +1 -0
  94. package/dist/main/packages/index.d.ts +10 -8
  95. package/dist/main/packages/index.d.ts.map +1 -1
  96. package/dist/main/packages/index.js +24 -17
  97. package/dist/main/packages/index.js.map +1 -1
  98. package/dist/module/DeepgramClient.d.ts +65 -12
  99. package/dist/module/DeepgramClient.d.ts.map +1 -1
  100. package/dist/module/DeepgramClient.js +72 -17
  101. package/dist/module/DeepgramClient.js.map +1 -1
  102. package/dist/module/index.d.ts +13 -4
  103. package/dist/module/index.d.ts.map +1 -1
  104. package/dist/module/index.js +18 -8
  105. package/dist/module/index.js.map +1 -1
  106. package/dist/module/lib/constants.d.ts +16 -7
  107. package/dist/module/lib/constants.d.ts.map +1 -1
  108. package/dist/module/lib/constants.js +26 -9
  109. package/dist/module/lib/constants.js.map +1 -1
  110. package/dist/module/lib/enums/LiveConnectionState.d.ts +5 -0
  111. package/dist/module/lib/enums/LiveConnectionState.d.ts.map +1 -1
  112. package/dist/module/lib/enums/LiveConnectionState.js +5 -0
  113. package/dist/module/lib/enums/LiveConnectionState.js.map +1 -1
  114. package/dist/module/lib/enums/LiveTranscriptionEvents.d.ts +24 -3
  115. package/dist/module/lib/enums/LiveTranscriptionEvents.d.ts.map +1 -1
  116. package/dist/module/lib/enums/LiveTranscriptionEvents.js +23 -2
  117. package/dist/module/lib/enums/LiveTranscriptionEvents.js.map +1 -1
  118. package/dist/module/lib/enums/index.d.ts +2 -2
  119. package/dist/module/lib/enums/index.d.ts.map +1 -1
  120. package/dist/module/lib/enums/index.js +2 -2
  121. package/dist/module/lib/enums/index.js.map +1 -1
  122. package/dist/module/lib/fetch.d.ts +19 -1
  123. package/dist/module/lib/fetch.d.ts.map +1 -1
  124. package/dist/module/lib/fetch.js +19 -1
  125. package/dist/module/lib/fetch.js.map +1 -1
  126. package/dist/module/lib/helpers.d.ts +9 -5
  127. package/dist/module/lib/helpers.d.ts.map +1 -1
  128. package/dist/module/lib/helpers.js +75 -4
  129. package/dist/module/lib/helpers.js.map +1 -1
  130. package/dist/module/lib/types/CreateProjectKeySchema.d.ts +0 -1
  131. package/dist/module/lib/types/CreateProjectKeySchema.d.ts.map +1 -1
  132. package/dist/module/lib/types/DeepgramClientOptions.d.ts +75 -8
  133. package/dist/module/lib/types/DeepgramClientOptions.d.ts.map +1 -1
  134. package/dist/module/lib/types/Fetch.d.ts +3 -13
  135. package/dist/module/lib/types/Fetch.d.ts.map +1 -1
  136. package/dist/module/lib/types/LiveConfigOptions.d.ts +6 -3
  137. package/dist/module/lib/types/LiveConfigOptions.d.ts.map +1 -1
  138. package/dist/module/lib/types/TranscriptionSchema.d.ts +0 -1
  139. package/dist/module/lib/types/TranscriptionSchema.d.ts.map +1 -1
  140. package/dist/module/lib/types/UpdateProjectMemberScopeSchema.d.ts +1 -1
  141. package/dist/module/lib/types/UpdateProjectMemberScopeSchema.d.ts.map +1 -1
  142. package/dist/module/lib/types/UpdateProjectSchema.d.ts +0 -1
  143. package/dist/module/lib/types/UpdateProjectSchema.d.ts.map +1 -1
  144. package/dist/module/lib/types/index.d.ts +39 -39
  145. package/dist/module/lib/types/index.d.ts.map +1 -1
  146. package/dist/module/lib/types/index.js +39 -1
  147. package/dist/module/lib/types/index.js.map +1 -1
  148. package/dist/module/lib/version.d.ts +1 -1
  149. package/dist/module/lib/version.js +1 -1
  150. package/dist/module/packages/AbstractClient.d.ts +63 -10
  151. package/dist/module/packages/AbstractClient.d.ts.map +1 -1
  152. package/dist/module/packages/AbstractClient.js +99 -50
  153. package/dist/module/packages/AbstractClient.js.map +1 -1
  154. package/dist/module/packages/AbstractLiveClient.d.ts +114 -0
  155. package/dist/module/packages/AbstractLiveClient.d.ts.map +1 -0
  156. package/dist/module/packages/AbstractLiveClient.js +211 -0
  157. package/dist/module/packages/AbstractLiveClient.js.map +1 -0
  158. package/dist/module/packages/AbstractRestClient.d.ts +105 -0
  159. package/dist/module/packages/AbstractRestClient.d.ts.map +1 -0
  160. package/dist/module/packages/AbstractRestClient.js +178 -0
  161. package/dist/module/packages/AbstractRestClient.js.map +1 -0
  162. package/dist/module/packages/ListenClient.d.ts +21 -4
  163. package/dist/module/packages/ListenClient.d.ts.map +1 -1
  164. package/dist/module/packages/ListenClient.js +25 -5
  165. package/dist/module/packages/ListenClient.js.map +1 -1
  166. package/dist/module/packages/ListenLiveClient.d.ts +58 -0
  167. package/dist/module/packages/ListenLiveClient.d.ts.map +1 -0
  168. package/dist/module/packages/ListenLiveClient.js +115 -0
  169. package/dist/module/packages/ListenLiveClient.js.map +1 -0
  170. package/dist/module/packages/ListenRestClient.d.ts +57 -0
  171. package/dist/module/packages/ListenRestClient.d.ts.map +1 -0
  172. package/dist/module/packages/ListenRestClient.js +163 -0
  173. package/dist/module/packages/ListenRestClient.js.map +1 -0
  174. package/dist/module/packages/ManageRestClient.d.ts +286 -0
  175. package/dist/module/packages/ManageRestClient.d.ts.map +1 -0
  176. package/dist/module/packages/ManageRestClient.js +624 -0
  177. package/dist/module/packages/ManageRestClient.js.map +1 -0
  178. package/dist/module/packages/ReadRestClient.d.ts +57 -0
  179. package/dist/module/packages/ReadRestClient.d.ts.map +1 -0
  180. package/dist/module/packages/ReadRestClient.js +161 -0
  181. package/dist/module/packages/ReadRestClient.js.map +1 -0
  182. package/dist/module/packages/SelfHostedRestClient.d.ts +47 -0
  183. package/dist/module/packages/SelfHostedRestClient.d.ts.map +1 -0
  184. package/dist/module/packages/SelfHostedRestClient.js +116 -0
  185. package/dist/module/packages/SelfHostedRestClient.js.map +1 -0
  186. package/dist/module/packages/SpeakRestClient.d.ts +36 -0
  187. package/dist/module/packages/SpeakRestClient.d.ts.map +1 -0
  188. package/dist/module/packages/SpeakRestClient.js +80 -0
  189. package/dist/module/packages/SpeakRestClient.js.map +1 -0
  190. package/dist/module/packages/index.d.ts +10 -8
  191. package/dist/module/packages/index.d.ts.map +1 -1
  192. package/dist/module/packages/index.js +10 -8
  193. package/dist/module/packages/index.js.map +1 -1
  194. package/dist/umd/deepgram.js +1 -1
  195. package/package.json +8 -6
  196. package/src/DeepgramClient.ts +81 -17
  197. package/src/index.ts +32 -7
  198. package/src/lib/constants.ts +33 -13
  199. package/src/lib/enums/LiveConnectionState.ts +11 -4
  200. package/src/lib/enums/LiveTranscriptionEvents.ts +27 -4
  201. package/src/lib/enums/index.ts +2 -2
  202. package/src/lib/fetch.ts +22 -2
  203. package/src/lib/helpers.ts +98 -9
  204. package/src/lib/types/CreateProjectKeySchema.ts +0 -1
  205. package/src/lib/types/DeepgramClientOptions.ts +75 -11
  206. package/src/lib/types/Fetch.ts +2 -24
  207. package/src/lib/types/LiveConfigOptions.ts +7 -3
  208. package/src/lib/types/TranscriptionSchema.ts +0 -2
  209. package/src/lib/types/UpdateProjectMemberScopeSchema.ts +1 -1
  210. package/src/lib/types/UpdateProjectSchema.ts +0 -1
  211. package/src/lib/types/index.ts +39 -54
  212. package/src/lib/version.ts +1 -1
  213. package/src/packages/AbstractClient.ts +129 -61
  214. package/src/packages/AbstractLiveClient.ts +280 -0
  215. package/src/packages/AbstractRestClient.ts +221 -0
  216. package/src/packages/ListenClient.ts +26 -5
  217. package/src/packages/ListenLiveClient.ts +133 -0
  218. package/src/packages/ListenRestClient.ts +201 -0
  219. package/src/packages/ManageRestClient.ts +760 -0
  220. package/src/packages/ReadRestClient.ts +200 -0
  221. package/src/packages/SelfHostedRestClient.ts +134 -0
  222. package/src/packages/SpeakRestClient.ts +79 -0
  223. package/src/packages/index.ts +10 -8
  224. package/dist/main/packages/AbstractRestfulClient.d.ts +0 -26
  225. package/dist/main/packages/AbstractRestfulClient.d.ts.map +0 -1
  226. package/dist/main/packages/AbstractRestfulClient.js +0 -118
  227. package/dist/main/packages/AbstractRestfulClient.js.map +0 -1
  228. package/dist/main/packages/AbstractWsClient.d.ts +0 -10
  229. package/dist/main/packages/AbstractWsClient.d.ts.map +0 -1
  230. package/dist/main/packages/AbstractWsClient.js +0 -33
  231. package/dist/main/packages/AbstractWsClient.js.map +0 -1
  232. package/dist/main/packages/LiveClient.d.ts +0 -28
  233. package/dist/main/packages/LiveClient.d.ts.map +0 -1
  234. package/dist/main/packages/LiveClient.js +0 -110
  235. package/dist/main/packages/LiveClient.js.map +0 -1
  236. package/dist/main/packages/ManageClient.d.ts +0 -97
  237. package/dist/main/packages/ManageClient.d.ts.map +0 -1
  238. package/dist/main/packages/ManageClient.js +0 -463
  239. package/dist/main/packages/ManageClient.js.map +0 -1
  240. package/dist/main/packages/OnPremClient.d.ts +0 -21
  241. package/dist/main/packages/OnPremClient.d.ts.map +0 -1
  242. package/dist/main/packages/OnPremClient.js +0 -99
  243. package/dist/main/packages/OnPremClient.js.map +0 -1
  244. package/dist/main/packages/PrerecordedClient.d.ts +0 -10
  245. package/dist/main/packages/PrerecordedClient.d.ts.map +0 -1
  246. package/dist/main/packages/PrerecordedClient.js +0 -125
  247. package/dist/main/packages/PrerecordedClient.js.map +0 -1
  248. package/dist/main/packages/ReadClient.d.ts +0 -10
  249. package/dist/main/packages/ReadClient.d.ts.map +0 -1
  250. package/dist/main/packages/ReadClient.js +0 -123
  251. package/dist/main/packages/ReadClient.js.map +0 -1
  252. package/dist/main/packages/SpeakClient.d.ts +0 -12
  253. package/dist/main/packages/SpeakClient.d.ts.map +0 -1
  254. package/dist/main/packages/SpeakClient.js +0 -57
  255. package/dist/main/packages/SpeakClient.js.map +0 -1
  256. package/dist/module/packages/AbstractRestfulClient.d.ts +0 -26
  257. package/dist/module/packages/AbstractRestfulClient.d.ts.map +0 -1
  258. package/dist/module/packages/AbstractRestfulClient.js +0 -114
  259. package/dist/module/packages/AbstractRestfulClient.js.map +0 -1
  260. package/dist/module/packages/AbstractWsClient.d.ts +0 -10
  261. package/dist/module/packages/AbstractWsClient.d.ts.map +0 -1
  262. package/dist/module/packages/AbstractWsClient.js +0 -29
  263. package/dist/module/packages/AbstractWsClient.js.map +0 -1
  264. package/dist/module/packages/LiveClient.d.ts +0 -28
  265. package/dist/module/packages/LiveClient.d.ts.map +0 -1
  266. package/dist/module/packages/LiveClient.js +0 -106
  267. package/dist/module/packages/LiveClient.js.map +0 -1
  268. package/dist/module/packages/ManageClient.d.ts +0 -97
  269. package/dist/module/packages/ManageClient.d.ts.map +0 -1
  270. package/dist/module/packages/ManageClient.js +0 -459
  271. package/dist/module/packages/ManageClient.js.map +0 -1
  272. package/dist/module/packages/OnPremClient.d.ts +0 -21
  273. package/dist/module/packages/OnPremClient.d.ts.map +0 -1
  274. package/dist/module/packages/OnPremClient.js +0 -95
  275. package/dist/module/packages/OnPremClient.js.map +0 -1
  276. package/dist/module/packages/PrerecordedClient.d.ts +0 -10
  277. package/dist/module/packages/PrerecordedClient.d.ts.map +0 -1
  278. package/dist/module/packages/PrerecordedClient.js +0 -121
  279. package/dist/module/packages/PrerecordedClient.js.map +0 -1
  280. package/dist/module/packages/ReadClient.d.ts +0 -10
  281. package/dist/module/packages/ReadClient.d.ts.map +0 -1
  282. package/dist/module/packages/ReadClient.js +0 -119
  283. package/dist/module/packages/ReadClient.js.map +0 -1
  284. package/dist/module/packages/SpeakClient.d.ts +0 -12
  285. package/dist/module/packages/SpeakClient.d.ts.map +0 -1
  286. package/dist/module/packages/SpeakClient.js +0 -53
  287. package/dist/module/packages/SpeakClient.js.map +0 -1
  288. package/src/packages/AbstractRestfulClient.ts +0 -160
  289. package/src/packages/AbstractWsClient.ts +0 -42
  290. package/src/packages/LiveClient.ts +0 -140
  291. package/src/packages/ManageClient.ts +0 -584
  292. package/src/packages/OnPremClient.ts +0 -113
  293. package/src/packages/PrerecordedClient.ts +0 -162
  294. package/src/packages/ReadClient.ts +0 -161
  295. package/src/packages/SpeakClient.ts +0 -50
@@ -0,0 +1,58 @@
1
+ import { AbstractLiveClient } from "./AbstractLiveClient";
2
+ import type { LiveSchema, LiveConfigOptions, DeepgramClientOptions } from "../lib/types";
3
+ /**
4
+ * The `ListenLiveClient` class extends the `AbstractLiveClient` class and provides functionality for setting up and managing a WebSocket connection for live transcription.
5
+ *
6
+ * The constructor takes in `DeepgramClientOptions` and an optional `LiveSchema` object, as well as an optional `endpoint` string. It then calls the `connect` method of the parent `AbstractLiveClient` class to establish the WebSocket connection.
7
+ *
8
+ * The `setupConnection` method is responsible for handling the various events that can occur on the WebSocket connection, such as opening, closing, and receiving messages. It sets up event handlers for these events and emits the appropriate events based on the message type.
9
+ *
10
+ * The `configure` method allows you to send additional configuration options to the connected session, such as enabling numerals.
11
+ *
12
+ * The `keepAlive` method sends a "KeepAlive" message to the server to maintain the connection.
13
+ *
14
+ * The `requestClose` method requests the server to close the connection.
15
+ *
16
+ * The `finish` method is deprecated as of version 3.4 and will be removed in version 4.0. Use `requestClose` instead.
17
+ */
18
+ export declare class ListenLiveClient extends AbstractLiveClient {
19
+ namespace: string;
20
+ /**
21
+ * Constructs a new `ListenLiveClient` instance with the provided options.
22
+ *
23
+ * @param options - The `DeepgramClientOptions` to use for the client connection.
24
+ * @param transcriptionOptions - An optional `LiveSchema` object containing additional configuration options for the live transcription.
25
+ * @param endpoint - An optional string representing the WebSocket endpoint to connect to. Defaults to `:version/listen`.
26
+ */
27
+ constructor(options: DeepgramClientOptions, transcriptionOptions?: LiveSchema, endpoint?: string);
28
+ /**
29
+ * Sets up the connection event handlers.
30
+ * This method is responsible for handling the various events that can occur on the WebSocket connection, such as opening, closing, and receiving messages.
31
+ * - When the connection is opened, it emits the `LiveTranscriptionEvents.Open` event.
32
+ * - When the connection is closed, it emits the `LiveTranscriptionEvents.Close` event.
33
+ * - When an error occurs on the connection, it emits the `LiveTranscriptionEvents.Error` event.
34
+ * - When a message is received, it parses the message and emits the appropriate event based on the message type, such as `LiveTranscriptionEvents.Metadata`, `LiveTranscriptionEvents.Transcript`, `LiveTranscriptionEvents.UtteranceEnd`, and `LiveTranscriptionEvents.SpeechStarted`.
35
+ */
36
+ setupConnection(): void;
37
+ /**
38
+ * Sends additional config to the connected session.
39
+ *
40
+ * @param config - The configuration options to apply to the LiveClient.
41
+ * @param config.numerals - We currently only support numerals.
42
+ */
43
+ configure(config: LiveConfigOptions): void;
44
+ /**
45
+ * Sends a "KeepAlive" message to the server to maintain the connection.
46
+ */
47
+ keepAlive(): void;
48
+ /**
49
+ * @deprecated Since version 3.4. Will be removed in version 4.0. Use `close` instead.
50
+ */
51
+ finish(): void;
52
+ /**
53
+ * Requests the server close the connection.
54
+ */
55
+ requestClose(): void;
56
+ }
57
+ export { ListenLiveClient as LiveClient };
58
+ //# sourceMappingURL=ListenLiveClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ListenLiveClient.d.ts","sourceRoot":"","sources":["../../../src/packages/ListenLiveClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAEzF;;;;;;;;;;;;;;GAcG;AACH,qBAAa,gBAAiB,SAAQ,kBAAkB;IAC/C,SAAS,EAAE,MAAM,CAAY;IAEpC;;;;;;OAMG;gBAED,OAAO,EAAE,qBAAqB,EAC9B,oBAAoB,GAAE,UAAe,EACrC,QAAQ,GAAE,MAA0B;IAOtC;;;;;;;OAOG;IACI,eAAe,IAAI,IAAI;IAwC9B;;;;;OAKG;IACI,SAAS,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI;IASjD;;OAEG;IACI,SAAS,IAAI,IAAI;IAQxB;;OAEG;IACI,MAAM,IAAI,IAAI;IAIrB;;OAEG;IACI,YAAY,IAAI,IAAI;CAO5B;AAED,OAAO,EAAE,gBAAgB,IAAI,UAAU,EAAE,CAAC"}
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LiveClient = exports.ListenLiveClient = void 0;
4
+ const AbstractLiveClient_1 = require("./AbstractLiveClient");
5
+ const enums_1 = require("../lib/enums");
6
+ /**
7
+ * The `ListenLiveClient` class extends the `AbstractLiveClient` class and provides functionality for setting up and managing a WebSocket connection for live transcription.
8
+ *
9
+ * The constructor takes in `DeepgramClientOptions` and an optional `LiveSchema` object, as well as an optional `endpoint` string. It then calls the `connect` method of the parent `AbstractLiveClient` class to establish the WebSocket connection.
10
+ *
11
+ * The `setupConnection` method is responsible for handling the various events that can occur on the WebSocket connection, such as opening, closing, and receiving messages. It sets up event handlers for these events and emits the appropriate events based on the message type.
12
+ *
13
+ * The `configure` method allows you to send additional configuration options to the connected session, such as enabling numerals.
14
+ *
15
+ * The `keepAlive` method sends a "KeepAlive" message to the server to maintain the connection.
16
+ *
17
+ * The `requestClose` method requests the server to close the connection.
18
+ *
19
+ * The `finish` method is deprecated as of version 3.4 and will be removed in version 4.0. Use `requestClose` instead.
20
+ */
21
+ class ListenLiveClient extends AbstractLiveClient_1.AbstractLiveClient {
22
+ /**
23
+ * Constructs a new `ListenLiveClient` instance with the provided options.
24
+ *
25
+ * @param options - The `DeepgramClientOptions` to use for the client connection.
26
+ * @param transcriptionOptions - An optional `LiveSchema` object containing additional configuration options for the live transcription.
27
+ * @param endpoint - An optional string representing the WebSocket endpoint to connect to. Defaults to `:version/listen`.
28
+ */
29
+ constructor(options, transcriptionOptions = {}, endpoint = ":version/listen") {
30
+ super(options);
31
+ this.namespace = "listen";
32
+ this.connect(transcriptionOptions, endpoint);
33
+ }
34
+ /**
35
+ * Sets up the connection event handlers.
36
+ * This method is responsible for handling the various events that can occur on the WebSocket connection, such as opening, closing, and receiving messages.
37
+ * - When the connection is opened, it emits the `LiveTranscriptionEvents.Open` event.
38
+ * - When the connection is closed, it emits the `LiveTranscriptionEvents.Close` event.
39
+ * - When an error occurs on the connection, it emits the `LiveTranscriptionEvents.Error` event.
40
+ * - When a message is received, it parses the message and emits the appropriate event based on the message type, such as `LiveTranscriptionEvents.Metadata`, `LiveTranscriptionEvents.Transcript`, `LiveTranscriptionEvents.UtteranceEnd`, and `LiveTranscriptionEvents.SpeechStarted`.
41
+ */
42
+ setupConnection() {
43
+ if (this.conn) {
44
+ this.conn.onopen = () => {
45
+ this.emit(enums_1.LiveTranscriptionEvents.Open, this);
46
+ };
47
+ this.conn.onclose = (event) => {
48
+ this.emit(enums_1.LiveTranscriptionEvents.Close, event);
49
+ };
50
+ this.conn.onerror = (event) => {
51
+ this.emit(enums_1.LiveTranscriptionEvents.Error, event);
52
+ };
53
+ this.conn.onmessage = (event) => {
54
+ try {
55
+ const data = JSON.parse(event.data.toString());
56
+ if (data.type === enums_1.LiveTranscriptionEvents.Metadata) {
57
+ this.emit(enums_1.LiveTranscriptionEvents.Metadata, data);
58
+ }
59
+ else if (data.type === enums_1.LiveTranscriptionEvents.Transcript) {
60
+ this.emit(enums_1.LiveTranscriptionEvents.Transcript, data);
61
+ }
62
+ else if (data.type === enums_1.LiveTranscriptionEvents.UtteranceEnd) {
63
+ this.emit(enums_1.LiveTranscriptionEvents.UtteranceEnd, data);
64
+ }
65
+ else if (data.type === enums_1.LiveTranscriptionEvents.SpeechStarted) {
66
+ this.emit(enums_1.LiveTranscriptionEvents.SpeechStarted, data);
67
+ }
68
+ else {
69
+ this.emit(enums_1.LiveTranscriptionEvents.Unhandled, data);
70
+ }
71
+ }
72
+ catch (error) {
73
+ this.emit(enums_1.LiveTranscriptionEvents.Error, {
74
+ event,
75
+ message: "Unable to parse `data` as JSON.",
76
+ error,
77
+ });
78
+ }
79
+ };
80
+ }
81
+ }
82
+ /**
83
+ * Sends additional config to the connected session.
84
+ *
85
+ * @param config - The configuration options to apply to the LiveClient.
86
+ * @param config.numerals - We currently only support numerals.
87
+ */
88
+ configure(config) {
89
+ this.send(JSON.stringify({
90
+ type: "Configure",
91
+ processors: config,
92
+ }));
93
+ }
94
+ /**
95
+ * Sends a "KeepAlive" message to the server to maintain the connection.
96
+ */
97
+ keepAlive() {
98
+ this.send(JSON.stringify({
99
+ type: "KeepAlive",
100
+ }));
101
+ }
102
+ /**
103
+ * @deprecated Since version 3.4. Will be removed in version 4.0. Use `close` instead.
104
+ */
105
+ finish() {
106
+ this.requestClose();
107
+ }
108
+ /**
109
+ * Requests the server close the connection.
110
+ */
111
+ requestClose() {
112
+ this.send(JSON.stringify({
113
+ type: "CloseStream",
114
+ }));
115
+ }
116
+ }
117
+ exports.ListenLiveClient = ListenLiveClient;
118
+ exports.LiveClient = ListenLiveClient;
119
+ //# sourceMappingURL=ListenLiveClient.js.map
@@ -0,0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;YACb,IAAI,EAAE,aAAa;SACpB,CAAC,CACH,CAAC;IACJ,CAAC;CACF;AA/GD,4CA+GC;AAE4B,sCAAU"}
@@ -0,0 +1,57 @@
1
+ import { CallbackUrl } from "../lib/helpers";
2
+ import type { AsyncPrerecordedResponse, DeepgramResponse, FileSource, PrerecordedSchema, SyncPrerecordedResponse, UrlSource } from "../lib/types";
3
+ import { AbstractRestClient } from "./AbstractRestClient";
4
+ /**
5
+ * The `ListenRestClient` class extends the `AbstractRestClient` class and provides methods for transcribing audio from URLs or files using the Deepgram API.
6
+ *
7
+ * The `transcribeUrl` method is used to transcribe audio from a URL synchronously. It takes a `UrlSource` object as the source, an optional `PrerecordedSchema` object as options, and an optional endpoint string. It returns a `DeepgramResponse` object containing the transcription result or an error.
8
+ *
9
+ * The `transcribeFile` method is used to transcribe audio from a file synchronously. It takes a `FileSource` object as the source, an optional `PrerecordedSchema` object as options, and an optional endpoint string. It returns a `DeepgramResponse` object containing the transcription result or an error.
10
+ *
11
+ * The `transcribeUrlCallback` method is used to transcribe audio from a URL asynchronously. It takes a `UrlSource` object as the source, a `CallbackUrl` object as the callback, an optional `PrerecordedSchema` object as options, and an optional endpoint string. It returns a `DeepgramResponse` object containing the transcription result or an error.
12
+ *
13
+ * The `transcribeFileCallback` method is used to transcribe audio from a file asynchronously. It takes a `FileSource` object as the source, a `CallbackUrl` object as the callback, an optional `PrerecordedSchema` object as options, and an optional endpoint string. It returns a `DeepgramResponse` object containing the transcription result or an error.
14
+ */
15
+ export declare class ListenRestClient extends AbstractRestClient {
16
+ namespace: string;
17
+ /**
18
+ * Transcribes audio from a URL synchronously.
19
+ *
20
+ * @param source - The URL source object containing the audio URL to transcribe.
21
+ * @param options - An optional `PrerecordedSchema` object containing additional options for the transcription.
22
+ * @param endpoint - An optional endpoint string to use for the transcription request.
23
+ * @returns A `DeepgramResponse` object containing the transcription result or an error.
24
+ */
25
+ transcribeUrl(source: UrlSource, options?: PrerecordedSchema, endpoint?: string): Promise<DeepgramResponse<SyncPrerecordedResponse>>;
26
+ /**
27
+ * Transcribes audio from a file asynchronously.
28
+ *
29
+ * @param source - The file source object containing the audio file to transcribe.
30
+ * @param options - An optional `PrerecordedSchema` object containing additional options for the transcription.
31
+ * @param endpoint - An optional endpoint string to use for the transcription request.
32
+ * @returns A `DeepgramResponse` object containing the transcription result or an error.
33
+ */
34
+ transcribeFile(source: FileSource, options?: PrerecordedSchema, endpoint?: string): Promise<DeepgramResponse<SyncPrerecordedResponse>>;
35
+ /**
36
+ * Transcribes audio from a URL asynchronously.
37
+ *
38
+ * @param source - The URL source object containing the audio file to transcribe.
39
+ * @param callback - The callback URL to receive the transcription result.
40
+ * @param options - An optional `PrerecordedSchema` object containing additional options for the transcription.
41
+ * @param endpoint - An optional endpoint string to use for the transcription request.
42
+ * @returns A `DeepgramResponse` object containing the transcription result or an error.
43
+ */
44
+ transcribeUrlCallback(source: UrlSource, callback: CallbackUrl, options?: PrerecordedSchema, endpoint?: string): Promise<DeepgramResponse<AsyncPrerecordedResponse>>;
45
+ /**
46
+ * Transcribes audio from a file asynchronously.
47
+ *
48
+ * @param source - The file source object containing the audio file to transcribe.
49
+ * @param callback - The callback URL to receive the transcription result.
50
+ * @param options - An optional `PrerecordedSchema` object containing additional options for the transcription.
51
+ * @param endpoint - An optional endpoint string to use for the transcription request.
52
+ * @returns A `DeepgramResponse` object containing the transcription result or an error.
53
+ */
54
+ transcribeFileCallback(source: FileSource, callback: CallbackUrl, options?: PrerecordedSchema, endpoint?: string): Promise<DeepgramResponse<AsyncPrerecordedResponse>>;
55
+ }
56
+ export { ListenRestClient as PrerecordedClient };
57
+ //# sourceMappingURL=ListenRestClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ListenRestClient.d.ts","sourceRoot":"","sources":["../../../src/packages/ListenRestClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA6B,MAAM,gBAAgB,CAAC;AAExE,OAAO,KAAK,EACV,wBAAwB,EACxB,gBAAgB,EAEhB,UAAU,EACV,iBAAiB,EACjB,uBAAuB,EACvB,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;;;;;;;GAUG;AACH,qBAAa,gBAAiB,SAAQ,kBAAkB;IAC/C,SAAS,EAAE,MAAM,CAAY;IAEpC;;;;;;;OAOG;IACG,aAAa,CACjB,MAAM,EAAE,SAAS,EACjB,OAAO,CAAC,EAAE,iBAAiB,EAC3B,QAAQ,SAAoB,GAC3B,OAAO,CAAC,gBAAgB,CAAC,uBAAuB,CAAC,CAAC;IA+BrD;;;;;;;OAOG;IACG,cAAc,CAClB,MAAM,EAAE,UAAU,EAClB,OAAO,CAAC,EAAE,iBAAiB,EAC3B,QAAQ,SAAoB,GAC3B,OAAO,CAAC,gBAAgB,CAAC,uBAAuB,CAAC,CAAC;IA+BrD;;;;;;;;OAQG;IACG,qBAAqB,CACzB,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,WAAW,EACrB,OAAO,CAAC,EAAE,iBAAiB,EAC3B,QAAQ,SAAoB,GAC3B,OAAO,CAAC,gBAAgB,CAAC,wBAAwB,CAAC,CAAC;IA6BtD;;;;;;;;OAQG;IACG,sBAAsB,CAC1B,MAAM,EAAE,UAAU,EAClB,QAAQ,EAAE,WAAW,EACrB,OAAO,CAAC,EAAE,iBAAiB,EAC3B,QAAQ,SAAoB,GAC3B,OAAO,CAAC,gBAAgB,CAAC,wBAAwB,CAAC,CAAC;CA4BvD;AAED,OAAO,EAAE,gBAAgB,IAAI,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PrerecordedClient = exports.ListenRestClient = void 0;
13
+ const helpers_1 = require("../lib/helpers");
14
+ const errors_1 = require("../lib/errors");
15
+ const AbstractRestClient_1 = require("./AbstractRestClient");
16
+ /**
17
+ * The `ListenRestClient` class extends the `AbstractRestClient` class and provides methods for transcribing audio from URLs or files using the Deepgram API.
18
+ *
19
+ * The `transcribeUrl` method is used to transcribe audio from a URL synchronously. It takes a `UrlSource` object as the source, an optional `PrerecordedSchema` object as options, and an optional endpoint string. It returns a `DeepgramResponse` object containing the transcription result or an error.
20
+ *
21
+ * The `transcribeFile` method is used to transcribe audio from a file synchronously. It takes a `FileSource` object as the source, an optional `PrerecordedSchema` object as options, and an optional endpoint string. It returns a `DeepgramResponse` object containing the transcription result or an error.
22
+ *
23
+ * The `transcribeUrlCallback` method is used to transcribe audio from a URL asynchronously. It takes a `UrlSource` object as the source, a `CallbackUrl` object as the callback, an optional `PrerecordedSchema` object as options, and an optional endpoint string. It returns a `DeepgramResponse` object containing the transcription result or an error.
24
+ *
25
+ * The `transcribeFileCallback` method is used to transcribe audio from a file asynchronously. It takes a `FileSource` object as the source, a `CallbackUrl` object as the callback, an optional `PrerecordedSchema` object as options, and an optional endpoint string. It returns a `DeepgramResponse` object containing the transcription result or an error.
26
+ */
27
+ class ListenRestClient extends AbstractRestClient_1.AbstractRestClient {
28
+ constructor() {
29
+ super(...arguments);
30
+ this.namespace = "listen";
31
+ }
32
+ /**
33
+ * Transcribes audio from a URL synchronously.
34
+ *
35
+ * @param source - The URL source object containing the audio URL to transcribe.
36
+ * @param options - An optional `PrerecordedSchema` object containing additional options for the transcription.
37
+ * @param endpoint - An optional endpoint string to use for the transcription request.
38
+ * @returns A `DeepgramResponse` object containing the transcription result or an error.
39
+ */
40
+ transcribeUrl(source, options, endpoint = ":version/listen") {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ try {
43
+ let body;
44
+ if ((0, helpers_1.isUrlSource)(source)) {
45
+ body = JSON.stringify(source);
46
+ }
47
+ else {
48
+ throw new errors_1.DeepgramError("Unknown transcription source type");
49
+ }
50
+ if (options !== undefined && "callback" in options) {
51
+ throw new errors_1.DeepgramError("Callback cannot be provided as an option to a synchronous transcription. Use `transcribeUrlCallback` or `transcribeFileCallback` instead.");
52
+ }
53
+ const requestUrl = this.getRequestUrl(endpoint, {}, Object.assign({}, options));
54
+ const result = yield this.post(requestUrl, body).then((result) => result.json());
55
+ return { result, error: null };
56
+ }
57
+ catch (error) {
58
+ if ((0, errors_1.isDeepgramError)(error)) {
59
+ return { result: null, error };
60
+ }
61
+ throw error;
62
+ }
63
+ });
64
+ }
65
+ /**
66
+ * Transcribes audio from a file asynchronously.
67
+ *
68
+ * @param source - The file source object containing the audio file to transcribe.
69
+ * @param options - An optional `PrerecordedSchema` object containing additional options for the transcription.
70
+ * @param endpoint - An optional endpoint string to use for the transcription request.
71
+ * @returns A `DeepgramResponse` object containing the transcription result or an error.
72
+ */
73
+ transcribeFile(source, options, endpoint = ":version/listen") {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ try {
76
+ let body;
77
+ if ((0, helpers_1.isFileSource)(source)) {
78
+ body = source;
79
+ }
80
+ else {
81
+ throw new errors_1.DeepgramError("Unknown transcription source type");
82
+ }
83
+ if (options !== undefined && "callback" in options) {
84
+ throw new errors_1.DeepgramError("Callback cannot be provided as an option to a synchronous transcription. Use `transcribeUrlCallback` or `transcribeFileCallback` instead.");
85
+ }
86
+ const requestUrl = this.getRequestUrl(endpoint, {}, Object.assign({}, options));
87
+ const result = yield this.post(requestUrl, body, {
88
+ headers: { "Content-Type": "deepgram/audio+video" },
89
+ }).then((result) => result.json());
90
+ return { result, error: null };
91
+ }
92
+ catch (error) {
93
+ if ((0, errors_1.isDeepgramError)(error)) {
94
+ return { result: null, error };
95
+ }
96
+ throw error;
97
+ }
98
+ });
99
+ }
100
+ /**
101
+ * Transcribes audio from a URL asynchronously.
102
+ *
103
+ * @param source - The URL source object containing the audio file to transcribe.
104
+ * @param callback - The callback URL to receive the transcription result.
105
+ * @param options - An optional `PrerecordedSchema` object containing additional options for the transcription.
106
+ * @param endpoint - An optional endpoint string to use for the transcription request.
107
+ * @returns A `DeepgramResponse` object containing the transcription result or an error.
108
+ */
109
+ transcribeUrlCallback(source, callback, options, endpoint = ":version/listen") {
110
+ return __awaiter(this, void 0, void 0, function* () {
111
+ try {
112
+ let body;
113
+ if ((0, helpers_1.isUrlSource)(source)) {
114
+ body = JSON.stringify(source);
115
+ }
116
+ else {
117
+ throw new errors_1.DeepgramError("Unknown transcription source type");
118
+ }
119
+ const requestUrl = this.getRequestUrl(endpoint, {}, Object.assign(Object.assign({}, options), { callback: callback.toString() }));
120
+ const result = yield this.post(requestUrl, body).then((result) => result.json());
121
+ return { result, error: null };
122
+ }
123
+ catch (error) {
124
+ if ((0, errors_1.isDeepgramError)(error)) {
125
+ return { result: null, error };
126
+ }
127
+ throw error;
128
+ }
129
+ });
130
+ }
131
+ /**
132
+ * Transcribes audio from a file asynchronously.
133
+ *
134
+ * @param source - The file source object containing the audio file to transcribe.
135
+ * @param callback - The callback URL to receive the transcription result.
136
+ * @param options - An optional `PrerecordedSchema` object containing additional options for the transcription.
137
+ * @param endpoint - An optional endpoint string to use for the transcription request.
138
+ * @returns A `DeepgramResponse` object containing the transcription result or an error.
139
+ */
140
+ transcribeFileCallback(source, callback, options, endpoint = ":version/listen") {
141
+ return __awaiter(this, void 0, void 0, function* () {
142
+ try {
143
+ let body;
144
+ if ((0, helpers_1.isFileSource)(source)) {
145
+ body = source;
146
+ }
147
+ else {
148
+ throw new errors_1.DeepgramError("Unknown transcription source type");
149
+ }
150
+ const requestUrl = this.getRequestUrl(endpoint, {}, Object.assign(Object.assign({}, options), { callback: callback.toString() }));
151
+ const result = yield this.post(requestUrl, body, {
152
+ headers: { "Content-Type": "deepgram/audio+video" },
153
+ }).then((result) => result.json());
154
+ return { result, error: null };
155
+ }
156
+ catch (error) {
157
+ if ((0, errors_1.isDeepgramError)(error)) {
158
+ return { result: null, error };
159
+ }
160
+ throw error;
161
+ }
162
+ });
163
+ }
164
+ }
165
+ exports.ListenRestClient = ListenRestClient;
166
+ exports.PrerecordedClient = ListenRestClient;
167
+ //# sourceMappingURL=ListenRestClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ListenRestClient.js","sourceRoot":"","sources":["../../../src/packages/ListenRestClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAwE;AACxE,0CAA+D;AAU/D,6DAA0D;AAE1D;;;;;;;;;;GAUG;AACH,MAAa,gBAAiB,SAAQ,uCAAkB;IAAxD;;QACS,cAAS,GAAW,QAAQ,CAAC;IA6KtC,CAAC;IA3KC;;;;;;;OAOG;IACG,aAAa,CACjB,MAAiB,EACjB,OAA2B,EAC3B,QAAQ,GAAG,iBAAiB;;YAE5B,IAAI;gBACF,IAAI,IAAI,CAAC;gBAET,IAAI,IAAA,qBAAW,EAAC,MAAM,CAAC,EAAE;oBACvB,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;iBAC/B;qBAAM;oBACL,MAAM,IAAI,sBAAa,CAAC,mCAAmC,CAAC,CAAC;iBAC9D;gBAED,IAAI,OAAO,KAAK,SAAS,IAAI,UAAU,IAAI,OAAO,EAAE;oBAClD,MAAM,IAAI,sBAAa,CACrB,2IAA2I,CAC5I,CAAC;iBACH;gBAED,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,EAAE,gBAAO,EAAE,EAAK,OAAO,EAAG,CAAC;gBAC3E,MAAM,MAAM,GAA4B,MAAM,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,CAA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