@pie-players/pie-section-player 0.3.19 → 0.3.21
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/components/shared/player-preload.d.ts +3 -1
- package/dist/components/shared/player-preload.d.ts.map +1 -1
- package/dist/components/shared/section-player-view-state.d.ts.map +1 -1
- package/dist/defineProperty-CyepwRr5-eHUSgEtz.js +33 -0
- package/dist/defineProperty-CyepwRr5.js +33 -0
- package/dist/dist-Bud4G4lv-DvJKILlA.js +407 -0
- package/dist/dist-C2B1t0Ov.js +411 -0
- package/dist/dist-DwP27yIs-gkxodgFn.js +201 -0
- package/dist/{index-QLtHZ4Yz-B0r-CUMY.js → dist-S3IAfazl.js} +36 -64
- package/dist/{index-BZq66Ke6-D8dZwpj4.js → module-COIydQYl-2o-TlgiW.js} +38152 -30086
- package/dist/pie-section-player.js +7129 -9320
- package/dist/player-preload-DHibXasK.js +6461 -0
- package/dist/tool-annotation-toolbar-BPFElcYO.js +3977 -0
- package/dist/utils/player-preload.js +5 -5
- package/package.json +14 -14
- package/dist/index-BRKsQ6Im-_GY8ip1I.js +0 -442
- package/dist/index-BRKsQ6Im.js +0 -460
- package/dist/index-QLtHZ4Yz.js +0 -244
- package/dist/player-preload-DGzat3U_.js +0 -7040
- package/dist/tool-annotation-toolbar-BCBoCQa5.js +0 -4930
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { ItemEntity } from '@pie-players/pie-players-shared';
|
|
1
|
+
import { BundleType, ItemEntity } from '@pie-players/pie-players-shared';
|
|
2
2
|
export declare const PRELOAD_TIMEOUT_MS = 15000;
|
|
3
3
|
export declare function getRenderablesSignature(renderables: unknown[]): string;
|
|
4
4
|
export declare function getLoaderView(env: Record<string, unknown>): "author" | "delivery";
|
|
5
5
|
export declare function buildPreloadSignature(args: {
|
|
6
6
|
strategy: string;
|
|
7
|
+
iifeBundleType: BundleType | null;
|
|
7
8
|
loaderView: string;
|
|
8
9
|
esmCdnUrl: string;
|
|
9
10
|
moduleResolution: "url" | "import-map";
|
|
@@ -13,6 +14,7 @@ export declare function buildPreloadSignature(args: {
|
|
|
13
14
|
export declare function preloadPlayerElements(args: {
|
|
14
15
|
strategy: string;
|
|
15
16
|
renderables: ItemEntity[];
|
|
17
|
+
iifeBundleType: BundleType | null;
|
|
16
18
|
loaderView: "author" | "delivery";
|
|
17
19
|
esmCdnUrl: string;
|
|
18
20
|
moduleResolution: "url" | "import-map";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"player-preload.d.ts","sourceRoot":"","sources":["../../../src/components/shared/player-preload.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"player-preload.d.ts","sourceRoot":"","sources":["../../../src/components/shared/player-preload.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,UAAU,EAGV,KAAK,UAAU,EAGf,MAAM,iCAAiC,CAAC;AAGzC,eAAO,MAAM,kBAAkB,QAAQ,CAAC;AAMxC,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,OAAO,EAAE,GAAG,MAAM,CAoCtE;AAED,wBAAgB,aAAa,CAC5B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC1B,QAAQ,GAAG,UAAU,CAEvB;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,UAAU,GAAG,IAAI,CAAC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,KAAK,GAAG,YAAY,CAAC;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,oBAAoB,EAAE,MAAM,CAAC;CAC7B,UAUA;AAED,wBAAsB,qBAAqB,CAAC,IAAI,EAAE;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,cAAc,EAAE,UAAU,GAAG,IAAI,CAAC;IAClC,UAAU,EAAE,QAAQ,GAAG,UAAU,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,KAAK,GAAG,YAAY,CAAC;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkChB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAChC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,wBAAgB,8BAA8B,CAAC,IAAI,EAAE;IACpD,uBAAuB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,iBAAiB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CAC5C,IACQ,MAAM,OAAO,CAAC,kBAAkB,CAAC,UAWzC;AAED,wBAAgB,+BAA+B,CAAC,IAAI,EAAE;IACrD,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,EAAE,MAAM,kBAAkB,CAAC;IACnC,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC;CACtD,QAsFA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"section-player-view-state.d.ts","sourceRoot":"","sources":["../../../src/components/shared/section-player-view-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAM1E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAI9D,MAAM,MAAM,yBAAyB,GAAG;IACvC,gBAAgB,EAAE,uBAAuB,CAAC;IAC1C,QAAQ,EAAE,uBAAuB,CAAC,UAAU,CAAC,CAAC;IAC9C,KAAK,EAAE,uBAAuB,CAAC,OAAO,CAAC,CAAC;IACxC,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,oBAAoB,EAAE,MAAM,CAAC;CAC7B,CAAC;
|
|
1
|
+
{"version":3,"file":"section-player-view-state.d.ts","sourceRoot":"","sources":["../../../src/components/shared/section-player-view-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAM1E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAI9D,MAAM,MAAM,yBAAyB,GAAG;IACvC,gBAAgB,EAAE,uBAAuB,CAAC;IAC1C,QAAQ,EAAE,uBAAuB,CAAC,UAAU,CAAC,CAAC;IAC9C,KAAK,EAAE,uBAAuB,CAAC,OAAO,CAAC,CAAC;IACxC,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,oBAAoB,EAAE,MAAM,CAAC;CAC7B,CAAC;AAMF,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,KAAK,GAAG,uBAAuB,CAI7E;AAED,wBAAgB,+BAA+B,CAC9C,gBAAgB,EAAE,uBAAuB,GACvC,yBAAyB,CAS3B;AAED,wBAAgB,+BAA+B,CAC9C,KAAK,EAAE,KAAK,GACV,yBAAyB,CAE3B;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAC5C,OAAO,EAAE,GAAG,CAAC;IACb,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,cAAc,EAAE,MAAM,CAAC;CACvB,GAAG,mBAAmB,CAatB;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IACzC,IAAI,EAAE,UAAU,CAAC;IACjB,gBAAgB,EAAE,uBAAuB,CAAC;IAC1C,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,cAAc,EAAE,MAAM,CAAC;CACvB,GAAG,mBAAmB,CAYtB;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACxC,gBAAgB,EAAE,uBAAuB,CAAC;IAC1C,IAAI,EAAE,UAAU,CAAC;CACjB,GAAG,MAAM,CAET"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function e(t) {
|
|
2
|
+
"@babel/helpers - typeof";
|
|
3
|
+
return e = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(r) {
|
|
4
|
+
return typeof r;
|
|
5
|
+
} : function(r) {
|
|
6
|
+
return r && typeof Symbol == "function" && r.constructor === Symbol && r !== Symbol.prototype ? "symbol" : typeof r;
|
|
7
|
+
}, e(t);
|
|
8
|
+
}
|
|
9
|
+
function i(t, r) {
|
|
10
|
+
if (e(t) != "object" || !t) return t;
|
|
11
|
+
var o = t[Symbol.toPrimitive];
|
|
12
|
+
if (o !== void 0) {
|
|
13
|
+
var n = o.call(t, r || "default");
|
|
14
|
+
if (e(n) != "object") return n;
|
|
15
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
16
|
+
}
|
|
17
|
+
return (r === "string" ? String : Number)(t);
|
|
18
|
+
}
|
|
19
|
+
function u(t) {
|
|
20
|
+
var r = i(t, "string");
|
|
21
|
+
return e(r) == "symbol" ? r : r + "";
|
|
22
|
+
}
|
|
23
|
+
function f(t, r, o) {
|
|
24
|
+
return (r = u(r)) in t ? Object.defineProperty(t, r, {
|
|
25
|
+
value: o,
|
|
26
|
+
enumerable: !0,
|
|
27
|
+
configurable: !0,
|
|
28
|
+
writable: !0
|
|
29
|
+
}) : t[r] = o, t;
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
f as t
|
|
33
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function o(e) {
|
|
2
|
+
"@babel/helpers - typeof";
|
|
3
|
+
return o = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(t) {
|
|
4
|
+
return typeof t;
|
|
5
|
+
} : function(t) {
|
|
6
|
+
return t && typeof Symbol == "function" && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t;
|
|
7
|
+
}, o(e);
|
|
8
|
+
}
|
|
9
|
+
function i(e, t) {
|
|
10
|
+
if (o(e) != "object" || !e) return e;
|
|
11
|
+
var r = e[Symbol.toPrimitive];
|
|
12
|
+
if (r !== void 0) {
|
|
13
|
+
var n = r.call(e, t || "default");
|
|
14
|
+
if (o(n) != "object") return n;
|
|
15
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
16
|
+
}
|
|
17
|
+
return (t === "string" ? String : Number)(e);
|
|
18
|
+
}
|
|
19
|
+
function u(e) {
|
|
20
|
+
var t = i(e, "string");
|
|
21
|
+
return o(t) == "symbol" ? t : t + "";
|
|
22
|
+
}
|
|
23
|
+
function f(e, t, r) {
|
|
24
|
+
return (t = u(t)) in e ? Object.defineProperty(e, t, {
|
|
25
|
+
value: r,
|
|
26
|
+
enumerable: !0,
|
|
27
|
+
configurable: !0,
|
|
28
|
+
writable: !0
|
|
29
|
+
}) : e[t] = r, e;
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
f as t
|
|
33
|
+
};
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import { t as d } from "./defineProperty-CyepwRr5-eHUSgEtz.js";
|
|
2
|
+
var b = (e) => {
|
|
3
|
+
const t = (e.providerOptions && typeof e.providerOptions == "object" ? e.providerOptions : {}).__pieTelemetry;
|
|
4
|
+
return typeof t == "function" ? t : void 0;
|
|
5
|
+
}, S = {
|
|
6
|
+
pie: 3e3,
|
|
7
|
+
custom: 3e3
|
|
8
|
+
}, v = (e) => e.replace(/\/+$/, ""), k = (e) => {
|
|
9
|
+
const t = v(e.apiEndpoint), i = (e.provider || "").toLowerCase();
|
|
10
|
+
return i === "polly" || i === "google" ? `${t}/${i}/voices` : `${t}/voices`;
|
|
11
|
+
}, w = (e) => e.transportMode === "custom" ? "custom" : e.transportMode === "pie" ? "pie" : e.provider === "custom" ? "custom" : "pie", T = (e, t) => e.endpointMode ? e.endpointMode : t === "custom" ? "rootPost" : "synthesizePath", A = (e, t) => e.endpointValidationMode ? e.endpointValidationMode : t === "custom" ? "none" : "voices", R = (e) => {
|
|
12
|
+
const t = e.providerOptions || {};
|
|
13
|
+
if (typeof t.speedRate == "string") return t.speedRate;
|
|
14
|
+
const i = Number(e.rate ?? 1);
|
|
15
|
+
return !Number.isFinite(i) || i <= 0.95 ? "slow" : i >= 1.5 ? "fast" : "medium";
|
|
16
|
+
}, I = (e) => {
|
|
17
|
+
const t = [];
|
|
18
|
+
let i = 0;
|
|
19
|
+
const r = e.split(`
|
|
20
|
+
`).map((o) => o.trim()).filter(Boolean);
|
|
21
|
+
for (const o of r) try {
|
|
22
|
+
const s = JSON.parse(o), a = typeof s.type == "string" ? s.type : "word", h = typeof s.time == "number" && Number.isFinite(s.time) ? s.time : 0, n = typeof s.value == "string" ? s.value : "", l = typeof s.start == "number" && Number.isFinite(s.start) ? s.start : null, u = typeof s.end == "number" && Number.isFinite(s.end) ? s.end : null, m = l ?? i, c = u ?? m + Math.max(1, n.length || String(s.value || "").length);
|
|
23
|
+
i = Math.max(c + 1, i), t.push({
|
|
24
|
+
time: h,
|
|
25
|
+
type: a,
|
|
26
|
+
start: m,
|
|
27
|
+
end: c,
|
|
28
|
+
value: n
|
|
29
|
+
});
|
|
30
|
+
} catch {
|
|
31
|
+
}
|
|
32
|
+
return t;
|
|
33
|
+
}, M = (e) => {
|
|
34
|
+
if (!Array.isArray(e)) return [];
|
|
35
|
+
const t = [];
|
|
36
|
+
let i = 0;
|
|
37
|
+
for (const r of e) {
|
|
38
|
+
if (!r || typeof r != "object") continue;
|
|
39
|
+
const o = typeof r.type == "string" ? r.type : "word", s = typeof r.time == "number" && Number.isFinite(r.time) ? r.time : 0, a = typeof r.value == "string" ? r.value : "", h = typeof r.start == "number" && Number.isFinite(r.start) ? r.start : null, n = typeof r.end == "number" && Number.isFinite(r.end) ? r.end : null, l = h ?? i, u = n ?? l + Math.max(1, a.length || 1);
|
|
40
|
+
i = Math.max(i, u + 1), t.push({
|
|
41
|
+
time: s,
|
|
42
|
+
type: o,
|
|
43
|
+
start: l,
|
|
44
|
+
end: u,
|
|
45
|
+
value: a
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return t.sort((r, o) => r.time !== o.time ? r.time - o.time : r.start !== o.start ? r.start - o.start : r.end - o.end);
|
|
49
|
+
}, P = {
|
|
50
|
+
pie: {
|
|
51
|
+
id: "pie",
|
|
52
|
+
resolveSynthesisUrl: (e) => {
|
|
53
|
+
const t = T(e, "pie"), i = v(e.apiEndpoint);
|
|
54
|
+
return t === "rootPost" ? i : `${i}/synthesize`;
|
|
55
|
+
},
|
|
56
|
+
buildRequestBody: (e, t) => {
|
|
57
|
+
const i = t.providerOptions || {}, r = typeof t.engine == "string" ? t.engine : typeof i.engine == "string" ? i.engine : void 0, o = typeof i.sampleRate == "number" && Number.isFinite(i.sampleRate) ? i.sampleRate : void 0, s = i.format === "mp3" || i.format === "ogg" || i.format === "pcm" ? i.format : void 0, a = Array.isArray(i.speechMarkTypes) ? i.speechMarkTypes.filter((h) => h === "word" || h === "sentence" || h === "ssml") : void 0;
|
|
58
|
+
return {
|
|
59
|
+
text: e,
|
|
60
|
+
provider: t.provider || "polly",
|
|
61
|
+
voice: t.voice,
|
|
62
|
+
language: t.language,
|
|
63
|
+
rate: t.rate,
|
|
64
|
+
engine: r,
|
|
65
|
+
sampleRate: o,
|
|
66
|
+
format: s,
|
|
67
|
+
speechMarkTypes: a,
|
|
68
|
+
includeSpeechMarks: !0
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
parseResponse: async (e) => {
|
|
72
|
+
const t = await e.json();
|
|
73
|
+
return {
|
|
74
|
+
audio: {
|
|
75
|
+
kind: "base64",
|
|
76
|
+
data: t.audio,
|
|
77
|
+
contentType: t.contentType
|
|
78
|
+
},
|
|
79
|
+
speechMarks: Array.isArray(t.speechMarks) ? t.speechMarks : []
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
custom: {
|
|
84
|
+
id: "custom",
|
|
85
|
+
resolveSynthesisUrl: (e) => {
|
|
86
|
+
const t = T(e, "custom"), i = v(e.apiEndpoint);
|
|
87
|
+
return t === "synthesizePath" ? `${i}/synthesize` : i;
|
|
88
|
+
},
|
|
89
|
+
buildRequestBody: (e, t) => {
|
|
90
|
+
const i = t.providerOptions || {}, r = typeof i.lang_id == "string" ? i.lang_id : t.language || "en-US", o = typeof i.cache == "boolean" ? i.cache : !0;
|
|
91
|
+
return {
|
|
92
|
+
text: e,
|
|
93
|
+
speedRate: R(t),
|
|
94
|
+
lang_id: r,
|
|
95
|
+
cache: o
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
parseResponse: async (e, t, i, r) => {
|
|
99
|
+
const o = await e.json(), s = {};
|
|
100
|
+
if (t.includeAuthOnAssetFetch) for (const [n, l] of Object.entries(i)) n.toLowerCase() === "authorization" && (s[n] = l);
|
|
101
|
+
let a = [];
|
|
102
|
+
const h = M(o.speechMarks);
|
|
103
|
+
if (h.length > 0) a = h;
|
|
104
|
+
else if (typeof o.word == "string" && o.word.length > 0) {
|
|
105
|
+
const n = await fetch(o.word, {
|
|
106
|
+
headers: s,
|
|
107
|
+
signal: r
|
|
108
|
+
});
|
|
109
|
+
n.ok && (a = I(await n.text()));
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
audio: {
|
|
113
|
+
kind: "url",
|
|
114
|
+
url: o.audioContent
|
|
115
|
+
},
|
|
116
|
+
speechMarks: a
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}, E = class {
|
|
121
|
+
constructor(e, t) {
|
|
122
|
+
d(this, "config", void 0), d(this, "adapter", void 0), d(this, "currentAudio", null), d(this, "pausedState", !1), d(this, "wordTimings", []), d(this, "highlightInterval", null), d(this, "intentionallyStopped", !1), d(this, "activeSynthesisController", null), d(this, "synthesisRunId", 0), d(this, "telemetryReporter", void 0), d(this, "onWordBoundary", void 0), this.config = e, this.adapter = t, this.telemetryReporter = b(e);
|
|
123
|
+
}
|
|
124
|
+
async emitTelemetry(e, t) {
|
|
125
|
+
try {
|
|
126
|
+
await this.telemetryReporter?.(e, t);
|
|
127
|
+
} catch (i) {
|
|
128
|
+
console.warn("[ServerTTSProvider] telemetry callback failed:", i);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async speak(e) {
|
|
132
|
+
this.stop(), this.intentionallyStopped = !1;
|
|
133
|
+
const t = ++this.synthesisRunId, i = new AbortController();
|
|
134
|
+
this.activeSynthesisController = i;
|
|
135
|
+
const { audioUrl: r, wordTimings: o } = await this.synthesizeSpeech(e, i.signal, t);
|
|
136
|
+
if (t !== this.synthesisRunId) {
|
|
137
|
+
URL.revokeObjectURL(r);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const s = this.config.rate || 1;
|
|
141
|
+
return this.wordTimings = o.map((a) => ({
|
|
142
|
+
...a,
|
|
143
|
+
time: a.time / s
|
|
144
|
+
})), new Promise((a, h) => {
|
|
145
|
+
const n = new Audio(r);
|
|
146
|
+
this.currentAudio = n, this.config.rate && (n.playbackRate = Math.max(0.25, Math.min(4, this.config.rate))), this.config.volume !== void 0 && (n.volume = Math.max(0, Math.min(1, this.config.volume))), n.onplay = () => {
|
|
147
|
+
this.pausedState = !1, this.onWordBoundary && this.wordTimings.length > 0 && this.startWordHighlighting();
|
|
148
|
+
}, n.onended = () => {
|
|
149
|
+
this.stopWordHighlighting(), URL.revokeObjectURL(r), this.currentAudio = null, this.wordTimings = [], a();
|
|
150
|
+
}, n.onerror = (l) => {
|
|
151
|
+
this.stopWordHighlighting(), URL.revokeObjectURL(r), this.currentAudio = null, this.wordTimings = [], this.intentionallyStopped ? a() : h(/* @__PURE__ */ new Error("Failed to play audio from server"));
|
|
152
|
+
}, n.onpause = () => {
|
|
153
|
+
this.stopWordHighlighting(), this.pausedState = !0;
|
|
154
|
+
}, n.play().catch(h);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
async synthesizeSpeech(e, t, i) {
|
|
158
|
+
const r = Date.now();
|
|
159
|
+
await this.emitTelemetry("pie-tool-backend-call-start", {
|
|
160
|
+
toolId: "tts",
|
|
161
|
+
backend: this.config.provider || "server",
|
|
162
|
+
operation: "synthesize-speech"
|
|
163
|
+
});
|
|
164
|
+
const o = {
|
|
165
|
+
"Content-Type": "application/json",
|
|
166
|
+
...this.config.headers
|
|
167
|
+
};
|
|
168
|
+
this.config.authToken && (o.Authorization = `Bearer ${this.config.authToken}`);
|
|
169
|
+
const s = this.adapter.resolveSynthesisUrl(this.config), a = this.adapter.buildRequestBody(e, this.config), h = await (async () => {
|
|
170
|
+
try {
|
|
171
|
+
return await fetch(s, {
|
|
172
|
+
method: "POST",
|
|
173
|
+
headers: o,
|
|
174
|
+
body: JSON.stringify(a),
|
|
175
|
+
signal: t
|
|
176
|
+
});
|
|
177
|
+
} catch (c) {
|
|
178
|
+
throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
179
|
+
toolId: "tts",
|
|
180
|
+
backend: this.config.provider || "server",
|
|
181
|
+
operation: "synthesize-speech",
|
|
182
|
+
duration: Date.now() - r,
|
|
183
|
+
errorType: "TTSBackendNetworkError",
|
|
184
|
+
message: c instanceof Error ? c.message : String(c)
|
|
185
|
+
}), c;
|
|
186
|
+
}
|
|
187
|
+
})();
|
|
188
|
+
if (!h.ok) {
|
|
189
|
+
const c = await h.json().catch(() => ({})), p = c.message || c.error?.message || `Server returned ${h.status}`;
|
|
190
|
+
throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
191
|
+
toolId: "tts",
|
|
192
|
+
backend: this.config.provider || "server",
|
|
193
|
+
operation: "synthesize-speech",
|
|
194
|
+
duration: Date.now() - r,
|
|
195
|
+
statusCode: h.status,
|
|
196
|
+
errorType: "TTSBackendRequestError",
|
|
197
|
+
message: p
|
|
198
|
+
}), new Error(p);
|
|
199
|
+
}
|
|
200
|
+
const n = await this.adapter.parseResponse(h, this.config, o, t);
|
|
201
|
+
if (i !== this.synthesisRunId || t.aborted) throw new Error("Synthesis superseded by a newer request");
|
|
202
|
+
let l;
|
|
203
|
+
if (n.audio.kind === "base64") l = this.base64ToBlob(n.audio.data, n.audio.contentType);
|
|
204
|
+
else {
|
|
205
|
+
const c = n.audio.url, p = Date.now();
|
|
206
|
+
await this.emitTelemetry("pie-tool-backend-call-start", {
|
|
207
|
+
toolId: "tts",
|
|
208
|
+
backend: this.config.provider || "server",
|
|
209
|
+
operation: "fetch-synthesized-audio-asset"
|
|
210
|
+
});
|
|
211
|
+
const f = {};
|
|
212
|
+
this.config.includeAuthOnAssetFetch && this.config.authToken && (f.Authorization = `Bearer ${this.config.authToken}`);
|
|
213
|
+
const g = await (async () => {
|
|
214
|
+
try {
|
|
215
|
+
return await fetch(c, {
|
|
216
|
+
headers: f,
|
|
217
|
+
signal: t
|
|
218
|
+
});
|
|
219
|
+
} catch (y) {
|
|
220
|
+
throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
221
|
+
toolId: "tts",
|
|
222
|
+
backend: this.config.provider || "server",
|
|
223
|
+
operation: "fetch-synthesized-audio-asset",
|
|
224
|
+
duration: Date.now() - p,
|
|
225
|
+
errorType: "TTSAssetNetworkError",
|
|
226
|
+
message: y instanceof Error ? y.message : String(y)
|
|
227
|
+
}), y;
|
|
228
|
+
}
|
|
229
|
+
})();
|
|
230
|
+
if (!g.ok) throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
231
|
+
toolId: "tts",
|
|
232
|
+
backend: this.config.provider || "server",
|
|
233
|
+
operation: "fetch-synthesized-audio-asset",
|
|
234
|
+
duration: Date.now() - p,
|
|
235
|
+
statusCode: g.status,
|
|
236
|
+
errorType: "TTSAssetFetchError",
|
|
237
|
+
message: `Failed to download synthesized audio (${g.status})`
|
|
238
|
+
}), /* @__PURE__ */ new Error(`Failed to download synthesized audio (${g.status})`);
|
|
239
|
+
l = await g.blob(), await this.emitTelemetry("pie-tool-backend-call-success", {
|
|
240
|
+
toolId: "tts",
|
|
241
|
+
backend: this.config.provider || "server",
|
|
242
|
+
operation: "fetch-synthesized-audio-asset",
|
|
243
|
+
duration: Date.now() - p
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
const u = URL.createObjectURL(l), m = this.parseSpeechMarks(n.speechMarks);
|
|
247
|
+
return await this.emitTelemetry("pie-tool-backend-call-success", {
|
|
248
|
+
toolId: "tts",
|
|
249
|
+
backend: this.config.provider || "server",
|
|
250
|
+
operation: "synthesize-speech",
|
|
251
|
+
duration: Date.now() - r
|
|
252
|
+
}), {
|
|
253
|
+
audioUrl: u,
|
|
254
|
+
wordTimings: m
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
base64ToBlob(e, t) {
|
|
258
|
+
const i = atob(e), r = new Array(i.length);
|
|
259
|
+
for (let o = 0; o < i.length; o++) r[o] = i.charCodeAt(o);
|
|
260
|
+
return new Blob([new Uint8Array(r)], { type: t });
|
|
261
|
+
}
|
|
262
|
+
parseSpeechMarks(e) {
|
|
263
|
+
return e.filter((t) => t.type === "word").map((t, i) => ({
|
|
264
|
+
time: t.time,
|
|
265
|
+
wordIndex: i,
|
|
266
|
+
charIndex: t.start,
|
|
267
|
+
length: t.end - t.start
|
|
268
|
+
}));
|
|
269
|
+
}
|
|
270
|
+
startWordHighlighting() {
|
|
271
|
+
if (this.stopWordHighlighting(), !this.currentAudio || !this.onWordBoundary || this.wordTimings.length === 0) {
|
|
272
|
+
console.log("[ServerTTSProvider] Cannot start highlighting:", {
|
|
273
|
+
hasAudio: !!this.currentAudio,
|
|
274
|
+
hasCallback: !!this.onWordBoundary,
|
|
275
|
+
wordTimingsCount: this.wordTimings.length
|
|
276
|
+
});
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
console.log("[ServerTTSProvider] Starting word highlighting with", this.wordTimings.length, "word timings"), console.log("[ServerTTSProvider] Playback rate:", this.currentAudio.playbackRate), console.log("[ServerTTSProvider] First 3 timings:", this.wordTimings.slice(0, 3));
|
|
280
|
+
let e = -1;
|
|
281
|
+
this.highlightInterval = window.setInterval(() => {
|
|
282
|
+
if (!this.currentAudio) {
|
|
283
|
+
this.stopWordHighlighting();
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const t = this.currentAudio.currentTime * 1e3;
|
|
287
|
+
for (let i = 0; i < this.wordTimings.length; i++) {
|
|
288
|
+
const r = this.wordTimings[i];
|
|
289
|
+
if (t >= r.time && i > e) {
|
|
290
|
+
this.onWordBoundary && (console.log("[ServerTTSProvider] Highlighting word at charIndex:", r.charIndex, "length:", r.length, "time:", r.time, "currentTime:", t), this.onWordBoundary("", r.charIndex, r.length)), e = i;
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}, 50);
|
|
295
|
+
}
|
|
296
|
+
stopWordHighlighting() {
|
|
297
|
+
this.highlightInterval !== null && (clearInterval(this.highlightInterval), this.highlightInterval = null);
|
|
298
|
+
}
|
|
299
|
+
pause() {
|
|
300
|
+
this.currentAudio && !this.pausedState && (this.currentAudio.pause(), this.stopWordHighlighting(), this.pausedState = !0);
|
|
301
|
+
}
|
|
302
|
+
resume() {
|
|
303
|
+
this.currentAudio && this.pausedState && (this.currentAudio.play(), this.pausedState = !1, this.onWordBoundary && this.wordTimings.length > 0 && this.startWordHighlighting());
|
|
304
|
+
}
|
|
305
|
+
stop() {
|
|
306
|
+
this.synthesisRunId += 1, this.activeSynthesisController && (this.activeSynthesisController.abort(), this.activeSynthesisController = null), this.stopWordHighlighting(), this.currentAudio && (this.intentionallyStopped = !0, this.currentAudio.pause(), this.currentAudio.src && URL.revokeObjectURL(this.currentAudio.src), this.currentAudio.src = "", this.currentAudio = null), this.pausedState = !1, this.wordTimings = [];
|
|
307
|
+
}
|
|
308
|
+
isPlaying() {
|
|
309
|
+
return this.currentAudio !== null && !this.pausedState;
|
|
310
|
+
}
|
|
311
|
+
isPaused() {
|
|
312
|
+
return this.pausedState;
|
|
313
|
+
}
|
|
314
|
+
updateSettings(e) {
|
|
315
|
+
e.rate !== void 0 && (this.config.rate = e.rate, this.currentAudio && (this.currentAudio.playbackRate = Math.max(0.25, Math.min(4, e.rate)))), e.pitch !== void 0 && (this.config.pitch = e.pitch), e.voice !== void 0 && (this.config.voice = e.voice);
|
|
316
|
+
}
|
|
317
|
+
}, C = class {
|
|
318
|
+
constructor() {
|
|
319
|
+
d(this, "providerId", "server-tts"), d(this, "providerName", "Server TTS"), d(this, "version", "1.0.0"), d(this, "config", null), d(this, "adapter", null), d(this, "telemetryReporter", void 0);
|
|
320
|
+
}
|
|
321
|
+
async emitTelemetry(e, t) {
|
|
322
|
+
try {
|
|
323
|
+
await this.telemetryReporter?.(e, t);
|
|
324
|
+
} catch (i) {
|
|
325
|
+
console.warn("[ServerTTSProvider] telemetry callback failed:", i);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
async initialize(e) {
|
|
329
|
+
const t = e;
|
|
330
|
+
if (!t.apiEndpoint) throw new Error("apiEndpoint is required for ServerTTSProvider");
|
|
331
|
+
if (this.config = t, this.telemetryReporter = b(t), this.adapter = P[w(t)], t.validateEndpoint) {
|
|
332
|
+
const i = Date.now();
|
|
333
|
+
if (await this.emitTelemetry("pie-tool-backend-call-start", {
|
|
334
|
+
toolId: "tts",
|
|
335
|
+
backend: t.provider || "server",
|
|
336
|
+
operation: "validate-endpoint"
|
|
337
|
+
}), !await this.testAPIAvailability()) throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
338
|
+
toolId: "tts",
|
|
339
|
+
backend: t.provider || "server",
|
|
340
|
+
operation: "validate-endpoint",
|
|
341
|
+
duration: Date.now() - i,
|
|
342
|
+
errorType: "TTSEndpointValidationError",
|
|
343
|
+
message: `Server TTS API not available at ${t.apiEndpoint}`
|
|
344
|
+
}), /* @__PURE__ */ new Error(`Server TTS API not available at ${t.apiEndpoint}`);
|
|
345
|
+
await this.emitTelemetry("pie-tool-backend-call-success", {
|
|
346
|
+
toolId: "tts",
|
|
347
|
+
backend: t.provider || "server",
|
|
348
|
+
operation: "validate-endpoint",
|
|
349
|
+
duration: Date.now() - i
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
return new E(t, this.adapter);
|
|
353
|
+
}
|
|
354
|
+
async testAPIAvailability() {
|
|
355
|
+
if (!this.config || !this.adapter) return !1;
|
|
356
|
+
try {
|
|
357
|
+
const e = { ...this.config.headers };
|
|
358
|
+
this.config.authToken && (e.Authorization = `Bearer ${this.config.authToken}`);
|
|
359
|
+
const t = new AbortController(), i = setTimeout(() => t.abort(), 5e3), r = A(this.config, this.adapter.id);
|
|
360
|
+
if (r === "none") return clearTimeout(i), !0;
|
|
361
|
+
const o = r === "voices" ? k(this.config) : this.adapter.resolveSynthesisUrl(this.config), s = r === "voices" ? "GET" : "OPTIONS";
|
|
362
|
+
try {
|
|
363
|
+
const a = await fetch(o, {
|
|
364
|
+
method: s,
|
|
365
|
+
headers: e,
|
|
366
|
+
signal: t.signal
|
|
367
|
+
});
|
|
368
|
+
return clearTimeout(i), a.ok || a.status === 405;
|
|
369
|
+
} catch {
|
|
370
|
+
return clearTimeout(i), !1;
|
|
371
|
+
}
|
|
372
|
+
} catch {
|
|
373
|
+
return !1;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
supportsFeature(e) {
|
|
377
|
+
switch (e) {
|
|
378
|
+
case "pause":
|
|
379
|
+
case "resume":
|
|
380
|
+
case "wordBoundary":
|
|
381
|
+
case "voiceSelection":
|
|
382
|
+
case "rateControl":
|
|
383
|
+
return !0;
|
|
384
|
+
case "pitchControl":
|
|
385
|
+
return !1;
|
|
386
|
+
default:
|
|
387
|
+
return !1;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
getCapabilities() {
|
|
391
|
+
return {
|
|
392
|
+
supportsPause: !0,
|
|
393
|
+
supportsResume: !0,
|
|
394
|
+
supportsWordBoundary: !0,
|
|
395
|
+
supportsVoiceSelection: !0,
|
|
396
|
+
supportsRateControl: !0,
|
|
397
|
+
supportsPitchControl: !1,
|
|
398
|
+
maxTextLength: S[this.config ? w(this.config) : "pie"]
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
destroy() {
|
|
402
|
+
this.config = null, this.adapter = null, this.telemetryReporter = void 0;
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
export {
|
|
406
|
+
C as ServerTTSProvider
|
|
407
|
+
};
|