@mcut/transcription-ai-sdk 0.1.0-alpha.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.
package/LICENSE ADDED
@@ -0,0 +1,187 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ https://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the
13
+ copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other
16
+ entities that control, are controlled by, or are under common control with
17
+ that entity. For the purposes of this definition, "control" means (i) the
18
+ power, direct or indirect, to cause the direction or management of such
19
+ entity, whether by contract or otherwise, or (ii) ownership of fifty percent
20
+ (50%) or more of the outstanding shares, or (iii) beneficial ownership of
21
+ such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
24
+ permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation source, and
28
+ configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical transformation
31
+ or translation of a Source form, including but not limited to compiled object
32
+ code, generated documentation, and conversions to other media types.
33
+
34
+ "Work" shall mean the work of authorship, whether in Source or Object form,
35
+ made available under the License, as indicated by a copyright notice that is
36
+ included in or attached to the work (an example is provided in the Appendix
37
+ below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object form,
40
+ that is based on (or derived from) the Work and for which the editorial
41
+ revisions, annotations, elaborations, or other modifications represent, as a
42
+ whole, an original work of authorship. For the purposes of this License,
43
+ Derivative Works shall not include works that remain separable from, or
44
+ merely link (or bind by name) to the interfaces of, the Work and Derivative
45
+ Works thereof.
46
+
47
+ "Contribution" shall mean any work of authorship, including the original
48
+ version of the Work and any modifications or additions to that Work or
49
+ Derivative Works thereof, that is intentionally submitted to Licensor for
50
+ inclusion in the Work by the copyright owner or by an individual or Legal
51
+ Entity authorized to submit on behalf of the copyright owner. For the
52
+ purposes of this definition, "submitted" means any form of electronic,
53
+ verbal, or written communication sent to the Licensor or its representatives,
54
+ including but not limited to communication on electronic mailing lists,
55
+ source code control systems, and issue tracking systems that are managed by,
56
+ or on behalf of, the Licensor for the purpose of discussing and improving the
57
+ Work, but excluding communication that is conspicuously marked or otherwise
58
+ designated in writing by the copyright owner as "Not a Contribution."
59
+
60
+ "Contributor" shall mean Licensor and any individual or Legal Entity on
61
+ behalf of whom a Contribution has been received by Licensor and subsequently
62
+ incorporated within the Work.
63
+
64
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
65
+ License, each Contributor hereby grants to You a perpetual, worldwide,
66
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
67
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
68
+ sublicense, and distribute the Work and such Derivative Works in Source or
69
+ Object form.
70
+
71
+ 3. Grant of Patent License. Subject to the terms and conditions of this
72
+ License, each Contributor hereby grants to You a perpetual, worldwide,
73
+ non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
74
+ section) patent license to make, have made, use, offer to sell, sell, import,
75
+ and otherwise transfer the Work, where such license applies only to those
76
+ patent claims licensable by such Contributor that are necessarily infringed
77
+ by their Contribution(s) alone or by combination of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You institute
79
+ patent litigation against any entity (including a cross-claim or counterclaim
80
+ in a lawsuit) alleging that the Work or a Contribution incorporated within
81
+ the Work constitutes direct or contributory patent infringement, then any
82
+ patent licenses granted to You under this License for that Work shall
83
+ terminate as of the date such litigation is filed.
84
+
85
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
86
+ Derivative Works thereof in any medium, with or without modifications, and in
87
+ Source or Object form, provided that You meet the following conditions:
88
+
89
+ (a) You must give any other recipients of the Work or Derivative Works a
90
+ copy of this License; and
91
+
92
+ (b) You must cause any modified files to carry prominent notices stating that
93
+ You changed the files; and
94
+
95
+ (c) You must retain, in the Source form of any Derivative Works that You
96
+ distribute, all copyright, patent, trademark, and attribution notices from
97
+ the Source form of the Work, excluding those notices that do not pertain to
98
+ any part of the Derivative Works; and
99
+
100
+ (d) If the Work includes a "NOTICE" text file as part of its distribution,
101
+ then any Derivative Works that You distribute must include a readable copy of
102
+ the attribution notices contained within such NOTICE file, excluding those
103
+ notices that do not pertain to any part of the Derivative Works, in at least
104
+ one of the following places: within a NOTICE text file distributed as part of
105
+ the Derivative Works; within the Source form or documentation, if provided
106
+ along with the Derivative Works; or, within a display generated by the
107
+ Derivative Works, if and wherever such third-party notices normally appear.
108
+ The contents of the NOTICE file are for informational purposes only and do
109
+ not modify the License. You may add Your own attribution notices within
110
+ Derivative Works that You distribute, alongside or as an addendum to the
111
+ NOTICE text from the Work, provided that such additional attribution notices
112
+ cannot be construed as modifying the License.
113
+
114
+ You may add Your own copyright statement to Your modifications and may
115
+ provide additional or different license terms and conditions for use,
116
+ reproduction, or distribution of Your modifications, or for any such
117
+ Derivative Works as a whole, provided Your use, reproduction, and
118
+ distribution of the Work otherwise complies with the conditions stated in
119
+ this License.
120
+
121
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
122
+ Contribution intentionally submitted for inclusion in the Work by You to the
123
+ Licensor shall be under the terms and conditions of this License, without any
124
+ additional terms or conditions. Notwithstanding the above, nothing herein
125
+ shall supersede or modify the terms of any separate license agreement you may
126
+ have executed with Licensor regarding such Contributions.
127
+
128
+ 6. Trademarks. This License does not grant permission to use the trade names,
129
+ trademarks, service marks, or product names of the Licensor, except as
130
+ required for reasonable and customary use in describing the origin of the
131
+ Work and reproducing the content of the NOTICE file.
132
+
133
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
134
+ writing, Licensor provides the Work (and each Contributor provides its
135
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
136
+ KIND, either express or implied, including, without limitation, any warranties
137
+ or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
138
+ PARTICULAR PURPOSE. You are solely responsible for determining the
139
+ appropriateness of using or redistributing the Work and assume any risks
140
+ associated with Your exercise of permissions under this License.
141
+
142
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
143
+ tort (including negligence), contract, or otherwise, unless required by
144
+ applicable law (such as deliberate and grossly negligent acts) or agreed to
145
+ in writing, shall any Contributor be liable to You for damages, including any
146
+ direct, indirect, special, incidental, or consequential damages of any
147
+ character arising as a result of this License or out of the use or inability
148
+ to use the Work (including but not limited to damages for loss of goodwill,
149
+ work stoppage, computer failure or malfunction, or any and all other
150
+ commercial damages or losses), even if such Contributor has been advised of
151
+ the possibility of such damages.
152
+
153
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work
154
+ or Derivative Works thereof, You may choose to offer, and charge a fee for,
155
+ acceptance of support, warranty, indemnity, or other liability obligations
156
+ and/or rights consistent with this License. However, in accepting such
157
+ obligations, You may act only on Your own behalf and on Your sole
158
+ responsibility, not on behalf of any other Contributor, and only if You agree
159
+ to indemnify, defend, and hold each Contributor harmless for any liability
160
+ incurred by, or claims asserted against, such Contributor by reason of your
161
+ accepting any such warranty or additional liability.
162
+
163
+ END OF TERMS AND CONDITIONS
164
+
165
+ APPENDIX: How to apply the Apache License to your work.
166
+
167
+ To apply the Apache License to your work, attach the following boilerplate
168
+ notice, with the fields enclosed by brackets "[]" replaced with your own
169
+ identifying information. (Don't include the brackets!) The text should be
170
+ enclosed in the appropriate comment syntax for the file format. We also
171
+ recommend that a file or class name and description of purpose be included on
172
+ the same "printed page" as the copyright notice for easier identification
173
+ within third-party archives.
174
+
175
+ Copyright [yyyy] [name of copyright owner]
176
+
177
+ Licensed under the Apache License, Version 2.0 (the "License");
178
+ you may not use this file except in compliance with the License.
179
+ You may obtain a copy of the License at
180
+
181
+ https://www.apache.org/licenses/LICENSE-2.0
182
+
183
+ Unless required by applicable law or agreed to in writing, software
184
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
185
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
186
+ See the License for the specific language governing permissions and
187
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # @mcut/transcription-ai-sdk
2
+
3
+ Vercel AI SDK transcription provider for mcut.
4
+
5
+ ```sh
6
+ bun add @mcut/transcription-ai-sdk @mcut/transcription ai
7
+ ```
8
+
9
+ This package normalizes AI SDK transcription results into the shared
10
+ `@mcut/transcription` format. The `ai` package is a peer dependency so apps can
11
+ choose and configure their transcription model provider.
@@ -0,0 +1,52 @@
1
+ import { experimental_transcribe } from "ai";
2
+ import { TranscriptResult, TranscriptionProvider } from "@mcut/transcription";
3
+
4
+ //#region src/index.d.ts
5
+ type TranscribeArgs = Parameters<typeof experimental_transcribe>[0];
6
+ interface AISDKTranscriptionProviderOptions {
7
+ /** Any AI SDK transcription model, e.g. `openai.transcription('whisper-1')`. */
8
+ model: TranscribeArgs['model'];
9
+ /**
10
+ * Provider-specific options forwarded to the AI SDK, e.g.
11
+ * `{ openai: { timestampGranularities: ['word'] } }` for word timings.
12
+ */
13
+ providerOptions?: TranscribeArgs['providerOptions'];
14
+ /** Provider id for diagnostics. Default `'ai-sdk'`. */
15
+ id?: string;
16
+ }
17
+ /** The fields of the AI SDK transcription result this adapter consumes. */
18
+ interface AISDKTranscriptionResultLike {
19
+ text: string;
20
+ segments: ReadonlyArray<{
21
+ text: string;
22
+ startSecond: number;
23
+ endSecond: number;
24
+ }>;
25
+ language: string | undefined;
26
+ durationInSeconds: number | undefined;
27
+ }
28
+ /**
29
+ * Normalize an AI SDK transcription result to mcut's `TranscriptResult`.
30
+ * Word-granularity outputs (every segment a single word) are detected and
31
+ * exposed as `words` so captions get karaoke timings; sentence-level
32
+ * segments pass through as `segments`.
33
+ */
34
+ declare function normalizeAISDKResult(result: AISDKTranscriptionResultLike): TranscriptResult;
35
+ /**
36
+ * An mcut transcription provider backed by the Vercel AI SDK — one adapter
37
+ * unlocks every AI SDK transcription model (OpenAI, Deepgram, Groq,
38
+ * ElevenLabs, AssemblyAI, ...). Runs wherever the AI SDK runs; keep API
39
+ * keys server-side.
40
+ *
41
+ * ```ts
42
+ * import { openai } from '@ai-sdk/openai'
43
+ * const provider = createAISDKTranscriptionProvider({
44
+ * model: openai.transcription('whisper-1'),
45
+ * providerOptions: { openai: { timestampGranularities: ['word'] } },
46
+ * })
47
+ * const transcript = await provider.transcribe({ audio: wavBlob })
48
+ * ```
49
+ */
50
+ declare function createAISDKTranscriptionProvider(options: AISDKTranscriptionProviderOptions): TranscriptionProvider;
51
+ //#endregion
52
+ export { AISDKTranscriptionProviderOptions, AISDKTranscriptionResultLike, createAISDKTranscriptionProvider, normalizeAISDKResult };
package/dist/index.js ADDED
@@ -0,0 +1,59 @@
1
+ import { experimental_transcribe } from "ai";
2
+ //#region src/index.ts
3
+ /**
4
+ * Normalize an AI SDK transcription result to mcut's `TranscriptResult`.
5
+ * Word-granularity outputs (every segment a single word) are detected and
6
+ * exposed as `words` so captions get karaoke timings; sentence-level
7
+ * segments pass through as `segments`.
8
+ */
9
+ function normalizeAISDKResult(result) {
10
+ const mapped = result.segments.map((segment) => ({
11
+ text: segment.text.trim(),
12
+ startMs: Math.round(segment.startSecond * 1e3),
13
+ endMs: Math.round(segment.endSecond * 1e3)
14
+ }));
15
+ const isWordLevel = mapped.length > 0 && mapped.every((s) => !/\s/.test(s.text));
16
+ return {
17
+ text: result.text,
18
+ ...result.language !== void 0 ? { language: result.language } : {},
19
+ ...result.durationInSeconds !== void 0 ? { durationMs: Math.round(result.durationInSeconds * 1e3) } : {},
20
+ words: isWordLevel ? mapped : [],
21
+ segments: isWordLevel ? [] : mapped
22
+ };
23
+ }
24
+ async function toAudioArg(audio) {
25
+ if (typeof audio === "string") return new URL(audio);
26
+ if (audio instanceof Blob) return new Uint8Array(await audio.arrayBuffer());
27
+ if (audio instanceof ArrayBuffer) return new Uint8Array(audio);
28
+ return audio;
29
+ }
30
+ /**
31
+ * An mcut transcription provider backed by the Vercel AI SDK — one adapter
32
+ * unlocks every AI SDK transcription model (OpenAI, Deepgram, Groq,
33
+ * ElevenLabs, AssemblyAI, ...). Runs wherever the AI SDK runs; keep API
34
+ * keys server-side.
35
+ *
36
+ * ```ts
37
+ * import { openai } from '@ai-sdk/openai'
38
+ * const provider = createAISDKTranscriptionProvider({
39
+ * model: openai.transcription('whisper-1'),
40
+ * providerOptions: { openai: { timestampGranularities: ['word'] } },
41
+ * })
42
+ * const transcript = await provider.transcribe({ audio: wavBlob })
43
+ * ```
44
+ */
45
+ function createAISDKTranscriptionProvider(options) {
46
+ return {
47
+ id: options.id ?? "ai-sdk",
48
+ async transcribe(input, transcribeOptions) {
49
+ return normalizeAISDKResult(await experimental_transcribe({
50
+ model: options.model,
51
+ audio: await toAudioArg(input.audio),
52
+ ...options.providerOptions ? { providerOptions: options.providerOptions } : {},
53
+ ...transcribeOptions?.signal ? { abortSignal: transcribeOptions.signal } : {}
54
+ }));
55
+ }
56
+ };
57
+ }
58
+ //#endregion
59
+ export { createAISDKTranscriptionProvider, normalizeAISDKResult };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@mcut/transcription-ai-sdk",
3
+ "version": "0.1.0-alpha.0",
4
+ "description": "mcut transcription provider backed by the Vercel AI SDK — use any AI SDK transcription model (OpenAI, Deepgram, Groq, ElevenLabs, ...)",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "sideEffects": false,
19
+ "scripts": {
20
+ "build": "tsdown",
21
+ "dev": "tsdown --watch --no-clean",
22
+ "typecheck": "tsc --noEmit",
23
+ "test": "bun test"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/mattppal/mcut.git",
28
+ "directory": "packages/transcription-ai-sdk"
29
+ },
30
+ "peerDependencies": {
31
+ "@mcut/transcription": "0.1.0-alpha.0",
32
+ "ai": ">=5.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "@mcut/transcription": "0.1.0-alpha.0",
36
+ "ai": "^6.0.0"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public",
40
+ "provenance": true
41
+ },
42
+ "author": "Matt Palmer",
43
+ "homepage": "https://github.com/mattppal/mcut/tree/main/packages/transcription-ai-sdk#readme",
44
+ "bugs": {
45
+ "url": "https://github.com/mattppal/mcut/issues"
46
+ },
47
+ "keywords": [
48
+ "mcut",
49
+ "video",
50
+ "video-editing",
51
+ "timeline",
52
+ "typescript",
53
+ "transcription",
54
+ "ai-sdk"
55
+ ]
56
+ }