@voicethere/agent 0.9.8 → 0.10.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/README.md +78 -6
- package/dist/agent.js +27 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/protocol.d.ts +40 -10
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js.map +1 -1
- package/dist/runtime.d.ts +10 -7
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +40 -35
- package/dist/runtime.js.map +1 -1
- package/dist/templates/echo/agent.js +27 -2
- package/dist/templates/echo-dc/agent.js +27 -2
- package/dist/templates/game-sync/agent.js +27 -2
- package/dist/templates/language-switch/agent.js +132 -36
- package/dist/templates/positional-tts/agent.js +27 -2
- package/dist/templates/recording-consent/agent.js +27 -2
- package/dist/templates/spatial-showcase/agent.js +27 -2
- package/dist/templates/voice-showcase/agent.js +27 -2
- package/dist/templates/voice-starter/agent.js +27 -2
- package/dist/templates/webhooks/agent.js +27 -2
- package/dist/templates/webhooks-redis/agent.js +27 -2
- package/dist/templates/world-sync/agent.js +27 -2
- package/dist/templates/world-sync-binary/agent.js +27 -2
- package/dist/voice-provider-id.d.ts +14 -0
- package/dist/voice-provider-id.d.ts.map +1 -0
- package/dist/voice-provider-id.js +27 -0
- package/dist/voice-provider-id.js.map +1 -0
- package/dist/voice-request-validation.d.ts +19 -0
- package/dist/voice-request-validation.d.ts.map +1 -0
- package/dist/voice-request-validation.js +111 -0
- package/dist/voice-request-validation.js.map +1 -0
- package/package.json +1 -1
- package/templates/language-switch/README.md +4 -4
- package/templates/language-switch/agent.ts +12 -11
- package/templates/voice-starter/agent.ts +5 -2
|
@@ -10761,6 +10761,27 @@ import { createHmac, timingSafeEqual } from "node:crypto";
|
|
|
10761
10761
|
import { randomUUID } from "node:crypto";
|
|
10762
10762
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
10763
10763
|
|
|
10764
|
+
// dist/voice-provider-id.js
|
|
10765
|
+
function toPublicProviderId(id) {
|
|
10766
|
+
const lower = id.trim().toLowerCase();
|
|
10767
|
+
return lower === "local-sherpa" || lower === "cluster-sherpa" ? "voicethere" : id;
|
|
10768
|
+
}
|
|
10769
|
+
|
|
10770
|
+
// dist/voice-request-validation.js
|
|
10771
|
+
var VOICE_SWITCH_MESSAGES = {
|
|
10772
|
+
invalid_scope: 'scope must be "stt", "tts" or "both".',
|
|
10773
|
+
nothing_to_apply: "Pass sttVendor, ttsVendor or language.",
|
|
10774
|
+
unknown_stt: 'No VoiceThere STT model matches sttVendor.model or the language; use a catalog id such as "en" or "en-small".',
|
|
10775
|
+
unknown_voice: 'No VoiceThere voice matches ttsVendor.voice or the language; use a catalog id such as "en-lessac".',
|
|
10776
|
+
invalid_language: 'language must be an ISO 639-1 code such as "en" or "de".',
|
|
10777
|
+
language_unavailable: "The models for this language did not start; try again later or pick another language.",
|
|
10778
|
+
unavailable: "Voice switching is not available for this session.",
|
|
10779
|
+
timeout: "The voice switch did not finish in time; try again."
|
|
10780
|
+
};
|
|
10781
|
+
function localVoiceSwitchMessage(reason) {
|
|
10782
|
+
return reason !== void 0 && Object.prototype.hasOwnProperty.call(VOICE_SWITCH_MESSAGES, reason) ? VOICE_SWITCH_MESSAGES[reason] : void 0;
|
|
10783
|
+
}
|
|
10784
|
+
|
|
10764
10785
|
// dist/session-serial-queue.js
|
|
10765
10786
|
var SessionSerialQueueCancellationError = class extends Error {
|
|
10766
10787
|
sessionId;
|
|
@@ -11137,16 +11158,18 @@ function handleVoiceLanguageControlAck(message) {
|
|
|
11137
11158
|
if (message.ok && message.language?.trim()) {
|
|
11138
11159
|
lastVoiceLanguageBySessionId.set(message.sessionId, message.language.trim());
|
|
11139
11160
|
}
|
|
11161
|
+
const text = message.message ?? (message.ok ? void 0 : localVoiceSwitchMessage(message.reason));
|
|
11140
11162
|
pending.resolve({
|
|
11141
11163
|
ok: message.ok,
|
|
11142
11164
|
reason: message.reason,
|
|
11165
|
+
...text ? { message: text } : {},
|
|
11143
11166
|
requestId: message.requestId,
|
|
11144
11167
|
...message.language ? { language: message.language } : {},
|
|
11145
11168
|
...message.voice ? { voice: message.voice } : {},
|
|
11146
11169
|
...message.stt ? { stt: message.stt } : {},
|
|
11147
11170
|
...message.scope ? { scope: message.scope } : {},
|
|
11148
|
-
...message.sttProvider ? { sttProvider: message.sttProvider } : {},
|
|
11149
|
-
...message.ttsProvider ? { ttsProvider: message.ttsProvider } : {}
|
|
11171
|
+
...message.sttProvider ? { sttProvider: toPublicProviderId(message.sttProvider) } : {},
|
|
11172
|
+
...message.ttsProvider ? { ttsProvider: toPublicProviderId(message.ttsProvider) } : {}
|
|
11150
11173
|
});
|
|
11151
11174
|
}
|
|
11152
11175
|
function handleVoiceLanguagePrepareResult(message) {
|
|
@@ -11155,10 +11178,12 @@ function handleVoiceLanguagePrepareResult(message) {
|
|
|
11155
11178
|
return;
|
|
11156
11179
|
clearTimeout(pending.timer);
|
|
11157
11180
|
pendingVoiceLanguagePrepares.delete(message.requestId);
|
|
11181
|
+
const text = message.message ?? (message.ok && message.ready ? void 0 : localVoiceSwitchMessage(message.reason));
|
|
11158
11182
|
pending.resolve({
|
|
11159
11183
|
ok: message.ok,
|
|
11160
11184
|
ready: message.ready,
|
|
11161
11185
|
reason: message.reason,
|
|
11186
|
+
...text ? { message: text } : {},
|
|
11162
11187
|
...message.language ? { language: message.language } : {}
|
|
11163
11188
|
});
|
|
11164
11189
|
}
|
|
@@ -6,6 +6,27 @@ const require = createRequire(import.meta.url);
|
|
|
6
6
|
import { randomUUID } from "node:crypto";
|
|
7
7
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8
8
|
|
|
9
|
+
// dist/voice-provider-id.js
|
|
10
|
+
function toPublicProviderId(id) {
|
|
11
|
+
const lower = id.trim().toLowerCase();
|
|
12
|
+
return lower === "local-sherpa" || lower === "cluster-sherpa" ? "voicethere" : id;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// dist/voice-request-validation.js
|
|
16
|
+
var VOICE_SWITCH_MESSAGES = {
|
|
17
|
+
invalid_scope: 'scope must be "stt", "tts" or "both".',
|
|
18
|
+
nothing_to_apply: "Pass sttVendor, ttsVendor or language.",
|
|
19
|
+
unknown_stt: 'No VoiceThere STT model matches sttVendor.model or the language; use a catalog id such as "en" or "en-small".',
|
|
20
|
+
unknown_voice: 'No VoiceThere voice matches ttsVendor.voice or the language; use a catalog id such as "en-lessac".',
|
|
21
|
+
invalid_language: 'language must be an ISO 639-1 code such as "en" or "de".',
|
|
22
|
+
language_unavailable: "The models for this language did not start; try again later or pick another language.",
|
|
23
|
+
unavailable: "Voice switching is not available for this session.",
|
|
24
|
+
timeout: "The voice switch did not finish in time; try again."
|
|
25
|
+
};
|
|
26
|
+
function localVoiceSwitchMessage(reason) {
|
|
27
|
+
return reason !== void 0 && Object.prototype.hasOwnProperty.call(VOICE_SWITCH_MESSAGES, reason) ? VOICE_SWITCH_MESSAGES[reason] : void 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
9
30
|
// dist/session-serial-queue.js
|
|
10
31
|
var SessionSerialQueueCancellationError = class extends Error {
|
|
11
32
|
sessionId;
|
|
@@ -382,16 +403,18 @@ function handleVoiceLanguageControlAck(message) {
|
|
|
382
403
|
if (message.ok && message.language?.trim()) {
|
|
383
404
|
lastVoiceLanguageBySessionId.set(message.sessionId, message.language.trim());
|
|
384
405
|
}
|
|
406
|
+
const text = message.message ?? (message.ok ? void 0 : localVoiceSwitchMessage(message.reason));
|
|
385
407
|
pending.resolve({
|
|
386
408
|
ok: message.ok,
|
|
387
409
|
reason: message.reason,
|
|
410
|
+
...text ? { message: text } : {},
|
|
388
411
|
requestId: message.requestId,
|
|
389
412
|
...message.language ? { language: message.language } : {},
|
|
390
413
|
...message.voice ? { voice: message.voice } : {},
|
|
391
414
|
...message.stt ? { stt: message.stt } : {},
|
|
392
415
|
...message.scope ? { scope: message.scope } : {},
|
|
393
|
-
...message.sttProvider ? { sttProvider: message.sttProvider } : {},
|
|
394
|
-
...message.ttsProvider ? { ttsProvider: message.ttsProvider } : {}
|
|
416
|
+
...message.sttProvider ? { sttProvider: toPublicProviderId(message.sttProvider) } : {},
|
|
417
|
+
...message.ttsProvider ? { ttsProvider: toPublicProviderId(message.ttsProvider) } : {}
|
|
395
418
|
});
|
|
396
419
|
}
|
|
397
420
|
function handleVoiceLanguagePrepareResult(message) {
|
|
@@ -400,10 +423,12 @@ function handleVoiceLanguagePrepareResult(message) {
|
|
|
400
423
|
return;
|
|
401
424
|
clearTimeout(pending.timer);
|
|
402
425
|
pendingVoiceLanguagePrepares.delete(message.requestId);
|
|
426
|
+
const text = message.message ?? (message.ok && message.ready ? void 0 : localVoiceSwitchMessage(message.reason));
|
|
403
427
|
pending.resolve({
|
|
404
428
|
ok: message.ok,
|
|
405
429
|
ready: message.ready,
|
|
406
430
|
reason: message.reason,
|
|
431
|
+
...text ? { message: text } : {},
|
|
407
432
|
...message.language ? { language: message.language } : {}
|
|
408
433
|
});
|
|
409
434
|
}
|
|
@@ -6,6 +6,27 @@ const require = createRequire(import.meta.url);
|
|
|
6
6
|
import { randomUUID } from "node:crypto";
|
|
7
7
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8
8
|
|
|
9
|
+
// dist/voice-provider-id.js
|
|
10
|
+
function toPublicProviderId(id) {
|
|
11
|
+
const lower = id.trim().toLowerCase();
|
|
12
|
+
return lower === "local-sherpa" || lower === "cluster-sherpa" ? "voicethere" : id;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// dist/voice-request-validation.js
|
|
16
|
+
var VOICE_SWITCH_MESSAGES = {
|
|
17
|
+
invalid_scope: 'scope must be "stt", "tts" or "both".',
|
|
18
|
+
nothing_to_apply: "Pass sttVendor, ttsVendor or language.",
|
|
19
|
+
unknown_stt: 'No VoiceThere STT model matches sttVendor.model or the language; use a catalog id such as "en" or "en-small".',
|
|
20
|
+
unknown_voice: 'No VoiceThere voice matches ttsVendor.voice or the language; use a catalog id such as "en-lessac".',
|
|
21
|
+
invalid_language: 'language must be an ISO 639-1 code such as "en" or "de".',
|
|
22
|
+
language_unavailable: "The models for this language did not start; try again later or pick another language.",
|
|
23
|
+
unavailable: "Voice switching is not available for this session.",
|
|
24
|
+
timeout: "The voice switch did not finish in time; try again."
|
|
25
|
+
};
|
|
26
|
+
function localVoiceSwitchMessage(reason) {
|
|
27
|
+
return reason !== void 0 && Object.prototype.hasOwnProperty.call(VOICE_SWITCH_MESSAGES, reason) ? VOICE_SWITCH_MESSAGES[reason] : void 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
9
30
|
// dist/session-serial-queue.js
|
|
10
31
|
var SessionSerialQueueCancellationError = class extends Error {
|
|
11
32
|
sessionId;
|
|
@@ -382,16 +403,18 @@ function handleVoiceLanguageControlAck(message) {
|
|
|
382
403
|
if (message.ok && message.language?.trim()) {
|
|
383
404
|
lastVoiceLanguageBySessionId.set(message.sessionId, message.language.trim());
|
|
384
405
|
}
|
|
406
|
+
const text = message.message ?? (message.ok ? void 0 : localVoiceSwitchMessage(message.reason));
|
|
385
407
|
pending.resolve({
|
|
386
408
|
ok: message.ok,
|
|
387
409
|
reason: message.reason,
|
|
410
|
+
...text ? { message: text } : {},
|
|
388
411
|
requestId: message.requestId,
|
|
389
412
|
...message.language ? { language: message.language } : {},
|
|
390
413
|
...message.voice ? { voice: message.voice } : {},
|
|
391
414
|
...message.stt ? { stt: message.stt } : {},
|
|
392
415
|
...message.scope ? { scope: message.scope } : {},
|
|
393
|
-
...message.sttProvider ? { sttProvider: message.sttProvider } : {},
|
|
394
|
-
...message.ttsProvider ? { ttsProvider: message.ttsProvider } : {}
|
|
416
|
+
...message.sttProvider ? { sttProvider: toPublicProviderId(message.sttProvider) } : {},
|
|
417
|
+
...message.ttsProvider ? { ttsProvider: toPublicProviderId(message.ttsProvider) } : {}
|
|
395
418
|
});
|
|
396
419
|
}
|
|
397
420
|
function handleVoiceLanguagePrepareResult(message) {
|
|
@@ -400,10 +423,12 @@ function handleVoiceLanguagePrepareResult(message) {
|
|
|
400
423
|
return;
|
|
401
424
|
clearTimeout(pending.timer);
|
|
402
425
|
pendingVoiceLanguagePrepares.delete(message.requestId);
|
|
426
|
+
const text = message.message ?? (message.ok && message.ready ? void 0 : localVoiceSwitchMessage(message.reason));
|
|
403
427
|
pending.resolve({
|
|
404
428
|
ok: message.ok,
|
|
405
429
|
ready: message.ready,
|
|
406
430
|
reason: message.reason,
|
|
431
|
+
...text ? { message: text } : {},
|
|
407
432
|
...message.language ? { language: message.language } : {}
|
|
408
433
|
});
|
|
409
434
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Id that goes on the wire to the VoiceThere runtime. `voicethere` (the
|
|
3
|
+
* built-in speech) and its deprecated aliases `local-sherpa` / `cluster-sherpa`
|
|
4
|
+
* all become `local-sherpa`, which every runtime version understands. Cloud ids
|
|
5
|
+
* are trimmed and keep their case.
|
|
6
|
+
*/
|
|
7
|
+
export declare function toWireProviderId(id: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Id that agent code sees. The runtime's internal ids for the built-in speech
|
|
10
|
+
* (`local-sherpa`, `cluster-sherpa`) are shown as `voicethere`; other ids are
|
|
11
|
+
* unchanged.
|
|
12
|
+
*/
|
|
13
|
+
export declare function toPublicProviderId(id: string): string;
|
|
14
|
+
//# sourceMappingURL=voice-provider-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voice-provider-id.d.ts","sourceRoot":"","sources":["../src/voice-provider-id.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAGnD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAKrD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const BUILT_IN_ALIASES = new Set([
|
|
2
|
+
"voicethere",
|
|
3
|
+
"local-sherpa",
|
|
4
|
+
"cluster-sherpa",
|
|
5
|
+
]);
|
|
6
|
+
/**
|
|
7
|
+
* Id that goes on the wire to the VoiceThere runtime. `voicethere` (the
|
|
8
|
+
* built-in speech) and its deprecated aliases `local-sherpa` / `cluster-sherpa`
|
|
9
|
+
* all become `local-sherpa`, which every runtime version understands. Cloud ids
|
|
10
|
+
* are trimmed and keep their case.
|
|
11
|
+
*/
|
|
12
|
+
export function toWireProviderId(id) {
|
|
13
|
+
const trimmed = id.trim();
|
|
14
|
+
return BUILT_IN_ALIASES.has(trimmed.toLowerCase()) ? "local-sherpa" : trimmed;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Id that agent code sees. The runtime's internal ids for the built-in speech
|
|
18
|
+
* (`local-sherpa`, `cluster-sherpa`) are shown as `voicethere`; other ids are
|
|
19
|
+
* unchanged.
|
|
20
|
+
*/
|
|
21
|
+
export function toPublicProviderId(id) {
|
|
22
|
+
const lower = id.trim().toLowerCase();
|
|
23
|
+
return lower === "local-sherpa" || lower === "cluster-sherpa"
|
|
24
|
+
? "voicethere"
|
|
25
|
+
: id;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=voice-provider-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voice-provider-id.js","sourceRoot":"","sources":["../src/voice-provider-id.ts"],"names":[],"mappings":"AAAA,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC;IAC/B,YAAY;IACZ,cAAc;IACd,gBAAgB;CACjB,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAAU;IACzC,MAAM,OAAO,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;IAC1B,OAAO,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC;AAChF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,EAAU;IAC3C,MAAM,KAAK,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACtC,OAAO,KAAK,KAAK,cAAc,IAAI,KAAK,KAAK,gBAAgB;QAC3D,CAAC,CAAC,YAAY;QACd,CAAC,CAAC,EAAE,CAAC;AACT,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type VoiceRequestValidation = {
|
|
2
|
+
ok: true;
|
|
3
|
+
} | {
|
|
4
|
+
ok: false;
|
|
5
|
+
reason: string;
|
|
6
|
+
message: string;
|
|
7
|
+
};
|
|
8
|
+
/** Texts for failures that older runtimes report as a bare `reason`. */
|
|
9
|
+
export declare const VOICE_SWITCH_MESSAGES: Readonly<Record<string, string>>;
|
|
10
|
+
/** Local text for a reason, or `undefined` when the runtime builds the text. */
|
|
11
|
+
export declare function localVoiceSwitchMessage(reason: string | undefined): string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Checks a `setVoiceLanguage` / `prepareVoiceLanguage` request before it is
|
|
14
|
+
* sent. The first failure wins. Provider ids are not checked here: the list of
|
|
15
|
+
* supported providers belongs to the runtime. The SDK-only `timeoutMs` option
|
|
16
|
+
* is ignored.
|
|
17
|
+
*/
|
|
18
|
+
export declare function validateVoiceRequest(options: unknown): VoiceRequestValidation;
|
|
19
|
+
//# sourceMappingURL=voice-request-validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voice-request-validation.d.ts","sourceRoot":"","sources":["../src/voice-request-validation.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,sBAAsB,GAChC;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhE,wEAAwE;AACxE,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAYlE,CAAC;AAEF,gFAAgF;AAChF,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,MAAM,GAAG,SAAS,CAKpB;AAgCD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,sBAAsB,CAgG7E"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { toWireProviderId } from "./voice-provider-id.js";
|
|
2
|
+
/** Texts for failures that older runtimes report as a bare `reason`. */
|
|
3
|
+
export const VOICE_SWITCH_MESSAGES = {
|
|
4
|
+
invalid_scope: 'scope must be "stt", "tts" or "both".',
|
|
5
|
+
nothing_to_apply: "Pass sttVendor, ttsVendor or language.",
|
|
6
|
+
unknown_stt: 'No VoiceThere STT model matches sttVendor.model or the language; use a catalog id such as "en" or "en-small".',
|
|
7
|
+
unknown_voice: 'No VoiceThere voice matches ttsVendor.voice or the language; use a catalog id such as "en-lessac".',
|
|
8
|
+
invalid_language: 'language must be an ISO 639-1 code such as "en" or "de".',
|
|
9
|
+
language_unavailable: "The models for this language did not start; try again later or pick another language.",
|
|
10
|
+
unavailable: "Voice switching is not available for this session.",
|
|
11
|
+
timeout: "The voice switch did not finish in time; try again.",
|
|
12
|
+
};
|
|
13
|
+
/** Local text for a reason, or `undefined` when the runtime builds the text. */
|
|
14
|
+
export function localVoiceSwitchMessage(reason) {
|
|
15
|
+
return reason !== undefined &&
|
|
16
|
+
Object.prototype.hasOwnProperty.call(VOICE_SWITCH_MESSAGES, reason)
|
|
17
|
+
? VOICE_SWITCH_MESSAGES[reason]
|
|
18
|
+
: undefined;
|
|
19
|
+
}
|
|
20
|
+
const INVALID_REQUEST = "setVoiceLanguage options must be an object; language, scope, voice and stt are strings; sttVendor and ttsVendor are objects.";
|
|
21
|
+
function isPlainObject(value) {
|
|
22
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23
|
+
}
|
|
24
|
+
function isAbsentOrString(value) {
|
|
25
|
+
return value === undefined || typeof value === "string";
|
|
26
|
+
}
|
|
27
|
+
function nonEmpty(value) {
|
|
28
|
+
return typeof value === "string" && value.trim() !== "";
|
|
29
|
+
}
|
|
30
|
+
function fail(reason, message) {
|
|
31
|
+
return { ok: false, reason, message };
|
|
32
|
+
}
|
|
33
|
+
function vendorShapeOk(vendor) {
|
|
34
|
+
if (vendor === undefined)
|
|
35
|
+
return true;
|
|
36
|
+
if (!isPlainObject(vendor))
|
|
37
|
+
return false;
|
|
38
|
+
return (isAbsentOrString(vendor.provider) &&
|
|
39
|
+
isAbsentOrString(vendor.model) &&
|
|
40
|
+
isAbsentOrString(vendor.voice) &&
|
|
41
|
+
isAbsentOrString(vendor.language));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Checks a `setVoiceLanguage` / `prepareVoiceLanguage` request before it is
|
|
45
|
+
* sent. The first failure wins. Provider ids are not checked here: the list of
|
|
46
|
+
* supported providers belongs to the runtime. The SDK-only `timeoutMs` option
|
|
47
|
+
* is ignored.
|
|
48
|
+
*/
|
|
49
|
+
export function validateVoiceRequest(options) {
|
|
50
|
+
if (!isPlainObject(options))
|
|
51
|
+
return fail("invalid_request", INVALID_REQUEST);
|
|
52
|
+
const { language, scope, voice, stt, sttVendor, ttsVendor } = options;
|
|
53
|
+
// 1. shape
|
|
54
|
+
if (!isAbsentOrString(language) ||
|
|
55
|
+
!isAbsentOrString(scope) ||
|
|
56
|
+
!isAbsentOrString(voice) ||
|
|
57
|
+
!isAbsentOrString(stt) ||
|
|
58
|
+
!vendorShapeOk(sttVendor) ||
|
|
59
|
+
!vendorShapeOk(ttsVendor)) {
|
|
60
|
+
return fail("invalid_request", INVALID_REQUEST);
|
|
61
|
+
}
|
|
62
|
+
// 2. scope
|
|
63
|
+
if (nonEmpty(scope) &&
|
|
64
|
+
!["stt", "tts", "both"].includes(scope.trim())) {
|
|
65
|
+
return fail("invalid_scope", VOICE_SWITCH_MESSAGES.invalid_scope);
|
|
66
|
+
}
|
|
67
|
+
const stv = sttVendor;
|
|
68
|
+
const ttv = ttsVendor;
|
|
69
|
+
// 3. provider required
|
|
70
|
+
if (stv && !nonEmpty(stv.provider)) {
|
|
71
|
+
return fail("missing_provider", "sttVendor.provider is required.");
|
|
72
|
+
}
|
|
73
|
+
if (ttv && !nonEmpty(ttv.provider)) {
|
|
74
|
+
return fail("missing_provider", "ttsVendor.provider is required.");
|
|
75
|
+
}
|
|
76
|
+
// 4, 5. deprecated fields next to a vendor object
|
|
77
|
+
if (nonEmpty(stt) && stv) {
|
|
78
|
+
return fail("conflicting_fields", "Pass the STT model as sttVendor.model, not stt, when sttVendor is set.");
|
|
79
|
+
}
|
|
80
|
+
if (nonEmpty(voice) && ttv) {
|
|
81
|
+
return fail("conflicting_fields", "Pass the voice as ttsVendor.voice, not voice, when ttsVendor is set.");
|
|
82
|
+
}
|
|
83
|
+
// 6. scope against vendor objects
|
|
84
|
+
const effectiveScope = nonEmpty(scope) ? scope.trim() : undefined;
|
|
85
|
+
if (effectiveScope === "tts" && stv) {
|
|
86
|
+
return fail("scope_mismatch", 'scope "tts" cannot change sttVendor; use scope "both" or drop sttVendor.');
|
|
87
|
+
}
|
|
88
|
+
if (effectiveScope === "stt" && ttv) {
|
|
89
|
+
return fail("scope_mismatch", 'scope "stt" cannot change ttsVendor; use scope "both" or drop ttsVendor.');
|
|
90
|
+
}
|
|
91
|
+
// 7. STT has no voice
|
|
92
|
+
if (stv && nonEmpty(stv.voice)) {
|
|
93
|
+
return fail("unsupported_field", "sttVendor has no voice field; set the voice with ttsVendor.voice.");
|
|
94
|
+
}
|
|
95
|
+
// 10. language on a cloud TTS vendor
|
|
96
|
+
if (ttv &&
|
|
97
|
+
nonEmpty(ttv.language) &&
|
|
98
|
+
toWireProviderId(ttv.provider) !== "local-sherpa") {
|
|
99
|
+
return fail("unsupported_field", 'ttsVendor.language only applies to provider "voicethere"; choose a voice for that language with ttsVendor.voice.');
|
|
100
|
+
}
|
|
101
|
+
// 11. nothing to do
|
|
102
|
+
if (!nonEmpty(language) &&
|
|
103
|
+
!nonEmpty(voice) &&
|
|
104
|
+
!nonEmpty(stt) &&
|
|
105
|
+
!stv &&
|
|
106
|
+
!ttv) {
|
|
107
|
+
return fail("nothing_to_apply", VOICE_SWITCH_MESSAGES.nothing_to_apply);
|
|
108
|
+
}
|
|
109
|
+
return { ok: true };
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=voice-request-validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voice-request-validation.js","sourceRoot":"","sources":["../src/voice-request-validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAK1D,wEAAwE;AACxE,MAAM,CAAC,MAAM,qBAAqB,GAAqC;IACrE,aAAa,EAAE,uCAAuC;IACtD,gBAAgB,EAAE,wCAAwC;IAC1D,WAAW,EACT,+GAA+G;IACjH,aAAa,EACX,oGAAoG;IACtG,gBAAgB,EAAE,0DAA0D;IAC5E,oBAAoB,EAClB,uFAAuF;IACzF,WAAW,EAAE,oDAAoD;IACjE,OAAO,EAAE,qDAAqD;CAC/D,CAAC;AAEF,gFAAgF;AAChF,MAAM,UAAU,uBAAuB,CACrC,MAA0B;IAE1B,OAAO,MAAM,KAAK,SAAS;QACzB,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,qBAAqB,EAAE,MAAM,CAAC;QACnE,CAAC,CAAC,qBAAqB,CAAC,MAAM,CAAC;QAC/B,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,MAAM,eAAe,GACnB,8HAA8H,CAAC;AAEjI,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK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AAI,CACT,gBAAgB,EAChB,0EAA0E,CAC3E,CAAC;IACJ,CAAC;IACD,IAAI,cAAc,KAAK,KAAK,IAAI,GAAG,EAAE,CAAC;QACpC,OAAO,IAAI,CACT,gBAAgB,EAChB,0EAA0E,CAC3E,CAAC;IACJ,CAAC;IAED,sBAAsB;IACtB,IAAI,GAAG,IAAI,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO,IAAI,CACT,mBAAmB,EACnB,mEAAmE,CACpE,CAAC;IACJ,CAAC;IAED,qCAAqC;IACrC,IACE,GAAG;QACH,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC;QACtB,gBAAgB,CAAC,GAAG,CAAC,QAAkB,CAAC,KAAK,cAAc,EAC3D,CAAC;QACD,OAAO,IAAI,CACT,mBAAmB,EACnB,kHAAkH,CACnH,CAAC;IACJ,CAAC;IAED,oBAAoB;IACpB,IACE,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACnB,CAAC,QAAQ,CAAC,KAAK,CAAC;QAChB,CAAC,QAAQ,CAAC,GAAG,CAAC;QACd,CAAC,GAAG;QACJ,CAAC,GAAG,EACJ,CAAC;QACD,OAAO,IAAI,CAAC,kBAAkB,EAAE,qBAAqB,CAAC,gBAAiB,CAAC,CAAC;IAC3E,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AACtB,CAAC"}
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@ When the switch took at least `readyMessageMinMs` (default 2000) and no wait mes
|
|
|
16
16
|
|
|
17
17
|
The swap waits until the holding message has finished playing (at most 8 seconds). If the language is detected after the caller's last final is already unanswered, that final is the switch utterance and the switch starts at once. If prepare or the swap fails for any other reason, the agent speaks a short fallback in the old language and stays. If only the replay fails, the voice is already the new one, so the agent asks the caller in the new language to repeat (`REPEAT_MESSAGES`) and stays in it. A second language event during a switch is ignored.
|
|
18
18
|
|
|
19
|
-
The built-in speech vendor is VoiceThere (id `
|
|
19
|
+
The built-in speech vendor is VoiceThere (id `voicethere`). Edit `PROFILES` in `agent.ts` to apply other vendors per target language, for example Deepgram for listening and ElevenLabs for speaking; the file has a commented example. Keys stay in project secrets.
|
|
20
20
|
|
|
21
21
|
Texts, in order of precedence: the env override, the project settings (`waitMessages`, `readyMessages`), then the maps in `agent.ts` (`HOLDING_MESSAGES`, `READY_MESSAGES`, `FAILED_MESSAGES`, `UNAVAILABLE_MESSAGES`; en, de, es, fr, it, pt, nl, pl, ru, except the ready and unavailable maps, which have no ru). `WAIT_MESSAGES` is kept as another name for `HOLDING_MESSAGES`. In a holding message, `{language}` is replaced by the target language's name, written in the language being left (`Intl.DisplayNames`), so project texts and the env override can use it too. Override per language with a JSON object in the session env, keyed by ISO 639-1 code:
|
|
22
22
|
|
|
@@ -40,13 +40,13 @@ Detection and chat commands are unchanged: `/tts` and `/stt` still call `setVoic
|
|
|
40
40
|
|
|
41
41
|
Chat commands change one vendor while the session stays connected. API keys are project secrets on the running deploy, not arguments:
|
|
42
42
|
|
|
43
|
-
- `/tts
|
|
44
|
-
- `/stt
|
|
43
|
+
- `/tts voicethere de` — VoiceThere TTS only (`sherpa` also works)
|
|
44
|
+
- `/stt voicethere de` — VoiceThere STT only (`sherpa` also works)
|
|
45
45
|
- `/tts elevenlabs` — ElevenLabs TTS, current STT stays
|
|
46
46
|
- `/stt deepgram de` — Deepgram STT, current voice stays
|
|
47
47
|
|
|
48
48
|
In manual mode, finals are echoed as `you said: …` (in the current language) after a short wait, so a language event for the same utterance can cancel the echo. The switch utterance is not spoken back as an English transcript; its replay is answered in the new language.
|
|
49
49
|
|
|
50
|
-
`
|
|
50
|
+
The default profile asks for VoiceThere speech on both sides: `sttVendor: { provider: "voicethere", language }` and `ttsVendor: { provider: "voicethere", language }`. To pick a specific model or voice, set `sttVendor.model` (`de`, `en-small`) or `ttsVendor.voice` (`en-lessac`); the ids are listed in the spoken-language docs. Other vendor ids are `openai`, `deepgram`, `assemblyai`, `google`, `elevenlabs`, `cartesia`, `fishaudio`, `groq`, `azure`, and `aws`. A failed switch carries a `reason` and a `message` that says what to change.
|
|
51
51
|
|
|
52
52
|
Entry: `templates/language-switch/agent.ts`.
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* FAILED_MESSAGES / UNAVAILABLE_MESSAGES, and env vars
|
|
28
28
|
* LANGUAGE_SWITCH_WAIT_MESSAGES_JSON / LANGUAGE_SWITCH_FAILED_MESSAGES_JSON /
|
|
29
29
|
* LANGUAGE_SWITCH_UNAVAILABLE_MESSAGES_JSON (JSON object, ISO 639-1 ->
|
|
30
|
-
* text) win. The built-in vendor is VoiceThere (id `
|
|
30
|
+
* text) win. The built-in vendor is VoiceThere (id `voicethere`); edit
|
|
31
31
|
* PROFILES to use other vendors.
|
|
32
32
|
* (B) Project enables runner auto-switch — STT/TTS are runner-owned. The
|
|
33
33
|
* runner replays the utterance into the new language's STT, so the next
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
*
|
|
41
41
|
* Chat commands change a single vendor mid-conversation:
|
|
42
42
|
*
|
|
43
|
-
* - `/tts
|
|
44
|
-
* - `/stt
|
|
43
|
+
* - `/tts voicethere de` — VoiceThere TTS only (`sherpa` also works)
|
|
44
|
+
* - `/stt voicethere de` — VoiceThere STT only (`sherpa` also works)
|
|
45
45
|
* - `/tts elevenlabs` — ElevenLabs TTS, current STT stays
|
|
46
46
|
* - `/stt deepgram de` — Deepgram STT, current voice stays
|
|
47
47
|
*
|
|
@@ -65,7 +65,7 @@ import {
|
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* What to apply per target language. The default is the built-in VoiceThere
|
|
68
|
-
* vendor (`
|
|
68
|
+
* vendor (`voicethere`): voice and STT model chosen for the language. A
|
|
69
69
|
* profile can name other vendors; keys stay in project secrets. Example:
|
|
70
70
|
*
|
|
71
71
|
* de: {
|
|
@@ -82,8 +82,8 @@ export function profileFor(language: string): SetVoiceLanguageOptions {
|
|
|
82
82
|
PROFILES[language] ?? {
|
|
83
83
|
scope: "both",
|
|
84
84
|
language,
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
sttVendor: { provider: "voicethere", language },
|
|
86
|
+
ttsVendor: { provider: "voicethere", language },
|
|
87
87
|
}
|
|
88
88
|
);
|
|
89
89
|
}
|
|
@@ -324,7 +324,7 @@ function logSwitch(
|
|
|
324
324
|
if (!result.ok) {
|
|
325
325
|
agentLog(
|
|
326
326
|
"warn",
|
|
327
|
-
`setVoiceLanguage ${side} failed: ${result.reason ?? "unknown"}`,
|
|
327
|
+
`setVoiceLanguage ${side} failed: ${result.reason ?? "unknown"}${result.message ? ` - ${result.message}` : ""}`,
|
|
328
328
|
);
|
|
329
329
|
return;
|
|
330
330
|
}
|
|
@@ -832,21 +832,22 @@ defineAgent({
|
|
|
832
832
|
const text = parseChatText(ctx.message);
|
|
833
833
|
if (!text) return;
|
|
834
834
|
const [command, vendor, language] = text.trim().split(/\s+/);
|
|
835
|
-
|
|
835
|
+
const builtIn = vendor === "voicethere" || vendor === "sherpa";
|
|
836
|
+
if (command === "/tts" && builtIn && language) {
|
|
836
837
|
const result = await setVoiceLanguage(ctx.sessionId, {
|
|
837
838
|
scope: "tts",
|
|
838
839
|
language,
|
|
839
|
-
ttsVendor: { provider: "
|
|
840
|
+
ttsVendor: { provider: "voicethere", language },
|
|
840
841
|
});
|
|
841
842
|
logSwitch(ctx.sessionId, "tts", result);
|
|
842
843
|
if (result.ok) speak(ctx.sessionId, replyFor(language));
|
|
843
844
|
return;
|
|
844
845
|
}
|
|
845
|
-
if (command === "/stt" &&
|
|
846
|
+
if (command === "/stt" && builtIn && language) {
|
|
846
847
|
const result = await setVoiceLanguage(ctx.sessionId, {
|
|
847
848
|
scope: "stt",
|
|
848
849
|
language,
|
|
849
|
-
sttVendor: { provider: "
|
|
850
|
+
sttVendor: { provider: "voicethere", language },
|
|
850
851
|
});
|
|
851
852
|
logSwitch(ctx.sessionId, "stt", result);
|
|
852
853
|
return;
|
|
@@ -179,8 +179,11 @@ defineAgent({
|
|
|
179
179
|
},
|
|
180
180
|
|
|
181
181
|
onUserLanguage({ sessionId, language }) {
|
|
182
|
-
// Detection does not change TTS or STT. Call setVoiceLanguage
|
|
183
|
-
// scope "
|
|
182
|
+
// Detection does not change TTS or STT. Call setVoiceLanguage, for example
|
|
183
|
+
// { scope: "both", language,
|
|
184
|
+
// sttVendor: { provider: "voicethere", language },
|
|
185
|
+
// ttsVendor: { provider: "voicethere", language } }
|
|
186
|
+
// or name another provider (deepgram, elevenlabs, ...) per side.
|
|
184
187
|
// See templates/language-switch/agent.ts.
|
|
185
188
|
agentLog("info", `user_language ${sessionId} ${language}`);
|
|
186
189
|
},
|