@absolutejs/voice 0.0.22-beta.575 → 0.0.22-beta.576
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/dist/core/cachedTTS.d.ts +26 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +26 -4
- package/package.json +1 -1
package/dist/core/cachedTTS.d.ts
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
import type { TTSAdapter, TTSAdapterOpenOptions } from "./types";
|
|
1
|
+
import type { TTSAdapter, TTSAdapterOpenOptions, TTSAudioEvent } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Optional persistent backing store for the cache — an L2 behind the in-memory
|
|
4
|
+
* LRU. Lets rendered audio survive process restarts/deploys so a fixed prompt
|
|
5
|
+
* (e.g. a greeting) is synthesized once *ever* per content key, not once per
|
|
6
|
+
* process. The store is content-addressed by the same `keyFor` key, so a
|
|
7
|
+
* changed prompt/voice/model naturally lands on a new key and re-renders.
|
|
8
|
+
*
|
|
9
|
+
* The store is told `TTSAudioEvent[]` and must return the same on read; how it
|
|
10
|
+
* serializes the binary `chunk`s (base64 in JSON, bytea, a file, etc.) is up to
|
|
11
|
+
* the implementation. `get` returns `null`/`undefined` on a miss. Both may be
|
|
12
|
+
* sync or async; errors should be swallowed by the implementation (a store
|
|
13
|
+
* failure must never break playback — the wrapper falls back to live render).
|
|
14
|
+
*/
|
|
15
|
+
export type CachedTTSStore = {
|
|
16
|
+
get: (key: string) => Promise<TTSAudioEvent[] | null | undefined> | TTSAudioEvent[] | null | undefined;
|
|
17
|
+
set: (key: string, events: TTSAudioEvent[]) => Promise<void> | void;
|
|
18
|
+
};
|
|
2
19
|
export type CachedTTSOptions = {
|
|
3
20
|
/**
|
|
4
21
|
* Return a stable cache key for an utterance whose synthesized audio should
|
|
@@ -13,8 +30,15 @@ export type CachedTTSOptions = {
|
|
|
13
30
|
* (and re-caches) while the old entry is simply orphaned.
|
|
14
31
|
*/
|
|
15
32
|
keyFor: (text: string, openOptions: TTSAdapterOpenOptions) => string | null | undefined;
|
|
16
|
-
/** Max distinct utterances to retain (LRU by insertion). Default 32. */
|
|
33
|
+
/** Max distinct utterances to retain in memory (LRU by insertion). Default 32. */
|
|
17
34
|
maxEntries?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Optional persistent L2 store (see {@link CachedTTSStore}). When set, an
|
|
37
|
+
* in-memory miss consults the store before rendering; a store hit is replayed
|
|
38
|
+
* and promoted into memory, and a fresh render is written through to it. Omit
|
|
39
|
+
* for memory-only behaviour (unchanged).
|
|
40
|
+
*/
|
|
41
|
+
store?: CachedTTSStore;
|
|
18
42
|
};
|
|
19
43
|
/**
|
|
20
44
|
* Wrap a TTS adapter so selected utterances are synthesized once and replayed
|
package/dist/index.d.ts
CHANGED
|
@@ -223,7 +223,7 @@ export type { VoiceSimulationSuiteAssertionInput, VoiceSimulationSuiteAssertionR
|
|
|
223
223
|
export type { VoiceWorkflowContract, VoiceWorkflowContractDefinition, VoiceWorkflowContractField, VoiceWorkflowContractFieldMatch, VoiceWorkflowContractPresetName, VoiceWorkflowContractPresetOptions, VoiceWorkflowContractTracePayload, VoiceWorkflowContractValidation, VoiceWorkflowContractValidationIssue, VoiceWorkflowOutcome, } from "./core/workflowContract";
|
|
224
224
|
export type { VoiceSessionListHTMLHandlerOptions, VoiceSessionListItem, VoiceSessionListOptions, VoiceSessionListRoutesOptions, VoiceSessionListStatus, VoiceProviderFallbackRecoverySummary, VoiceSessionReplay, VoiceSessionReplayHTMLHandlerOptions, VoiceSessionReplayOptions, VoiceSessionReplayRoutesOptions, VoiceSessionReplayTurn, } from "./core/sessionReplay";
|
|
225
225
|
export type { AnthropicVoiceAssistantModelOptions, GeminiVoiceAssistantModelOptions, OpenAIVoiceAssistantModelOptions, VoiceProviderRouterEvent, VoiceProviderRouterFallbackMode, VoiceProviderRouterHealthOptions, VoiceProviderRouterOptions, VoiceProviderOrchestrationProfile, VoiceProviderOrchestrationProfileOptions, VoiceProviderOrchestrationResolvedSurface, VoiceProviderOrchestrationSurface, VoiceProviderRouterPolicy, VoiceProviderRouterPolicyPreset, VoiceProviderRouterPolicyWeights, VoiceProviderRouterProviderHealth, VoiceProviderRouterProviderProfile, VoiceProviderRouterStrategy, VoiceJSONAssistantModelHandler, VoiceJSONAssistantModelOptions, } from "./core/modelAdapters";
|
|
226
|
-
export type { CachedTTSOptions } from "./core/cachedTTS";
|
|
226
|
+
export type { CachedTTSOptions, CachedTTSStore } from "./core/cachedTTS";
|
|
227
227
|
export type { OpenAIVoiceTTSOptions, OpenAIVoiceTTSVoice, } from "./core/openaiTTS";
|
|
228
228
|
export type { VoiceProviderHealthStatus, VoiceProviderHealthSummary, VoiceProviderHealthSummaryOptions, } from "./core/providerHealth";
|
|
229
229
|
export type { VoiceProviderCapabilityDefinition, VoiceProviderCapabilityHandlerOptions, VoiceProviderCapabilityHTMLHandlerOptions, VoiceProviderCapabilityKind, VoiceProviderCapabilityOptions, VoiceProviderCapabilityReport, VoiceProviderCapabilityRoutesOptions, VoiceProviderCapabilitySummary, } from "./core/providerCapabilities";
|
package/dist/index.js
CHANGED
|
@@ -45566,6 +45566,7 @@ var createGeminiVoiceAssistantModel = (options) => {
|
|
|
45566
45566
|
var DEFAULT_MAX_ENTRIES = 32;
|
|
45567
45567
|
var createCachedTTS = (inner, options) => {
|
|
45568
45568
|
const maxEntries = options.maxEntries ?? DEFAULT_MAX_ENTRIES;
|
|
45569
|
+
const { store } = options;
|
|
45569
45570
|
const cache = new Map;
|
|
45570
45571
|
const remember = (key, events) => {
|
|
45571
45572
|
cache.delete(key);
|
|
@@ -45578,6 +45579,18 @@ var createCachedTTS = (inner, options) => {
|
|
|
45578
45579
|
cache.delete(oldest);
|
|
45579
45580
|
}
|
|
45580
45581
|
};
|
|
45582
|
+
const loadFromStore = async (key) => {
|
|
45583
|
+
if (!store)
|
|
45584
|
+
return null;
|
|
45585
|
+
try {
|
|
45586
|
+
const events = await store.get(key);
|
|
45587
|
+
if (events && events.length > 0) {
|
|
45588
|
+
remember(key, events);
|
|
45589
|
+
return events;
|
|
45590
|
+
}
|
|
45591
|
+
} catch {}
|
|
45592
|
+
return null;
|
|
45593
|
+
};
|
|
45581
45594
|
return {
|
|
45582
45595
|
kind: "tts",
|
|
45583
45596
|
open: async (openOptions) => {
|
|
@@ -45608,9 +45621,8 @@ var createCachedTTS = (inner, options) => {
|
|
|
45608
45621
|
await session.send(text);
|
|
45609
45622
|
return;
|
|
45610
45623
|
}
|
|
45611
|
-
const
|
|
45612
|
-
|
|
45613
|
-
for (const event of cached) {
|
|
45624
|
+
const replayEvents = async (events) => {
|
|
45625
|
+
for (const event of events) {
|
|
45614
45626
|
const replay = {
|
|
45615
45627
|
...event,
|
|
45616
45628
|
receivedAt: Date.now()
|
|
@@ -45619,12 +45631,22 @@ var createCachedTTS = (inner, options) => {
|
|
|
45619
45631
|
await Promise.resolve(handler(replay));
|
|
45620
45632
|
}
|
|
45621
45633
|
}
|
|
45634
|
+
};
|
|
45635
|
+
const cached = cache.get(key) ?? await loadFromStore(key);
|
|
45636
|
+
if (cached) {
|
|
45637
|
+
await replayEvents(cached);
|
|
45622
45638
|
return;
|
|
45623
45639
|
}
|
|
45624
45640
|
capture = [];
|
|
45625
45641
|
await session.send(text);
|
|
45626
|
-
|
|
45642
|
+
const rendered = capture;
|
|
45643
|
+
remember(key, rendered);
|
|
45627
45644
|
capture = null;
|
|
45645
|
+
if (store) {
|
|
45646
|
+
try {
|
|
45647
|
+
await store.set(key, rendered);
|
|
45648
|
+
} catch {}
|
|
45649
|
+
}
|
|
45628
45650
|
}
|
|
45629
45651
|
};
|
|
45630
45652
|
}
|