@deepgram/sdk 3.3.4 → 3.4.0

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 (300) 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/SyncPrerecordedResponse.d.ts +1 -0
  43. package/dist/main/lib/types/SyncPrerecordedResponse.d.ts.map +1 -1
  44. package/dist/main/lib/types/TranscriptionSchema.d.ts +0 -1
  45. package/dist/main/lib/types/TranscriptionSchema.d.ts.map +1 -1
  46. package/dist/main/lib/types/UpdateProjectMemberScopeSchema.d.ts +1 -1
  47. package/dist/main/lib/types/UpdateProjectMemberScopeSchema.d.ts.map +1 -1
  48. package/dist/main/lib/types/UpdateProjectSchema.d.ts +0 -1
  49. package/dist/main/lib/types/UpdateProjectSchema.d.ts.map +1 -1
  50. package/dist/main/lib/types/index.d.ts +39 -39
  51. package/dist/main/lib/types/index.d.ts.map +1 -1
  52. package/dist/main/lib/types/index.js +53 -0
  53. package/dist/main/lib/types/index.js.map +1 -1
  54. package/dist/main/lib/version.d.ts +1 -1
  55. package/dist/main/lib/version.js +1 -1
  56. package/dist/main/packages/AbstractClient.d.ts +63 -10
  57. package/dist/main/packages/AbstractClient.d.ts.map +1 -1
  58. package/dist/main/packages/AbstractClient.js +103 -50
  59. package/dist/main/packages/AbstractClient.js.map +1 -1
  60. package/dist/main/packages/AbstractLiveClient.d.ts +114 -0
  61. package/dist/main/packages/AbstractLiveClient.d.ts.map +1 -0
  62. package/dist/main/packages/AbstractLiveClient.js +238 -0
  63. package/dist/main/packages/AbstractLiveClient.js.map +1 -0
  64. package/dist/main/packages/AbstractRestClient.d.ts +105 -0
  65. package/dist/main/packages/AbstractRestClient.d.ts.map +1 -0
  66. package/dist/main/packages/AbstractRestClient.js +185 -0
  67. package/dist/main/packages/AbstractRestClient.js.map +1 -0
  68. package/dist/main/packages/ListenClient.d.ts +21 -4
  69. package/dist/main/packages/ListenClient.d.ts.map +1 -1
  70. package/dist/main/packages/ListenClient.js +25 -5
  71. package/dist/main/packages/ListenClient.js.map +1 -1
  72. package/dist/main/packages/ListenLiveClient.d.ts +58 -0
  73. package/dist/main/packages/ListenLiveClient.d.ts.map +1 -0
  74. package/dist/main/packages/ListenLiveClient.js +119 -0
  75. package/dist/main/packages/ListenLiveClient.js.map +1 -0
  76. package/dist/main/packages/ListenRestClient.d.ts +57 -0
  77. package/dist/main/packages/ListenRestClient.d.ts.map +1 -0
  78. package/dist/main/packages/ListenRestClient.js +167 -0
  79. package/dist/main/packages/ListenRestClient.js.map +1 -0
  80. package/dist/main/packages/ManageRestClient.d.ts +286 -0
  81. package/dist/main/packages/ManageRestClient.d.ts.map +1 -0
  82. package/dist/main/packages/ManageRestClient.js +628 -0
  83. package/dist/main/packages/ManageRestClient.js.map +1 -0
  84. package/dist/main/packages/ReadRestClient.d.ts +57 -0
  85. package/dist/main/packages/ReadRestClient.d.ts.map +1 -0
  86. package/dist/main/packages/ReadRestClient.js +165 -0
  87. package/dist/main/packages/ReadRestClient.js.map +1 -0
  88. package/dist/main/packages/SelfHostedRestClient.d.ts +47 -0
  89. package/dist/main/packages/SelfHostedRestClient.d.ts.map +1 -0
  90. package/dist/main/packages/SelfHostedRestClient.js +120 -0
  91. package/dist/main/packages/SelfHostedRestClient.js.map +1 -0
  92. package/dist/main/packages/SpeakRestClient.d.ts +36 -0
  93. package/dist/main/packages/SpeakRestClient.d.ts.map +1 -0
  94. package/dist/main/packages/SpeakRestClient.js +84 -0
  95. package/dist/main/packages/SpeakRestClient.js.map +1 -0
  96. package/dist/main/packages/index.d.ts +10 -8
  97. package/dist/main/packages/index.d.ts.map +1 -1
  98. package/dist/main/packages/index.js +24 -17
  99. package/dist/main/packages/index.js.map +1 -1
  100. package/dist/module/DeepgramClient.d.ts +65 -12
  101. package/dist/module/DeepgramClient.d.ts.map +1 -1
  102. package/dist/module/DeepgramClient.js +72 -17
  103. package/dist/module/DeepgramClient.js.map +1 -1
  104. package/dist/module/index.d.ts +13 -4
  105. package/dist/module/index.d.ts.map +1 -1
  106. package/dist/module/index.js +18 -8
  107. package/dist/module/index.js.map +1 -1
  108. package/dist/module/lib/constants.d.ts +16 -7
  109. package/dist/module/lib/constants.d.ts.map +1 -1
  110. package/dist/module/lib/constants.js +26 -9
  111. package/dist/module/lib/constants.js.map +1 -1
  112. package/dist/module/lib/enums/LiveConnectionState.d.ts +5 -0
  113. package/dist/module/lib/enums/LiveConnectionState.d.ts.map +1 -1
  114. package/dist/module/lib/enums/LiveConnectionState.js +5 -0
  115. package/dist/module/lib/enums/LiveConnectionState.js.map +1 -1
  116. package/dist/module/lib/enums/LiveTranscriptionEvents.d.ts +24 -3
  117. package/dist/module/lib/enums/LiveTranscriptionEvents.d.ts.map +1 -1
  118. package/dist/module/lib/enums/LiveTranscriptionEvents.js +23 -2
  119. package/dist/module/lib/enums/LiveTranscriptionEvents.js.map +1 -1
  120. package/dist/module/lib/enums/index.d.ts +2 -2
  121. package/dist/module/lib/enums/index.d.ts.map +1 -1
  122. package/dist/module/lib/enums/index.js +2 -2
  123. package/dist/module/lib/enums/index.js.map +1 -1
  124. package/dist/module/lib/fetch.d.ts +19 -1
  125. package/dist/module/lib/fetch.d.ts.map +1 -1
  126. package/dist/module/lib/fetch.js +19 -1
  127. package/dist/module/lib/fetch.js.map +1 -1
  128. package/dist/module/lib/helpers.d.ts +9 -5
  129. package/dist/module/lib/helpers.d.ts.map +1 -1
  130. package/dist/module/lib/helpers.js +75 -4
  131. package/dist/module/lib/helpers.js.map +1 -1
  132. package/dist/module/lib/types/CreateProjectKeySchema.d.ts +0 -1
  133. package/dist/module/lib/types/CreateProjectKeySchema.d.ts.map +1 -1
  134. package/dist/module/lib/types/DeepgramClientOptions.d.ts +75 -8
  135. package/dist/module/lib/types/DeepgramClientOptions.d.ts.map +1 -1
  136. package/dist/module/lib/types/Fetch.d.ts +3 -13
  137. package/dist/module/lib/types/Fetch.d.ts.map +1 -1
  138. package/dist/module/lib/types/LiveConfigOptions.d.ts +6 -3
  139. package/dist/module/lib/types/LiveConfigOptions.d.ts.map +1 -1
  140. package/dist/module/lib/types/SyncPrerecordedResponse.d.ts +1 -0
  141. package/dist/module/lib/types/SyncPrerecordedResponse.d.ts.map +1 -1
  142. package/dist/module/lib/types/TranscriptionSchema.d.ts +0 -1
  143. package/dist/module/lib/types/TranscriptionSchema.d.ts.map +1 -1
  144. package/dist/module/lib/types/UpdateProjectMemberScopeSchema.d.ts +1 -1
  145. package/dist/module/lib/types/UpdateProjectMemberScopeSchema.d.ts.map +1 -1
  146. package/dist/module/lib/types/UpdateProjectSchema.d.ts +0 -1
  147. package/dist/module/lib/types/UpdateProjectSchema.d.ts.map +1 -1
  148. package/dist/module/lib/types/index.d.ts +39 -39
  149. package/dist/module/lib/types/index.d.ts.map +1 -1
  150. package/dist/module/lib/types/index.js +39 -1
  151. package/dist/module/lib/types/index.js.map +1 -1
  152. package/dist/module/lib/version.d.ts +1 -1
  153. package/dist/module/lib/version.js +1 -1
  154. package/dist/module/packages/AbstractClient.d.ts +63 -10
  155. package/dist/module/packages/AbstractClient.d.ts.map +1 -1
  156. package/dist/module/packages/AbstractClient.js +99 -50
  157. package/dist/module/packages/AbstractClient.js.map +1 -1
  158. package/dist/module/packages/AbstractLiveClient.d.ts +114 -0
  159. package/dist/module/packages/AbstractLiveClient.d.ts.map +1 -0
  160. package/dist/module/packages/AbstractLiveClient.js +211 -0
  161. package/dist/module/packages/AbstractLiveClient.js.map +1 -0
  162. package/dist/module/packages/AbstractRestClient.d.ts +105 -0
  163. package/dist/module/packages/AbstractRestClient.d.ts.map +1 -0
  164. package/dist/module/packages/AbstractRestClient.js +178 -0
  165. package/dist/module/packages/AbstractRestClient.js.map +1 -0
  166. package/dist/module/packages/ListenClient.d.ts +21 -4
  167. package/dist/module/packages/ListenClient.d.ts.map +1 -1
  168. package/dist/module/packages/ListenClient.js +25 -5
  169. package/dist/module/packages/ListenClient.js.map +1 -1
  170. package/dist/module/packages/ListenLiveClient.d.ts +58 -0
  171. package/dist/module/packages/ListenLiveClient.d.ts.map +1 -0
  172. package/dist/module/packages/ListenLiveClient.js +115 -0
  173. package/dist/module/packages/ListenLiveClient.js.map +1 -0
  174. package/dist/module/packages/ListenRestClient.d.ts +57 -0
  175. package/dist/module/packages/ListenRestClient.d.ts.map +1 -0
  176. package/dist/module/packages/ListenRestClient.js +163 -0
  177. package/dist/module/packages/ListenRestClient.js.map +1 -0
  178. package/dist/module/packages/ManageRestClient.d.ts +286 -0
  179. package/dist/module/packages/ManageRestClient.d.ts.map +1 -0
  180. package/dist/module/packages/ManageRestClient.js +624 -0
  181. package/dist/module/packages/ManageRestClient.js.map +1 -0
  182. package/dist/module/packages/ReadRestClient.d.ts +57 -0
  183. package/dist/module/packages/ReadRestClient.d.ts.map +1 -0
  184. package/dist/module/packages/ReadRestClient.js +161 -0
  185. package/dist/module/packages/ReadRestClient.js.map +1 -0
  186. package/dist/module/packages/SelfHostedRestClient.d.ts +47 -0
  187. package/dist/module/packages/SelfHostedRestClient.d.ts.map +1 -0
  188. package/dist/module/packages/SelfHostedRestClient.js +116 -0
  189. package/dist/module/packages/SelfHostedRestClient.js.map +1 -0
  190. package/dist/module/packages/SpeakRestClient.d.ts +36 -0
  191. package/dist/module/packages/SpeakRestClient.d.ts.map +1 -0
  192. package/dist/module/packages/SpeakRestClient.js +80 -0
  193. package/dist/module/packages/SpeakRestClient.js.map +1 -0
  194. package/dist/module/packages/index.d.ts +10 -8
  195. package/dist/module/packages/index.d.ts.map +1 -1
  196. package/dist/module/packages/index.js +10 -8
  197. package/dist/module/packages/index.js.map +1 -1
  198. package/dist/umd/deepgram.js +1 -1
  199. package/package.json +8 -6
  200. package/src/DeepgramClient.ts +81 -17
  201. package/src/index.ts +32 -7
  202. package/src/lib/constants.ts +33 -13
  203. package/src/lib/enums/LiveConnectionState.ts +11 -4
  204. package/src/lib/enums/LiveTranscriptionEvents.ts +27 -4
  205. package/src/lib/enums/index.ts +2 -2
  206. package/src/lib/fetch.ts +22 -2
  207. package/src/lib/helpers.ts +98 -9
  208. package/src/lib/types/CreateProjectKeySchema.ts +0 -1
  209. package/src/lib/types/DeepgramClientOptions.ts +75 -11
  210. package/src/lib/types/Fetch.ts +2 -24
  211. package/src/lib/types/LiveConfigOptions.ts +7 -3
  212. package/src/lib/types/SyncPrerecordedResponse.ts +1 -0
  213. package/src/lib/types/TranscriptionSchema.ts +0 -2
  214. package/src/lib/types/UpdateProjectMemberScopeSchema.ts +1 -1
  215. package/src/lib/types/UpdateProjectSchema.ts +0 -1
  216. package/src/lib/types/index.ts +39 -54
  217. package/src/lib/version.ts +1 -1
  218. package/src/packages/AbstractClient.ts +129 -61
  219. package/src/packages/AbstractLiveClient.ts +280 -0
  220. package/src/packages/AbstractRestClient.ts +221 -0
  221. package/src/packages/ListenClient.ts +26 -5
  222. package/src/packages/ListenLiveClient.ts +133 -0
  223. package/src/packages/ListenRestClient.ts +201 -0
  224. package/src/packages/ManageRestClient.ts +760 -0
  225. package/src/packages/ReadRestClient.ts +200 -0
  226. package/src/packages/SelfHostedRestClient.ts +134 -0
  227. package/src/packages/SpeakRestClient.ts +79 -0
  228. package/src/packages/index.ts +10 -8
  229. package/dist/main/packages/AbstractRestfulClient.d.ts +0 -26
  230. package/dist/main/packages/AbstractRestfulClient.d.ts.map +0 -1
  231. package/dist/main/packages/AbstractRestfulClient.js +0 -118
  232. package/dist/main/packages/AbstractRestfulClient.js.map +0 -1
  233. package/dist/main/packages/AbstractWsClient.d.ts +0 -10
  234. package/dist/main/packages/AbstractWsClient.d.ts.map +0 -1
  235. package/dist/main/packages/AbstractWsClient.js +0 -33
  236. package/dist/main/packages/AbstractWsClient.js.map +0 -1
  237. package/dist/main/packages/LiveClient.d.ts +0 -28
  238. package/dist/main/packages/LiveClient.d.ts.map +0 -1
  239. package/dist/main/packages/LiveClient.js +0 -110
  240. package/dist/main/packages/LiveClient.js.map +0 -1
  241. package/dist/main/packages/ManageClient.d.ts +0 -97
  242. package/dist/main/packages/ManageClient.d.ts.map +0 -1
  243. package/dist/main/packages/ManageClient.js +0 -463
  244. package/dist/main/packages/ManageClient.js.map +0 -1
  245. package/dist/main/packages/OnPremClient.d.ts +0 -21
  246. package/dist/main/packages/OnPremClient.d.ts.map +0 -1
  247. package/dist/main/packages/OnPremClient.js +0 -99
  248. package/dist/main/packages/OnPremClient.js.map +0 -1
  249. package/dist/main/packages/PrerecordedClient.d.ts +0 -10
  250. package/dist/main/packages/PrerecordedClient.d.ts.map +0 -1
  251. package/dist/main/packages/PrerecordedClient.js +0 -125
  252. package/dist/main/packages/PrerecordedClient.js.map +0 -1
  253. package/dist/main/packages/ReadClient.d.ts +0 -10
  254. package/dist/main/packages/ReadClient.d.ts.map +0 -1
  255. package/dist/main/packages/ReadClient.js +0 -123
  256. package/dist/main/packages/ReadClient.js.map +0 -1
  257. package/dist/main/packages/SpeakClient.d.ts +0 -12
  258. package/dist/main/packages/SpeakClient.d.ts.map +0 -1
  259. package/dist/main/packages/SpeakClient.js +0 -57
  260. package/dist/main/packages/SpeakClient.js.map +0 -1
  261. package/dist/module/packages/AbstractRestfulClient.d.ts +0 -26
  262. package/dist/module/packages/AbstractRestfulClient.d.ts.map +0 -1
  263. package/dist/module/packages/AbstractRestfulClient.js +0 -114
  264. package/dist/module/packages/AbstractRestfulClient.js.map +0 -1
  265. package/dist/module/packages/AbstractWsClient.d.ts +0 -10
  266. package/dist/module/packages/AbstractWsClient.d.ts.map +0 -1
  267. package/dist/module/packages/AbstractWsClient.js +0 -29
  268. package/dist/module/packages/AbstractWsClient.js.map +0 -1
  269. package/dist/module/packages/LiveClient.d.ts +0 -28
  270. package/dist/module/packages/LiveClient.d.ts.map +0 -1
  271. package/dist/module/packages/LiveClient.js +0 -106
  272. package/dist/module/packages/LiveClient.js.map +0 -1
  273. package/dist/module/packages/ManageClient.d.ts +0 -97
  274. package/dist/module/packages/ManageClient.d.ts.map +0 -1
  275. package/dist/module/packages/ManageClient.js +0 -459
  276. package/dist/module/packages/ManageClient.js.map +0 -1
  277. package/dist/module/packages/OnPremClient.d.ts +0 -21
  278. package/dist/module/packages/OnPremClient.d.ts.map +0 -1
  279. package/dist/module/packages/OnPremClient.js +0 -95
  280. package/dist/module/packages/OnPremClient.js.map +0 -1
  281. package/dist/module/packages/PrerecordedClient.d.ts +0 -10
  282. package/dist/module/packages/PrerecordedClient.d.ts.map +0 -1
  283. package/dist/module/packages/PrerecordedClient.js +0 -121
  284. package/dist/module/packages/PrerecordedClient.js.map +0 -1
  285. package/dist/module/packages/ReadClient.d.ts +0 -10
  286. package/dist/module/packages/ReadClient.d.ts.map +0 -1
  287. package/dist/module/packages/ReadClient.js +0 -119
  288. package/dist/module/packages/ReadClient.js.map +0 -1
  289. package/dist/module/packages/SpeakClient.d.ts +0 -12
  290. package/dist/module/packages/SpeakClient.d.ts.map +0 -1
  291. package/dist/module/packages/SpeakClient.js +0 -53
  292. package/dist/module/packages/SpeakClient.js.map +0 -1
  293. package/src/packages/AbstractRestfulClient.ts +0 -160
  294. package/src/packages/AbstractWsClient.ts +0 -42
  295. package/src/packages/LiveClient.ts +0 -140
  296. package/src/packages/ManageClient.ts +0 -584
  297. package/src/packages/OnPremClient.ts +0 -113
  298. package/src/packages/PrerecordedClient.ts +0 -162
  299. package/src/packages/ReadClient.ts +0 -161
  300. package/src/packages/SpeakClient.ts +0 -50
