@unieai/rabi-experimental-api-speech-to-text 0.0.0-stage → 0.2.2-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +7 -2
- package/lib/index.js +219 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +505 -0
- package/lib/typert.remote-client.d.ts +42 -0
- package/lib/typert.remote-client.js +375 -0
- package/lib/types/index.d.ts +64 -0
- package/lib/types/index.js +142 -0
- package/lib/types/types.d.ts +26 -0
- package/lib/types/types.js +1 -0
- package/locale/de.json +6 -0
- package/locale/en.json +6 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +55 -4
- package/src/index.ts +111 -0
- package/src/types.ts +25 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DeepSeek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @unieai/rabi-experimental-api-speech-to-text
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Authenticated experimental speech transcription for browser clients
|
|
4
|
+
|
|
5
|
+
Part of Rabi, the agent harness UnieAI Code runs on. Installed as a dependency of `@unieai/rabi`;
|
|
6
|
+
not meant to be used on its own.
|
|
7
|
+
|
|
8
|
+
See LICENSE for the license and copyright of this package.
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import z from "@unieai/schemastery";
|
|
2
|
+
import { Remote, RemoteError, TypertRemoteService } from "@unieai/rabi-typert-protocol";
|
|
3
|
+
import { validateWave } from "@unieai/rabi-experimental-speech-to-text/wave";
|
|
4
|
+
//#region lib/types/index.js
|
|
5
|
+
var __runInitializers = function(thisArg, initializers, value) {
|
|
6
|
+
var useValue = arguments.length > 2;
|
|
7
|
+
for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
8
|
+
return useValue ? value : void 0;
|
|
9
|
+
};
|
|
10
|
+
var __esDecorate = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
11
|
+
function accept(f) {
|
|
12
|
+
if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
|
|
13
|
+
return f;
|
|
14
|
+
}
|
|
15
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
16
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
17
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
18
|
+
var _, done = false;
|
|
19
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
20
|
+
var context = {};
|
|
21
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
22
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
23
|
+
context.addInitializer = function(f) {
|
|
24
|
+
if (done) throw new TypeError("Cannot add initializers after decoration has completed");
|
|
25
|
+
extraInitializers.push(accept(f || null));
|
|
26
|
+
};
|
|
27
|
+
var result = (0, decorators[i])(kind === "accessor" ? {
|
|
28
|
+
get: descriptor.get,
|
|
29
|
+
set: descriptor.set
|
|
30
|
+
} : descriptor[key], context);
|
|
31
|
+
if (kind === "accessor") {
|
|
32
|
+
if (result === void 0) continue;
|
|
33
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
34
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
35
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
36
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
37
|
+
} else if (_ = accept(result)) if (kind === "field") initializers.unshift(_);
|
|
38
|
+
else descriptor[key] = _;
|
|
39
|
+
}
|
|
40
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
41
|
+
done = true;
|
|
42
|
+
};
|
|
43
|
+
let SpeechController = (() => {
|
|
44
|
+
let _classSuper = TypertRemoteService;
|
|
45
|
+
let _instanceExtraInitializers = [];
|
|
46
|
+
let _catalog_decorators;
|
|
47
|
+
let _follow_decorators;
|
|
48
|
+
let _configure_decorators;
|
|
49
|
+
let _prepare_decorators;
|
|
50
|
+
let _cancelPreparation_decorators;
|
|
51
|
+
let _transcribe_decorators;
|
|
52
|
+
return class SpeechController extends _classSuper {
|
|
53
|
+
static {
|
|
54
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
55
|
+
_catalog_decorators = [Remote];
|
|
56
|
+
_follow_decorators = [Remote({ mode: "stream" })];
|
|
57
|
+
_configure_decorators = [Remote];
|
|
58
|
+
_prepare_decorators = [Remote];
|
|
59
|
+
_cancelPreparation_decorators = [Remote];
|
|
60
|
+
_transcribe_decorators = [Remote];
|
|
61
|
+
__esDecorate(this, null, _catalog_decorators, {
|
|
62
|
+
kind: "method",
|
|
63
|
+
name: "catalog",
|
|
64
|
+
static: false,
|
|
65
|
+
private: false,
|
|
66
|
+
access: {
|
|
67
|
+
has: (obj) => "catalog" in obj,
|
|
68
|
+
get: (obj) => obj.catalog
|
|
69
|
+
},
|
|
70
|
+
metadata: _metadata
|
|
71
|
+
}, null, _instanceExtraInitializers);
|
|
72
|
+
__esDecorate(this, null, _follow_decorators, {
|
|
73
|
+
kind: "method",
|
|
74
|
+
name: "follow",
|
|
75
|
+
static: false,
|
|
76
|
+
private: false,
|
|
77
|
+
access: {
|
|
78
|
+
has: (obj) => "follow" in obj,
|
|
79
|
+
get: (obj) => obj.follow
|
|
80
|
+
},
|
|
81
|
+
metadata: _metadata
|
|
82
|
+
}, null, _instanceExtraInitializers);
|
|
83
|
+
__esDecorate(this, null, _configure_decorators, {
|
|
84
|
+
kind: "method",
|
|
85
|
+
name: "configure",
|
|
86
|
+
static: false,
|
|
87
|
+
private: false,
|
|
88
|
+
access: {
|
|
89
|
+
has: (obj) => "configure" in obj,
|
|
90
|
+
get: (obj) => obj.configure
|
|
91
|
+
},
|
|
92
|
+
metadata: _metadata
|
|
93
|
+
}, null, _instanceExtraInitializers);
|
|
94
|
+
__esDecorate(this, null, _prepare_decorators, {
|
|
95
|
+
kind: "method",
|
|
96
|
+
name: "prepare",
|
|
97
|
+
static: false,
|
|
98
|
+
private: false,
|
|
99
|
+
access: {
|
|
100
|
+
has: (obj) => "prepare" in obj,
|
|
101
|
+
get: (obj) => obj.prepare
|
|
102
|
+
},
|
|
103
|
+
metadata: _metadata
|
|
104
|
+
}, null, _instanceExtraInitializers);
|
|
105
|
+
__esDecorate(this, null, _cancelPreparation_decorators, {
|
|
106
|
+
kind: "method",
|
|
107
|
+
name: "cancelPreparation",
|
|
108
|
+
static: false,
|
|
109
|
+
private: false,
|
|
110
|
+
access: {
|
|
111
|
+
has: (obj) => "cancelPreparation" in obj,
|
|
112
|
+
get: (obj) => obj.cancelPreparation
|
|
113
|
+
},
|
|
114
|
+
metadata: _metadata
|
|
115
|
+
}, null, _instanceExtraInitializers);
|
|
116
|
+
__esDecorate(this, null, _transcribe_decorators, {
|
|
117
|
+
kind: "method",
|
|
118
|
+
name: "transcribe",
|
|
119
|
+
static: false,
|
|
120
|
+
private: false,
|
|
121
|
+
access: {
|
|
122
|
+
has: (obj) => "transcribe" in obj,
|
|
123
|
+
get: (obj) => obj.transcribe
|
|
124
|
+
},
|
|
125
|
+
metadata: _metadata
|
|
126
|
+
}, null, _instanceExtraInitializers);
|
|
127
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, {
|
|
128
|
+
enumerable: true,
|
|
129
|
+
configurable: true,
|
|
130
|
+
writable: true,
|
|
131
|
+
value: _metadata
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
config = __runInitializers(this, _instanceExtraInitializers);
|
|
135
|
+
static inject = ["speechToText", "typert"];
|
|
136
|
+
static Config = z.object({
|
|
137
|
+
maxAudioBytes: z.natural().min(46).default(4 * 1024 * 1024),
|
|
138
|
+
maxDurationSeconds: z.number().min(1).default(120)
|
|
139
|
+
});
|
|
140
|
+
constructor(ctx, config) {
|
|
141
|
+
super(ctx, "speechController", { namespace: "speech" });
|
|
142
|
+
this.config = config;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Read provider choices without preparing a recognizer.
|
|
146
|
+
* @returns available providers, resolved default, and recording limits.
|
|
147
|
+
*/
|
|
148
|
+
catalog() {
|
|
149
|
+
return {
|
|
150
|
+
...this.ctx.speechToText.snapshot(),
|
|
151
|
+
...this.config
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Follow provider readiness independently of Session and preparation lifetimes.
|
|
156
|
+
* @param signal - Client observation lifetime.
|
|
157
|
+
* @returns initial and subsequent complete readiness snapshots.
|
|
158
|
+
*/
|
|
159
|
+
async *follow(signal) {
|
|
160
|
+
for await (const snapshot of this.ctx.speechToText.follow(signal)) yield {
|
|
161
|
+
...snapshot,
|
|
162
|
+
...this.config
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Persist the user's recognition preferences.
|
|
167
|
+
* @param patch - changed preference fields.
|
|
168
|
+
* @returns after preferences are saved.
|
|
169
|
+
*/
|
|
170
|
+
configure(patch) {
|
|
171
|
+
return this.ctx.speechToText.configure(patch);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Start or join one Host-owned preparation task.
|
|
175
|
+
* @param providerId - selected recognizer.
|
|
176
|
+
* @param options - task-local source selection validated by the provider.
|
|
177
|
+
*/
|
|
178
|
+
prepare(providerId, options) {
|
|
179
|
+
this.ctx.speechToText.prepare(providerId, options);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Explicitly cancel resource preparation.
|
|
183
|
+
* @param providerId - selected recognizer.
|
|
184
|
+
* @returns after the preparation task settles.
|
|
185
|
+
*/
|
|
186
|
+
cancelPreparation(providerId) {
|
|
187
|
+
return this.ctx.speechToText.cancelPreparation(providerId);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Validate and transcribe one recording through the explicit provider selection.
|
|
191
|
+
* @param request - canonical WAV encoded as base64, provider id and language hint.
|
|
192
|
+
* @param signal - Client cancellation or Remote contribution disposal.
|
|
193
|
+
* @returns final transcript without adding a Session event.
|
|
194
|
+
*/
|
|
195
|
+
async transcribe(request, signal) {
|
|
196
|
+
signal.throwIfAborted();
|
|
197
|
+
const encoded = request.audioBase64;
|
|
198
|
+
if (encoded.length > Math.ceil(this.config.maxAudioBytes / 3) * 4) throw new RemoteError("speech/invalid-audio", "Audio is invalid or exceeds the configured byte limit", { reason: "encoding-or-size" });
|
|
199
|
+
const audio = Buffer.from(encoded, "base64");
|
|
200
|
+
try {
|
|
201
|
+
if (audio.toString("base64") !== encoded) throw new Error("Audio must use canonical base64 encoding");
|
|
202
|
+
if (audio.length > this.config.maxAudioBytes) throw new Error("Audio exceeds the configured byte limit");
|
|
203
|
+
validateWave(audio, this.config.maxDurationSeconds);
|
|
204
|
+
const spec = this.ctx.speechToText.resolve({
|
|
205
|
+
audio,
|
|
206
|
+
...request.providerId === void 0 ? {} : { providerId: request.providerId },
|
|
207
|
+
...request.language === void 0 ? {} : { language: request.language }
|
|
208
|
+
});
|
|
209
|
+
return await this.ctx.speechToText.transcribe(spec, signal);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
signal.throwIfAborted();
|
|
212
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
213
|
+
throw new RemoteError("speech/transcription-failed", reason, { reason });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
})();
|
|
218
|
+
//#endregion
|
|
219
|
+
export { SpeechController as default };
|