@pie-qti/player-elements 0.1.23 → 0.1.25
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/ItemToolBar-d36g3aw4-B6TGPyKt.js +3079 -0
- package/dist/ItemToolBar-d36g3aw4-B6TGPyKt.js.map +1 -0
- package/dist/ar-SA-BDmOol_3.js +854 -0
- package/dist/ar-SA-BDmOol_3.js.map +1 -0
- package/dist/{define-CqE08oOW.js → define-D80uAEx4.js} +2891 -4399
- package/dist/define-D80uAEx4.js.map +1 -0
- package/dist/dist-BSG0NOza.js +229 -0
- package/dist/dist-BSG0NOza.js.map +1 -0
- package/dist/{dist-CsEP48m1.js → dist-C8BDh5vZ.js} +1129 -760
- package/dist/dist-C8BDh5vZ.js.map +1 -0
- package/dist/dist-CQel8-vi.js +2507 -0
- package/dist/dist-CQel8-vi.js.map +1 -0
- package/dist/{dist-DQ_jFQFX.js → dist-L-bDDBry.js} +231 -147
- package/dist/dist-L-bDDBry.js.map +1 -0
- package/dist/{element-DU-n15ch.js → element-C5rTAwch.js} +2 -2
- package/dist/{element-DU-n15ch.js.map → element-C5rTAwch.js.map} +1 -1
- package/dist/{element-class-DBV-1lkb-BeszDwN_.js → element-class-B_qAd8ET-DGj15cBY.js} +4404 -3503
- package/dist/element-class-B_qAd8ET-DGj15cBY.js.map +1 -0
- package/dist/elements/BaseSvelteMountElement.d.ts +1 -0
- package/dist/elements/QtiAssessmentPlayerElement.d.ts +1 -0
- package/dist/elements.js +3 -3
- package/dist/es-ES-C98YtDtb.js +802 -0
- package/dist/es-ES-C98YtDtb.js.map +1 -0
- package/dist/fr-FR-CrmmiRPf.js +802 -0
- package/dist/fr-FR-CrmmiRPf.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/item-toolbar-element-BgqPFwsS.js +1990 -0
- package/dist/item-toolbar-element-BgqPFwsS.js.map +1 -0
- package/dist/{types-BFOGFD4R.js → language-tags-BwFWXo71.js} +24 -3
- package/dist/language-tags-BwFWXo71.js.map +1 -0
- package/dist/nl-NL-BRA_1Wcl.js +507 -0
- package/dist/nl-NL-BRA_1Wcl.js.map +1 -0
- package/dist/nl-NL-CAR7pgVz.js +802 -0
- package/dist/nl-NL-CAR7pgVz.js.map +1 -0
- package/dist/pie-DwmznDHb.js +363 -0
- package/dist/pie-DwmznDHb.js.map +1 -0
- package/dist/pie-assessment-toolkit-Cruxm385.js +5 -0
- package/dist/pie-assessment-toolkit-Cruxm385.js.map +1 -0
- package/dist/pie-assessment-toolkit-DJfg6laX.js +5 -0
- package/dist/pie-assessment-toolkit-DJfg6laX.js.map +1 -0
- package/dist/{pie-assessment-toolkit-element-BGOTMhdG.js → pie-assessment-toolkit-element-CT5UuvVY.js} +1679 -1245
- package/dist/pie-assessment-toolkit-element-CT5UuvVY.js.map +1 -0
- package/dist/pie-tool-calculator-Crfk-IZe.js +378 -0
- package/dist/pie-tool-calculator-Crfk-IZe.js.map +1 -0
- package/dist/{root-Dqg3cyBt.js → provider-gBXlGb0d.js} +4 -44
- package/dist/provider-gBXlGb0d.js.map +1 -0
- package/dist/register-players.js +1 -1
- package/dist/register.js +10603 -10162
- package/dist/register.js.map +1 -1
- package/dist/{resolveItems-DhQQhD2k.js → resolveItems-CNMvD8LP.js} +2 -2
- package/dist/{resolveItems-DhQQhD2k.js.map → resolveItems-CNMvD8LP.js.map} +1 -1
- package/dist/ro-RO-DTZbhL0e.js +802 -0
- package/dist/ro-RO-DTZbhL0e.js.map +1 -0
- package/dist/root-dCY6j_Hh.js +47 -0
- package/dist/root-dCY6j_Hh.js.map +1 -0
- package/dist/tag-names-DZGvnAgd.js +2495 -0
- package/dist/tag-names-DZGvnAgd.js.map +1 -0
- package/dist/th-TH-aqlT_oK3.js +802 -0
- package/dist/th-TH-aqlT_oK3.js.map +1 -0
- package/dist/tool-tts-inline-k3hLJUfp.js +4447 -0
- package/dist/tool-tts-inline-k3hLJUfp.js.map +1 -0
- package/dist/zh-CN-DCqaRRhU.js +802 -0
- package/dist/zh-CN-DCqaRRhU.js.map +1 -0
- package/package.json +8 -8
- package/dist/define-CqE08oOW.js.map +0 -1
- package/dist/dist-B1Rc9Jhz.js +0 -220
- package/dist/dist-B1Rc9Jhz.js.map +0 -1
- package/dist/dist-CQEJemjs.js +0 -5061
- package/dist/dist-CQEJemjs.js.map +0 -1
- package/dist/dist-CsEP48m1.js.map +0 -1
- package/dist/dist-DQ_jFQFX.js.map +0 -1
- package/dist/element-class-DBV-1lkb-BeszDwN_.js.map +0 -1
- package/dist/item-toolbar-element-iE73NEkH.js +0 -1922
- package/dist/item-toolbar-element-iE73NEkH.js.map +0 -1
- package/dist/pie-assessment-toolkit-element-BGOTMhdG.js.map +0 -1
- package/dist/pie-tool-calculator-CkQb5qxg.js +0 -2243
- package/dist/pie-tool-calculator-CkQb5qxg.js.map +0 -1
- package/dist/root-Dqg3cyBt.js.map +0 -1
- package/dist/tool-tts-inline-CA3VjWU4.js +0 -3670
- package/dist/tool-tts-inline-CA3VjWU4.js.map +0 -1
- package/dist/types-BFOGFD4R.js.map +0 -1
|
@@ -1,5 +1,91 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { a as e, i as t } from "./pie-DwmznDHb.js";
|
|
2
|
+
//#region ../../node_modules/.bun/@pie-players+tts-server-core@0.3.73/node_modules/@pie-players/tts-server-core/dist/speech-marks.js
|
|
3
|
+
var n = (e) => {
|
|
4
|
+
let t = Number(e);
|
|
5
|
+
return Number.isFinite(t) ? t : null;
|
|
6
|
+
}, r = (e) => [...e].sort((e, t) => e.time === t.time ? e.start === t.start ? e.end - t.end : e.start - t.start : e.time - t.time), i = (e) => {
|
|
7
|
+
let t = [], i = 0;
|
|
8
|
+
for (let r of e.split(/\r?\n/)) {
|
|
9
|
+
let e = r.trim();
|
|
10
|
+
if (e) try {
|
|
11
|
+
let r = JSON.parse(e);
|
|
12
|
+
if (r.type && r.type !== "word") continue;
|
|
13
|
+
let a = n(r.time);
|
|
14
|
+
if (a === null) continue;
|
|
15
|
+
let o = typeof r.value == "string" ? r.value : "", s = n(r.start) ?? i, c = n(r.end) ?? s + Math.max(1, o.length);
|
|
16
|
+
i = Math.max(c + 1, i), t.push({
|
|
17
|
+
time: a,
|
|
18
|
+
type: "word",
|
|
19
|
+
start: s,
|
|
20
|
+
end: c,
|
|
21
|
+
value: o
|
|
22
|
+
});
|
|
23
|
+
} catch {}
|
|
24
|
+
}
|
|
25
|
+
return r(t);
|
|
26
|
+
}, a = (e) => {
|
|
27
|
+
if (e.length < 2) return e;
|
|
28
|
+
let t = e.map((e) => e.time).filter((e) => e >= 0), n = t.length ? Math.max(...t) : 0, r = [];
|
|
29
|
+
for (let e = 1; e < t.length; e += 1) {
|
|
30
|
+
let n = t[e] - t[e - 1];
|
|
31
|
+
n > 0 && Number.isFinite(n) && r.push(n);
|
|
32
|
+
}
|
|
33
|
+
let i = r.length > 0 ? [...r].sort((e, t) => e - t)[Math.floor(r.length / 2)] : 0;
|
|
34
|
+
return n > 0 && n < 100 && e.length > 3 || i > 0 && i < 10 ? e.map((e) => ({
|
|
35
|
+
...e,
|
|
36
|
+
time: e.time * 1e3
|
|
37
|
+
})) : e;
|
|
38
|
+
}, o = (e, t) => {
|
|
39
|
+
if (!e.length || !t.length) return 0;
|
|
40
|
+
let n = t.toLowerCase(), r = [], i = 0;
|
|
41
|
+
for (let t of e) {
|
|
42
|
+
let e = t.value.trim().toLowerCase();
|
|
43
|
+
if (!e) continue;
|
|
44
|
+
let a = n.indexOf(e, i);
|
|
45
|
+
if (a < 0) continue;
|
|
46
|
+
let o = t.start - a;
|
|
47
|
+
if (o >= 0 && r.push(o), i = a + e.length, r.length >= 8) break;
|
|
48
|
+
}
|
|
49
|
+
if (r.length > 0) {
|
|
50
|
+
let e = [...r].sort((e, t) => e - t);
|
|
51
|
+
return e[Math.floor(e.length / 2)];
|
|
52
|
+
}
|
|
53
|
+
return Math.max(0, Math.floor(e[0].start));
|
|
54
|
+
}, s = (e, t) => {
|
|
55
|
+
if (!e.length || !t.length) return e;
|
|
56
|
+
let n = t.length;
|
|
57
|
+
if (Math.max(...e.map((e) => e.end)) <= n + 2) return e;
|
|
58
|
+
let r = o(e, t);
|
|
59
|
+
return r <= 0 ? e : e.map((e) => ({
|
|
60
|
+
...e,
|
|
61
|
+
start: e.start - r,
|
|
62
|
+
end: e.end - r
|
|
63
|
+
}));
|
|
64
|
+
}, c = (e, t) => {
|
|
65
|
+
if (!t.length) return e;
|
|
66
|
+
let n = t.length;
|
|
67
|
+
return r(e.map((e) => {
|
|
68
|
+
let t = Math.max(0, Math.min(n, Math.floor(e.start))), r = Math.max(t + 1, Math.min(n, Math.floor(e.end)));
|
|
69
|
+
return {
|
|
70
|
+
...e,
|
|
71
|
+
start: t,
|
|
72
|
+
end: r
|
|
73
|
+
};
|
|
74
|
+
}));
|
|
75
|
+
};
|
|
76
|
+
function l(e, t) {
|
|
77
|
+
return c(s(a(i(e)), t), t);
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region ../../node_modules/.bun/@pie-players+tts-server-core@0.3.73/node_modules/@pie-players/tts-server-core/dist/speed-rate.js
|
|
81
|
+
function u(e, t = "medium") {
|
|
82
|
+
let n = Number(e ?? 1);
|
|
83
|
+
return Number.isFinite(n) ? n <= .95 ? "slow" : n >= 1.5 ? "fast" : t : t;
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region ../../node_modules/.bun/@pie-players+tts-client-server@0.3.73/node_modules/@pie-players/tts-client-server/dist/ServerTTSProvider.js
|
|
87
|
+
var d = t("server-tts-provider", () => e());
|
|
88
|
+
function f(e, t) {
|
|
3
89
|
if (typeof e != "string" || e.length === 0) return null;
|
|
4
90
|
try {
|
|
5
91
|
let n = typeof t.apiEndpoint == "string" && /^https?:\/\//i.test(t.apiEndpoint) ? t.apiEndpoint : void 0, r = n ? new URL(e, n) : new URL(e);
|
|
@@ -8,7 +94,7 @@ function e(e, t) {
|
|
|
8
94
|
return null;
|
|
9
95
|
}
|
|
10
96
|
}
|
|
11
|
-
function
|
|
97
|
+
function p(e, t) {
|
|
12
98
|
let n = Array.isArray(t.assetOrigins) ? t.assetOrigins.filter((e) => typeof e == "string" && e.length > 0).map((e) => {
|
|
13
99
|
try {
|
|
14
100
|
return new URL(e).origin;
|
|
@@ -26,7 +112,7 @@ function t(e, t) {
|
|
|
26
112
|
}
|
|
27
113
|
return n.includes(e.origin);
|
|
28
114
|
}
|
|
29
|
-
function
|
|
115
|
+
function m(e) {
|
|
30
116
|
let t = {};
|
|
31
117
|
for (let [n, r] of Object.entries(e)) {
|
|
32
118
|
let e = n.toLowerCase();
|
|
@@ -34,36 +120,23 @@ function n(e) {
|
|
|
34
120
|
}
|
|
35
121
|
return t;
|
|
36
122
|
}
|
|
37
|
-
var
|
|
123
|
+
var h = (e) => {
|
|
38
124
|
let t = (e.providerOptions && typeof e.providerOptions == "object" ? e.providerOptions : {}).__pieTelemetry;
|
|
39
125
|
return typeof t == "function" ? t : void 0;
|
|
40
|
-
},
|
|
126
|
+
}, g = {
|
|
41
127
|
pie: 3e3,
|
|
42
128
|
custom: 3e3
|
|
43
|
-
},
|
|
44
|
-
if (!e ||
|
|
129
|
+
}, _ = /* @__PURE__ */ new Set(["polly", "google"]), v = (e) => {
|
|
130
|
+
if (!e || x(e) !== "pie") return !1;
|
|
45
131
|
let t = (e.provider || "polly").toLowerCase();
|
|
46
|
-
return
|
|
47
|
-
},
|
|
48
|
-
let t =
|
|
132
|
+
return _.has(t);
|
|
133
|
+
}, y = (e) => e.replace(/\/+$/, ""), b = (e) => {
|
|
134
|
+
let t = y(e.apiEndpoint), n = (e.provider || "").toLowerCase();
|
|
49
135
|
return n === "polly" || n === "google" ? `${t}/${n}/voices` : `${t}/voices`;
|
|
50
|
-
},
|
|
136
|
+
}, x = (e) => e.transportMode === "custom" ? "custom" : e.transportMode === "pie" ? "pie" : e.provider === "custom" ? "custom" : "pie", S = (e, t) => e.endpointMode ? e.endpointMode : t === "custom" ? "rootPost" : "synthesizePath", C = (e, t) => e.endpointValidationMode ? e.endpointValidationMode : t === "custom" ? "none" : "voices", w = (e) => {
|
|
51
137
|
let t = e.providerOptions || {};
|
|
52
|
-
return typeof t.speedRate == "string" ? t.speedRate :
|
|
53
|
-
},
|
|
54
|
-
let t = [], n = 0, r = e.split("\n").map((e) => e.trim()).filter(Boolean);
|
|
55
|
-
for (let e of r) try {
|
|
56
|
-
let r = JSON.parse(e), i = typeof r.type == "string" ? r.type : "word", a = typeof r.time == "number" && Number.isFinite(r.time) ? r.time : 0, o = typeof r.value == "string" ? r.value : "", s = typeof r.start == "number" && Number.isFinite(r.start) ? r.start : null, c = typeof r.end == "number" && Number.isFinite(r.end) ? r.end : null, l = s ?? n, u = c ?? l + Math.max(1, o.length || String(r.value || "").length);
|
|
57
|
-
n = Math.max(u + 1, n), t.push({
|
|
58
|
-
time: a,
|
|
59
|
-
type: i,
|
|
60
|
-
start: l,
|
|
61
|
-
end: u,
|
|
62
|
-
value: o
|
|
63
|
-
});
|
|
64
|
-
} catch {}
|
|
65
|
-
return t;
|
|
66
|
-
}, h = (e) => {
|
|
138
|
+
return typeof t.speedRate == "string" ? t.speedRate : u(e.rate);
|
|
139
|
+
}, T = (e) => {
|
|
67
140
|
if (!Array.isArray(e)) return [];
|
|
68
141
|
let t = [], n = 0;
|
|
69
142
|
for (let r of e) {
|
|
@@ -78,11 +151,11 @@ var r = (e) => {
|
|
|
78
151
|
});
|
|
79
152
|
}
|
|
80
153
|
return t.sort((e, t) => e.time === t.time ? e.start === t.start ? e.end - t.end : e.start - t.start : e.time - t.time);
|
|
81
|
-
},
|
|
154
|
+
}, E = {
|
|
82
155
|
pie: {
|
|
83
156
|
id: "pie",
|
|
84
157
|
resolveSynthesisUrl: (e) => {
|
|
85
|
-
let t =
|
|
158
|
+
let t = S(e, "pie"), n = y(e.apiEndpoint);
|
|
86
159
|
return t === "rootPost" ? n : `${n}/synthesize`;
|
|
87
160
|
},
|
|
88
161
|
buildRequestBody: (e, t) => {
|
|
@@ -100,67 +173,68 @@ var r = (e) => {
|
|
|
100
173
|
includeSpeechMarks: !0
|
|
101
174
|
};
|
|
102
175
|
},
|
|
103
|
-
parseResponse: async (e) => {
|
|
104
|
-
let
|
|
176
|
+
parseResponse: async (e, t, n, r, i) => {
|
|
177
|
+
let a = await e.json();
|
|
105
178
|
return {
|
|
106
179
|
audio: {
|
|
107
180
|
kind: "base64",
|
|
108
|
-
data:
|
|
109
|
-
contentType:
|
|
181
|
+
data: a.audio,
|
|
182
|
+
contentType: a.contentType
|
|
110
183
|
},
|
|
111
|
-
speechMarks: Array.isArray(
|
|
184
|
+
speechMarks: Array.isArray(a.speechMarks) ? a.speechMarks : []
|
|
112
185
|
};
|
|
113
186
|
}
|
|
114
187
|
},
|
|
115
188
|
custom: {
|
|
116
189
|
id: "custom",
|
|
117
190
|
resolveSynthesisUrl: (e) => {
|
|
118
|
-
let t =
|
|
191
|
+
let t = S(e, "custom"), n = y(e.apiEndpoint);
|
|
119
192
|
return t === "synthesizePath" ? `${n}/synthesize` : n;
|
|
120
193
|
},
|
|
121
194
|
buildRequestBody: (e, t) => {
|
|
122
195
|
let n = t.providerOptions || {}, r = typeof n.lang_id == "string" ? n.lang_id : t.language || "en-US", i = typeof n.cache != "boolean" || n.cache;
|
|
123
196
|
return {
|
|
124
197
|
text: e,
|
|
125
|
-
speedRate:
|
|
198
|
+
speedRate: w(t),
|
|
126
199
|
lang_id: r,
|
|
127
200
|
cache: i
|
|
128
201
|
};
|
|
129
202
|
},
|
|
130
|
-
parseResponse: async (
|
|
131
|
-
let
|
|
132
|
-
if (
|
|
133
|
-
let
|
|
134
|
-
if (
|
|
135
|
-
else if (typeof
|
|
136
|
-
let
|
|
137
|
-
if (
|
|
138
|
-
let
|
|
139
|
-
headers:
|
|
140
|
-
signal:
|
|
203
|
+
parseResponse: async (e, t, n, r, i) => {
|
|
204
|
+
let a = await e.json(), o = {};
|
|
205
|
+
if (t.includeAuthOnAssetFetch) for (let [e, t] of Object.entries(n)) e.toLowerCase() === "authorization" && (o[e] = t);
|
|
206
|
+
let s = [], c = T(a.speechMarks);
|
|
207
|
+
if (c.length > 0) s = c;
|
|
208
|
+
else if (typeof a.word == "string" && a.word.length > 0) {
|
|
209
|
+
let e = f(a.word, t);
|
|
210
|
+
if (e !== null) {
|
|
211
|
+
let n = p(e, t) ? o : m(o), a = await fetch(e.toString(), {
|
|
212
|
+
headers: n,
|
|
213
|
+
signal: r,
|
|
141
214
|
redirect: "error"
|
|
142
215
|
});
|
|
143
|
-
a.ok && (
|
|
216
|
+
a.ok && (s = l(await a.text(), i));
|
|
144
217
|
}
|
|
145
218
|
}
|
|
146
|
-
let
|
|
147
|
-
if (
|
|
219
|
+
let u = f(a.audioContent, t);
|
|
220
|
+
if (u === null) throw Error("TTS server returned an invalid audio URL");
|
|
148
221
|
return {
|
|
149
222
|
audio: {
|
|
150
223
|
kind: "url",
|
|
151
|
-
url:
|
|
224
|
+
url: u.toString()
|
|
152
225
|
},
|
|
153
|
-
speechMarks:
|
|
226
|
+
speechMarks: s
|
|
154
227
|
};
|
|
155
228
|
}
|
|
156
229
|
}
|
|
157
|
-
},
|
|
230
|
+
}, D = class {
|
|
158
231
|
config;
|
|
159
232
|
adapter;
|
|
160
233
|
currentAudio = null;
|
|
161
234
|
pausedState = !1;
|
|
162
235
|
wordTimings = [];
|
|
163
236
|
highlightInterval = null;
|
|
237
|
+
highlightCursor = -1;
|
|
164
238
|
intentionallyStopped = !1;
|
|
165
239
|
activeSynthesisController = null;
|
|
166
240
|
synthesisRunId = 0;
|
|
@@ -168,13 +242,13 @@ var r = (e) => {
|
|
|
168
242
|
onPlaybackStart;
|
|
169
243
|
onWordBoundary;
|
|
170
244
|
constructor(e, t) {
|
|
171
|
-
this.config = e, this.adapter = t, this.telemetryReporter =
|
|
245
|
+
this.config = e, this.adapter = t, this.telemetryReporter = h(e);
|
|
172
246
|
}
|
|
173
247
|
async emitTelemetry(e, t) {
|
|
174
248
|
try {
|
|
175
249
|
await this.telemetryReporter?.(e, t);
|
|
176
250
|
} catch (e) {
|
|
177
|
-
|
|
251
|
+
d.warn("telemetry callback failed:", e);
|
|
178
252
|
}
|
|
179
253
|
}
|
|
180
254
|
async speak(e) {
|
|
@@ -186,7 +260,7 @@ var r = (e) => {
|
|
|
186
260
|
URL.revokeObjectURL(r);
|
|
187
261
|
return;
|
|
188
262
|
}
|
|
189
|
-
return this.wordTimings = i, new Promise((e, n) => {
|
|
263
|
+
return this.wordTimings = i, this.highlightCursor = -1, new Promise((e, n) => {
|
|
190
264
|
let i = new Audio(r);
|
|
191
265
|
this.currentAudio = i, this.config.volume !== void 0 && (i.volume = Math.max(0, Math.min(1, this.config.volume))), i.onplay = () => {
|
|
192
266
|
if (t === this.synthesisRunId && this.currentAudio === i) {
|
|
@@ -194,110 +268,111 @@ var r = (e) => {
|
|
|
194
268
|
try {
|
|
195
269
|
this.onPlaybackStart?.();
|
|
196
270
|
} catch (e) {
|
|
197
|
-
|
|
271
|
+
d.warn("playback-start callback failed:", e);
|
|
198
272
|
}
|
|
199
273
|
this.onWordBoundary && this.wordTimings.length > 0 && this.startWordHighlighting();
|
|
200
274
|
}
|
|
201
275
|
}, i.onended = () => {
|
|
202
|
-
this.stopWordHighlighting(), URL.revokeObjectURL(r), this.currentAudio = null, this.wordTimings = [], e();
|
|
276
|
+
this.stopWordHighlighting(), URL.revokeObjectURL(r), this.currentAudio = null, this.wordTimings = [], this.highlightCursor = -1, e();
|
|
203
277
|
}, i.onerror = (t) => {
|
|
204
|
-
this.stopWordHighlighting(), URL.revokeObjectURL(r), this.currentAudio = null, this.wordTimings = [], this.intentionallyStopped ? e() : n(/* @__PURE__ */ Error("Failed to play audio from server"));
|
|
278
|
+
this.stopWordHighlighting(), URL.revokeObjectURL(r), this.currentAudio = null, this.wordTimings = [], this.highlightCursor = -1, this.intentionallyStopped ? e() : n(/* @__PURE__ */ Error("Failed to play audio from server"));
|
|
205
279
|
}, i.onpause = () => {
|
|
206
280
|
this.stopWordHighlighting(), this.pausedState = !0;
|
|
207
281
|
}, i.play().catch(n);
|
|
208
282
|
});
|
|
209
283
|
}
|
|
210
|
-
async synthesizeSpeech(
|
|
211
|
-
let
|
|
284
|
+
async synthesizeSpeech(e, t, n) {
|
|
285
|
+
let r = Date.now();
|
|
212
286
|
await this.emitTelemetry("pie-tool-backend-call-start", {
|
|
213
287
|
toolId: "tts",
|
|
214
288
|
backend: this.config.provider || "server",
|
|
215
289
|
operation: "synthesize-speech"
|
|
216
290
|
});
|
|
217
|
-
let
|
|
291
|
+
let i = {
|
|
218
292
|
"Content-Type": "application/json",
|
|
219
293
|
...this.config.headers
|
|
220
294
|
};
|
|
221
|
-
this.config.authToken && (
|
|
222
|
-
let
|
|
295
|
+
this.config.authToken && (i.Authorization = `Bearer ${this.config.authToken}`);
|
|
296
|
+
let a = this.adapter.resolveSynthesisUrl(this.config), o = this.adapter.buildRequestBody(e, this.config), s = await (async () => {
|
|
223
297
|
try {
|
|
224
|
-
return await fetch(
|
|
298
|
+
return await fetch(a, {
|
|
225
299
|
method: "POST",
|
|
226
|
-
headers:
|
|
227
|
-
body: JSON.stringify(
|
|
228
|
-
signal:
|
|
300
|
+
headers: i,
|
|
301
|
+
body: JSON.stringify(o),
|
|
302
|
+
signal: t
|
|
229
303
|
});
|
|
230
304
|
} catch (e) {
|
|
231
305
|
throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
232
306
|
toolId: "tts",
|
|
233
307
|
backend: this.config.provider || "server",
|
|
234
308
|
operation: "synthesize-speech",
|
|
235
|
-
duration: Date.now() -
|
|
309
|
+
duration: Date.now() - r,
|
|
236
310
|
errorType: "TTSBackendNetworkError",
|
|
237
311
|
message: e instanceof Error ? e.message : String(e)
|
|
238
312
|
}), e;
|
|
239
313
|
}
|
|
240
314
|
})();
|
|
241
|
-
if (!
|
|
242
|
-
let
|
|
243
|
-
if (
|
|
244
|
-
|
|
245
|
-
} catch (
|
|
246
|
-
|
|
247
|
-
status:
|
|
248
|
-
url:
|
|
249
|
-
|
|
250
|
-
parseError:
|
|
251
|
-
});
|
|
315
|
+
if (!s.ok) {
|
|
316
|
+
let t = await s.text().catch(() => ""), n = {};
|
|
317
|
+
if (t) try {
|
|
318
|
+
n = JSON.parse(t);
|
|
319
|
+
} catch (e) {
|
|
320
|
+
d.warn("non-OK response body was not JSON", {
|
|
321
|
+
status: s.status,
|
|
322
|
+
url: a,
|
|
323
|
+
bodyLength: t.length,
|
|
324
|
+
parseError: e instanceof Error ? e.message : String(e)
|
|
325
|
+
}), d.debug("non-OK response body", { rawBodyPreview: t.slice(0, 500) });
|
|
252
326
|
}
|
|
253
|
-
let
|
|
327
|
+
let i = typeof n.message == "string" && n.message || (typeof n.error?.message == "string" ? n.error.message : void 0) || `Server returned ${s.status}`;
|
|
254
328
|
await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
255
329
|
toolId: "tts",
|
|
256
330
|
backend: this.config.provider || "server",
|
|
257
331
|
operation: "synthesize-speech",
|
|
258
|
-
duration: Date.now() -
|
|
259
|
-
statusCode:
|
|
332
|
+
duration: Date.now() - r,
|
|
333
|
+
statusCode: s.status,
|
|
260
334
|
errorType: "TTSBackendRequestError",
|
|
261
|
-
message:
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
status: u.status,
|
|
266
|
-
url: c,
|
|
335
|
+
message: i
|
|
336
|
+
}), d.error("synthesize request failed", {
|
|
337
|
+
status: s.status,
|
|
338
|
+
url: a,
|
|
267
339
|
backend: this.config.provider || "server",
|
|
268
|
-
message:
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
340
|
+
message: i,
|
|
341
|
+
textLength: e.length
|
|
342
|
+
});
|
|
343
|
+
let o = e.replace(/\s+/g, " ").trim().slice(0, 120);
|
|
344
|
+
throw d.debug("synthesize request failed for text", {
|
|
345
|
+
responseBody: n,
|
|
346
|
+
textPreview: o.length < e.length ? `${o}…` : o
|
|
347
|
+
}), Error(i);
|
|
273
348
|
}
|
|
274
|
-
let
|
|
275
|
-
if (
|
|
276
|
-
let
|
|
277
|
-
if (
|
|
349
|
+
let c = await this.adapter.parseResponse(s, this.config, i, t, e);
|
|
350
|
+
if (n !== this.synthesisRunId || t.aborted) throw Error("Synthesis superseded by a newer request");
|
|
351
|
+
let l;
|
|
352
|
+
if (c.audio.kind === "base64") l = this.base64ToBlob(c.audio.data, c.audio.contentType);
|
|
278
353
|
else {
|
|
279
|
-
let
|
|
354
|
+
let e = c.audio.url, n = Date.now();
|
|
280
355
|
await this.emitTelemetry("pie-tool-backend-call-start", {
|
|
281
356
|
toolId: "tts",
|
|
282
357
|
backend: this.config.provider || "server",
|
|
283
358
|
operation: "fetch-synthesized-audio-asset"
|
|
284
359
|
});
|
|
285
|
-
let
|
|
286
|
-
this.config.includeAuthOnAssetFetch && this.config.authToken && (
|
|
287
|
-
let
|
|
288
|
-
if (
|
|
360
|
+
let r = {};
|
|
361
|
+
this.config.includeAuthOnAssetFetch && this.config.authToken && (r.Authorization = `Bearer ${this.config.authToken}`);
|
|
362
|
+
let i = f(e, this.config);
|
|
363
|
+
if (i === null) throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
289
364
|
toolId: "tts",
|
|
290
365
|
backend: this.config.provider || "server",
|
|
291
366
|
operation: "fetch-synthesized-audio-asset",
|
|
292
|
-
duration: Date.now() -
|
|
367
|
+
duration: Date.now() - n,
|
|
293
368
|
errorType: "TTSAssetInvalidUrl",
|
|
294
369
|
message: "TTS asset URL rejected (non-http(s) or malformed)"
|
|
295
370
|
}), Error("TTS asset URL rejected (non-http(s) or malformed)");
|
|
296
|
-
let
|
|
371
|
+
let a = p(i, this.config) ? r : m(r), o = await (async () => {
|
|
297
372
|
try {
|
|
298
|
-
return await fetch(
|
|
299
|
-
headers:
|
|
300
|
-
signal:
|
|
373
|
+
return await fetch(i.toString(), {
|
|
374
|
+
headers: a,
|
|
375
|
+
signal: t,
|
|
301
376
|
redirect: "error"
|
|
302
377
|
});
|
|
303
378
|
} catch (e) {
|
|
@@ -305,37 +380,37 @@ var r = (e) => {
|
|
|
305
380
|
toolId: "tts",
|
|
306
381
|
backend: this.config.provider || "server",
|
|
307
382
|
operation: "fetch-synthesized-audio-asset",
|
|
308
|
-
duration: Date.now() -
|
|
383
|
+
duration: Date.now() - n,
|
|
309
384
|
errorType: "TTSAssetNetworkError",
|
|
310
385
|
message: e instanceof Error ? e.message : String(e)
|
|
311
386
|
}), e;
|
|
312
387
|
}
|
|
313
388
|
})();
|
|
314
|
-
if (!
|
|
389
|
+
if (!o.ok) throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
315
390
|
toolId: "tts",
|
|
316
391
|
backend: this.config.provider || "server",
|
|
317
392
|
operation: "fetch-synthesized-audio-asset",
|
|
318
|
-
duration: Date.now() -
|
|
319
|
-
statusCode:
|
|
393
|
+
duration: Date.now() - n,
|
|
394
|
+
statusCode: o.status,
|
|
320
395
|
errorType: "TTSAssetFetchError",
|
|
321
|
-
message: `Failed to download synthesized audio (${
|
|
322
|
-
}), Error(`Failed to download synthesized audio (${
|
|
323
|
-
|
|
396
|
+
message: `Failed to download synthesized audio (${o.status})`
|
|
397
|
+
}), Error(`Failed to download synthesized audio (${o.status})`);
|
|
398
|
+
l = await o.blob(), await this.emitTelemetry("pie-tool-backend-call-success", {
|
|
324
399
|
toolId: "tts",
|
|
325
400
|
backend: this.config.provider || "server",
|
|
326
401
|
operation: "fetch-synthesized-audio-asset",
|
|
327
|
-
duration: Date.now() -
|
|
402
|
+
duration: Date.now() - n
|
|
328
403
|
});
|
|
329
404
|
}
|
|
330
|
-
let
|
|
405
|
+
let u = URL.createObjectURL(l), h = this.parseSpeechMarks(c.speechMarks);
|
|
331
406
|
return await this.emitTelemetry("pie-tool-backend-call-success", {
|
|
332
407
|
toolId: "tts",
|
|
333
408
|
backend: this.config.provider || "server",
|
|
334
409
|
operation: "synthesize-speech",
|
|
335
|
-
duration: Date.now() -
|
|
410
|
+
duration: Date.now() - r
|
|
336
411
|
}), {
|
|
337
|
-
audioUrl:
|
|
338
|
-
wordTimings:
|
|
412
|
+
audioUrl: u,
|
|
413
|
+
wordTimings: h
|
|
339
414
|
};
|
|
340
415
|
}
|
|
341
416
|
base64ToBlob(e, t) {
|
|
@@ -355,30 +430,39 @@ var r = (e) => {
|
|
|
355
430
|
}
|
|
356
431
|
startWordHighlighting() {
|
|
357
432
|
if (this.stopWordHighlighting(), !this.currentAudio || !this.onWordBoundary || this.wordTimings.length === 0) {
|
|
358
|
-
|
|
433
|
+
d.debug("cannot start word highlighting", {
|
|
359
434
|
hasAudio: !!this.currentAudio,
|
|
360
435
|
hasCallback: !!this.onWordBoundary,
|
|
361
436
|
wordTimingsCount: this.wordTimings.length
|
|
362
437
|
});
|
|
363
438
|
return;
|
|
364
439
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
440
|
+
d.debug("starting word highlighting", {
|
|
441
|
+
wordTimingsCount: this.wordTimings.length,
|
|
442
|
+
playbackRate: this.currentAudio.playbackRate
|
|
443
|
+
}), this.highlightInterval = window.setInterval(() => {
|
|
368
444
|
if (!this.currentAudio) {
|
|
369
445
|
this.stopWordHighlighting();
|
|
370
446
|
return;
|
|
371
447
|
}
|
|
372
|
-
let
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
448
|
+
let e = this.currentAudio.currentTime * 1e3, t = this.resolveCurrentWordIndex(e, this.highlightCursor);
|
|
449
|
+
if (t < 0 || t === this.highlightCursor) return;
|
|
450
|
+
this.highlightCursor = t;
|
|
451
|
+
let n = this.wordTimings[t];
|
|
452
|
+
d.debug("word boundary", {
|
|
453
|
+
wordIndex: n.wordIndex,
|
|
454
|
+
charIndex: n.charIndex,
|
|
455
|
+
length: n.length,
|
|
456
|
+
timingMs: n.time,
|
|
457
|
+
currentTimeMs: e
|
|
458
|
+
}), this.onWordBoundary?.(n.word, n.charIndex, n.length);
|
|
380
459
|
}, 50);
|
|
381
460
|
}
|
|
461
|
+
resolveCurrentWordIndex(e, t) {
|
|
462
|
+
let n = this.wordTimings, r = t < n.length ? t : -1;
|
|
463
|
+
for (r >= 0 && e < n[r].time && (r = -1); r + 1 < n.length && n[r + 1].time <= e;) r++;
|
|
464
|
+
return r;
|
|
465
|
+
}
|
|
382
466
|
stopWordHighlighting() {
|
|
383
467
|
this.highlightInterval !== null && (clearInterval(this.highlightInterval), this.highlightInterval = null);
|
|
384
468
|
}
|
|
@@ -389,7 +473,7 @@ var r = (e) => {
|
|
|
389
473
|
this.currentAudio && this.pausedState && (this.currentAudio.play(), this.pausedState = !1, this.onWordBoundary && this.wordTimings.length > 0 && this.startWordHighlighting());
|
|
390
474
|
}
|
|
391
475
|
stop() {
|
|
392
|
-
this.synthesisRunId += 1, this.activeSynthesisController &&= (this.activeSynthesisController.abort(), null), this.stopWordHighlighting(), this.currentAudio &&= (this.intentionallyStopped = !0, this.currentAudio.pause(), this.currentAudio.src && URL.revokeObjectURL(this.currentAudio.src), this.currentAudio.src = "", null), this.pausedState = !1, this.wordTimings = [];
|
|
476
|
+
this.synthesisRunId += 1, this.activeSynthesisController &&= (this.activeSynthesisController.abort(), null), this.stopWordHighlighting(), this.currentAudio &&= (this.intentionallyStopped = !0, this.currentAudio.pause(), this.currentAudio.src && URL.revokeObjectURL(this.currentAudio.src), this.currentAudio.src = "", null), this.pausedState = !1, this.wordTimings = [], this.highlightCursor = -1;
|
|
393
477
|
}
|
|
394
478
|
isPlaying() {
|
|
395
479
|
return this.currentAudio !== null && !this.pausedState;
|
|
@@ -400,10 +484,10 @@ var r = (e) => {
|
|
|
400
484
|
updateSettings(e) {
|
|
401
485
|
e.rate !== void 0 && (this.config.rate = e.rate, this.config.providerOptions = {
|
|
402
486
|
...this.config.providerOptions || {},
|
|
403
|
-
speedRate:
|
|
487
|
+
speedRate: u(e.rate)
|
|
404
488
|
}), e.pitch !== void 0 && (this.config.pitch = e.pitch), e.voice !== void 0 && (this.config.voice = e.voice);
|
|
405
489
|
}
|
|
406
|
-
},
|
|
490
|
+
}, O = class {
|
|
407
491
|
providerId = "server-tts";
|
|
408
492
|
providerName = "Server TTS";
|
|
409
493
|
version = "1.0.0";
|
|
@@ -414,15 +498,15 @@ var r = (e) => {
|
|
|
414
498
|
try {
|
|
415
499
|
await this.telemetryReporter?.(e, t);
|
|
416
500
|
} catch (e) {
|
|
417
|
-
|
|
501
|
+
d.warn("telemetry callback failed:", e);
|
|
418
502
|
}
|
|
419
503
|
}
|
|
420
504
|
async initialize(e) {
|
|
421
505
|
let t = e;
|
|
422
506
|
if (!t.apiEndpoint) throw Error("apiEndpoint is required for ServerTTSProvider");
|
|
423
|
-
this.config = t, this.telemetryReporter =
|
|
424
|
-
let n =
|
|
425
|
-
if (this.adapter =
|
|
507
|
+
this.config = t, this.telemetryReporter = h(t);
|
|
508
|
+
let n = x(t);
|
|
509
|
+
if (this.adapter = E[n], t.validateEndpoint) {
|
|
426
510
|
let e = Date.now();
|
|
427
511
|
if (await this.emitTelemetry("pie-tool-backend-call-start", {
|
|
428
512
|
toolId: "tts",
|
|
@@ -443,16 +527,16 @@ var r = (e) => {
|
|
|
443
527
|
duration: Date.now() - e
|
|
444
528
|
});
|
|
445
529
|
}
|
|
446
|
-
return new
|
|
530
|
+
return new D(t, this.adapter);
|
|
447
531
|
}
|
|
448
532
|
async testAPIAvailability() {
|
|
449
533
|
if (!this.config || !this.adapter) return !1;
|
|
450
534
|
try {
|
|
451
535
|
let e = { ...this.config.headers };
|
|
452
536
|
this.config.authToken && (e.Authorization = `Bearer ${this.config.authToken}`);
|
|
453
|
-
let t = new AbortController(), n = setTimeout(() => t.abort(), 5e3), r =
|
|
537
|
+
let t = new AbortController(), n = setTimeout(() => t.abort(), 5e3), r = C(this.config, this.adapter.id);
|
|
454
538
|
if (r === "none") return clearTimeout(n), !0;
|
|
455
|
-
let i = r === "voices" ?
|
|
539
|
+
let i = r === "voices" ? b(this.config) : this.adapter.resolveSynthesisUrl(this.config), a = r === "voices" ? "GET" : "OPTIONS";
|
|
456
540
|
try {
|
|
457
541
|
let r = await fetch(i, {
|
|
458
542
|
method: a,
|
|
@@ -479,7 +563,7 @@ var r = (e) => {
|
|
|
479
563
|
}
|
|
480
564
|
}
|
|
481
565
|
getCapabilities() {
|
|
482
|
-
let e = this.config ?
|
|
566
|
+
let e = this.config ? x(this.config) : "pie";
|
|
483
567
|
return {
|
|
484
568
|
supportsPause: !0,
|
|
485
569
|
supportsResume: !0,
|
|
@@ -487,8 +571,8 @@ var r = (e) => {
|
|
|
487
571
|
supportsVoiceSelection: !0,
|
|
488
572
|
supportsRateControl: !0,
|
|
489
573
|
supportsPitchControl: !1,
|
|
490
|
-
supportsSSML:
|
|
491
|
-
maxTextLength:
|
|
574
|
+
supportsSSML: v(this.config),
|
|
575
|
+
maxTextLength: g[e]
|
|
492
576
|
};
|
|
493
577
|
}
|
|
494
578
|
destroy() {
|
|
@@ -496,6 +580,6 @@ var r = (e) => {
|
|
|
496
580
|
}
|
|
497
581
|
};
|
|
498
582
|
//#endregion
|
|
499
|
-
export {
|
|
583
|
+
export { O as ServerTTSProvider };
|
|
500
584
|
|
|
501
|
-
//# sourceMappingURL=dist-
|
|
585
|
+
//# sourceMappingURL=dist-L-bDDBry.js.map
|