@@ -1,162 +0,0 @@
1
- import { AbstractRestfulClient } from "./AbstractRestfulClient";
2
- import { CallbackUrl, appendSearchParams, isFileSource, isUrlSource } from "../lib/helpers";
3
- import { DeepgramError, isDeepgramError } from "../lib/errors";
4
- import type {
5
- AsyncPrerecordedResponse,
6
- DeepgramResponse,
7
- Fetch,
8
- FileSource,
9
- PrerecordedSchema,
10
- SyncPrerecordedResponse,
11
- UrlSource,
12
- } from "../lib/types";
13
-
14
- export class PrerecordedClient extends AbstractRestfulClient {
15
- async transcribeUrl(
16
- source: UrlSource,
17
- options?: PrerecordedSchema,
18
- endpoint = "v1/listen"
19
- ): Promise<DeepgramResponse<SyncPrerecordedResponse>> {
20
- try {
21
- let body;
22
-
23
- if (isUrlSource(source)) {
24
- body = JSON.stringify(source);
25
- } else {
26
- throw new DeepgramError("Unknown transcription source type");
27
- }
28
-
29
- if (options !== undefined && "callback" in options) {
30
- throw new DeepgramError(
31
- "Callback cannot be provided as an option to a synchronous transcription. Use `transcribeUrlCallback` or `transcribeFileCallback` instead."
32
- );
33
- }
34
-
35
- const transcriptionOptions: PrerecordedSchema = { ...{}, ...options };
36
-
37
- const url = new URL(endpoint, this.baseUrl);
38
- appendSearchParams(url.searchParams, transcriptionOptions);
39
-
40
- const result: SyncPrerecordedResponse = await this.post(this.fetch as Fetch, url, body);
41
-
42
- return { result, error: null };
43
- } catch (error) {
44
- if (isDeepgramError(error)) {
45
- return { result: null, error };
46
- }
47
-
48
- throw error;
49
- }
50
- }
51
-
52
- async transcribeFile(
53
- source: FileSource,
54
- options?: PrerecordedSchema,
55
- endpoint = "v1/listen"
56
- ): Promise<DeepgramResponse<SyncPrerecordedResponse>> {
57
- try {
58
- let body;
59
-
60
- if (isFileSource(source)) {
61
- body = source;
62
- } else {
63
- throw new DeepgramError("Unknown transcription source type");
64
- }
65
-
66
- if (options !== undefined && "callback" in options) {
67
- throw new DeepgramError(
68
- "Callback cannot be provided as an option to a synchronous transcription. Use `transcribeUrlCallback` or `transcribeFileCallback` instead."
69
- );
70
- }
71
-
72
- const transcriptionOptions: PrerecordedSchema = { ...{}, ...options };
73
-
74
- const url = new URL(endpoint, this.baseUrl);
75
- appendSearchParams(url.searchParams, transcriptionOptions);
76
-
77
- const result: SyncPrerecordedResponse = await this.post(this.fetch as Fetch, url, body, {
78
- "Content-Type": "deepgram/audio+video",
79
- });
80
-
81
- return { result, error: null };
82
- } catch (error) {
83
- if (isDeepgramError(error)) {
84
- return { result: null, error };
85
- }
86
-
87
- throw error;
88
- }
89
- }
90
-
91
- async transcribeUrlCallback(
92
- source: UrlSource,
93
- callback: CallbackUrl,
94
- options?: PrerecordedSchema,
95
- endpoint = "v1/listen"
96
- ): Promise<DeepgramResponse<AsyncPrerecordedResponse>> {
97
- try {
98
- let body;
99
-
100
- if (isUrlSource(source)) {
101
- body = JSON.stringify(source);
102
- } else {
103
- throw new DeepgramError("Unknown transcription source type");
104
- }
105
-
106
- const transcriptionOptions: PrerecordedSchema = {
107
- ...options,
108
- ...{ callback: callback.toString() },
109
- };
110
-
111
- const url = new URL(endpoint, this.baseUrl);
112
- appendSearchParams(url.searchParams, transcriptionOptions);
113
-
114
- const result: AsyncPrerecordedResponse = await this.post(this.fetch as Fetch, url, body);
115
-
116
- return { result, error: null };
117
- } catch (error) {
118
- if (isDeepgramError(error)) {
119
- return { result: null, error };
120
- }
121
-
122
- throw error;
123
- }
124
- }
125
-
126
- async transcribeFileCallback(
127
- source: FileSource,
128
- callback: CallbackUrl,
129
- options?: PrerecordedSchema,
130
- endpoint = "v1/listen"
131
- ): Promise<DeepgramResponse<AsyncPrerecordedResponse>> {
132
- try {
133
- let body;
134
-
135
- if (isFileSource(source)) {
136
- body = source;
137
- } else {
138
- throw new DeepgramError("Unknown transcription source type");
139
- }
140
-
141
- const transcriptionOptions: PrerecordedSchema = {
142
- ...options,
143
- ...{ callback: callback.toString() },
144
- };
145
-
146
- const url = new URL(endpoint, this.baseUrl);
147
- appendSearchParams(url.searchParams, transcriptionOptions);
148
-
149
- const result: AsyncPrerecordedResponse = await this.post(this.fetch as Fetch, url, body, {
150
- "Content-Type": "deepgram/audio+video",
151
- });
152
-
153
- return { result, error: null };
154
- } catch (error) {
155
- if (isDeepgramError(error)) {
156
- return { result: null, error };
157
- }
158
-
159
- throw error;
160
- }
161
- }
162
- }
@@ -1,161 +0,0 @@
1
- import { AbstractRestfulClient } from "./AbstractRestfulClient";
2
- import { CallbackUrl, appendSearchParams, isTextSource, isUrlSource } from "../lib/helpers";
3
- import { DeepgramError, isDeepgramError } from "../lib/errors";
4
- import type {
5
- AnalyzeSchema,
6
- AsyncAnalyzeResponse,
7
- DeepgramResponse,
8
- Fetch,
9
- PrerecordedSchema,
10
- SyncAnalyzeResponse,
11
- TextSource,
12
- UrlSource,
13
- } from "../lib/types";
14
-
15
- export class ReadClient extends AbstractRestfulClient {
16
- async analyzeUrl(
17
- source: UrlSource,
18
- options?: AnalyzeSchema,
19
- endpoint = "v1/read"
20
- ): Promise<DeepgramResponse<SyncAnalyzeResponse>> {
21
- try {
22
- let body;
23
-
24
- if (isUrlSource(source)) {
25
- body = JSON.stringify(source);
26
- } else {
27
- throw new DeepgramError("Unknown source type");
28
- }
29
-
30
- if (options !== undefined && "callback" in options) {
31
- throw new DeepgramError(
32
- "Callback cannot be provided as an option to a synchronous transcription. Use `analyzeUrlCallback` or `analyzeTextCallback` instead."
33
- );
34
- }
35
-
36
- const analyzeOptions: AnalyzeSchema = { ...{}, ...options };
37
-
38
- const url = new URL(endpoint, this.baseUrl);
39
- appendSearchParams(url.searchParams, analyzeOptions);
40
-
41
- const result: SyncAnalyzeResponse = await this.post(this.fetch as Fetch, url, body);
42
-
43
- return { result, error: null };
44
- } catch (error) {
45
- if (isDeepgramError(error)) {
46
- return { result: null, error };
47
- }
48
-
49
- throw error;
50
- }
51
- }
52
-
53
- async analyzeText(
54
- source: TextSource,
55
- options?: AnalyzeSchema,
56
- endpoint = "v1/read"
57
- ): Promise<DeepgramResponse<SyncAnalyzeResponse>> {
58
- try {
59
- let body;
60
-
61
- if (isTextSource(source)) {
62
- body = JSON.stringify(source);
63
- } else {
64
- throw new DeepgramError("Unknown source type");
65
- }
66
-
67
- if (options !== undefined && "callback" in options) {
68
- throw new DeepgramError(
69
- "Callback cannot be provided as an option to a synchronous requests. Use `analyzeUrlCallback` or `analyzeTextCallback` instead."
70
- );
71
- }
72
-
73
- const analyzeOptions: AnalyzeSchema = { ...{}, ...options };
74
-
75
- const url = new URL(endpoint, this.baseUrl);
76
- appendSearchParams(url.searchParams, analyzeOptions);
77
-
78
- const result: SyncAnalyzeResponse = await this.post(this.fetch as Fetch, url, body);
79
-
80
- return { result, error: null };
81
- } catch (error) {
82
- if (isDeepgramError(error)) {
83
- return { result: null, error };
84
- }
85
-
86
- throw error;
87
- }
88
- }
89
-
90
- async analyzeUrlCallback(
91
- source: UrlSource,
92
- callback: CallbackUrl,
93
- options?: AnalyzeSchema,
94
- endpoint = "v1/read"
95
- ): Promise<DeepgramResponse<AsyncAnalyzeResponse>> {
96
- try {
97
- let body;
98
-
99
- if (isUrlSource(source)) {
100
- body = JSON.stringify(source);
101
- } else {
102
- throw new DeepgramError("Unknown source type");
103
- }
104
-
105
- const transcriptionOptions: PrerecordedSchema = {
106
- ...options,
107
- ...{ callback: callback.toString() },
108
- };
109
-
110
- const url = new URL(endpoint, this.baseUrl);
111
- appendSearchParams(url.searchParams, transcriptionOptions);
112
-
113
- const result: AsyncAnalyzeResponse = await this.post(this.fetch as Fetch, url, body);
114
-
115
- return { result, error: null };
116
- } catch (error) {
117
- if (isDeepgramError(error)) {
118
- return { result: null, error };
119
- }
120
-
121
- throw error;
122
- }
123
- }
124
-
125
- async analyzeTextCallback(
126
- source: TextSource,
127
- callback: CallbackUrl,
128
- options?: AnalyzeSchema,
129
- endpoint = "v1/read"
130
- ): Promise<DeepgramResponse<AsyncAnalyzeResponse>> {
131
- try {
132
- let body;
133
-
134
- if (isTextSource(source)) {
135
- body = JSON.stringify(source);
136
- } else {
137
- throw new DeepgramError("Unknown source type");
138
- }
139
-
140
- const transcriptionOptions: PrerecordedSchema = {
141
- ...options,
142
- ...{ callback: callback.toString() },
143
- };
144
-
145
- const url = new URL(endpoint, this.baseUrl);
146
- appendSearchParams(url.searchParams, transcriptionOptions);
147
-
148
- const result: AsyncAnalyzeResponse = await this.post(this.fetch as Fetch, url, body, {
149
- "Content-Type": "deepgram/audio+video",
150
- });
151
-
152
- return { result, error: null };
153
- } catch (error) {
154
- if (isDeepgramError(error)) {
155
- return { result: null, error };
156
- }
157
-
158
- throw error;
159
- }
160
- }
161
- }
@@ -1,50 +0,0 @@
1
- import { AbstractRestfulClient } from "./AbstractRestfulClient";
2
- import { DeepgramError, DeepgramUnknownError, isDeepgramError } from "../lib/errors";
3
- import { appendSearchParams, isTextSource } from "../lib/helpers";
4
- import { Fetch, SpeakSchema, TextSource } from "../lib/types";
5
-
6
- export class SpeakClient extends AbstractRestfulClient {
7
- public result: undefined | Response;
8
-
9
- /**
10
- * @see https://developers.deepgram.com/reference/text-to-speech-api
11
- */
12
- async request(
13
- source: TextSource,
14
- options?: SpeakSchema,
15
- endpoint = "v1/speak"
16
- ): Promise<SpeakClient> {
17
- try {
18
- let body;
19
-
20
- if (isTextSource(source)) {
21
- body = JSON.stringify(source);
22
- } else {
23
- throw new DeepgramError("Unknown transcription source type");
24
- }
25
-
26
- const speakOptions: SpeakSchema = { ...{ model: "aura-asteria-en" }, ...options };
27
-
28
- const url = new URL(endpoint, this.baseUrl);
29
- appendSearchParams(url.searchParams, speakOptions);
30
- this.result = await this._handleRawRequest(this.fetch as Fetch, "POST", url, {}, {}, body);
31
- return this;
32
- } catch (error) {
33
- throw error;
34
- }
35
- }
36
-
37
- async getStream(): Promise<ReadableStream<Uint8Array> | null> {
38
- if (!this.result)
39
- throw new DeepgramUnknownError("Tried to get stream before making request", "");
40
-
41
- return this.result.body;
42
- }
43
-
44
- async getHeaders(): Promise<Headers> {
45
- if (!this.result)
46
- throw new DeepgramUnknownError("Tried to get headers before making request", "");
47
-
48
- return this.result.headers;
49
- }
50
- }