@pie-qti/player-elements 0.1.22 → 0.1.24
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/ar-SA-BDmOol_3.js +854 -0
- package/dist/ar-SA-BDmOol_3.js.map +1 -0
- package/dist/{define-Bkc2UFCK.js → define-D7_K0JFy.js} +4057 -2664
- package/dist/define-D7_K0JFy.js.map +1 -0
- package/dist/dist-BRTWr852.js +5809 -0
- package/dist/dist-BRTWr852.js.map +1 -0
- package/dist/{dist-CPyrAOfS.js → dist-BaQdJU08.js} +210 -130
- package/dist/dist-BaQdJU08.js.map +1 -0
- package/dist/{dist-C0bIgnik.js → dist-DwvskOs6.js} +4 -4
- package/dist/{dist-C0bIgnik.js.map → dist-DwvskOs6.js.map} +1 -1
- package/dist/{dist-_mWRIrTg.js → dist-ffJZTPTU.js} +2440 -2658
- package/dist/dist-ffJZTPTU.js.map +1 -0
- package/dist/{element-BrpUrZI4.js → element-DSCNeDLu.js} +2 -2
- package/dist/{element-BrpUrZI4.js.map → element-DSCNeDLu.js.map} +1 -1
- package/dist/{element-class-DWoLXp_r-ms67Krq-.js → element-class-DQy2cIPM-CldZrSRR.js} +3717 -3464
- package/dist/element-class-DQy2cIPM-CldZrSRR.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-BW9Y_n5x.js +1990 -0
- package/dist/item-toolbar-element-BW9Y_n5x.js.map +1 -0
- package/dist/{tag-names-DV56RHJk.js → language-tags-DVlRltrl.js} +25 -22
- package/dist/language-tags-DVlRltrl.js.map +1 -0
- package/dist/nl-NL-BeQBX6yq.js +505 -0
- package/dist/nl-NL-BeQBX6yq.js.map +1 -0
- package/dist/nl-NL-CAR7pgVz.js +802 -0
- package/dist/nl-NL-CAR7pgVz.js.map +1 -0
- package/dist/pie-assessment-toolkit-element-CpiB3twr.js +8573 -0
- package/dist/pie-assessment-toolkit-element-CpiB3twr.js.map +1 -0
- package/dist/pie-tool-calculator-BiWMTJe7.js +2992 -0
- package/dist/pie-tool-calculator-BiWMTJe7.js.map +1 -0
- package/dist/provider-Y5PhmTAu.js +58 -0
- package/dist/provider-Y5PhmTAu.js.map +1 -0
- package/dist/register-players.js +1 -1
- package/dist/register.js +7285 -9569
- package/dist/register.js.map +1 -1
- package/dist/{resolveItems-XtUnsftV.js → resolveItems-D8DJkv-4.js} +2 -2
- package/dist/{resolveItems-XtUnsftV.js.map → resolveItems-D8DJkv-4.js.map} +1 -1
- package/dist/ro-RO-DTZbhL0e.js +802 -0
- package/dist/ro-RO-DTZbhL0e.js.map +1 -0
- package/dist/root-DSkIM1v3.js +47 -0
- package/dist/root-DSkIM1v3.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-B71NTBbb.js +4435 -0
- package/dist/tool-tts-inline-B71NTBbb.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-Bkc2UFCK.js.map +0 -1
- package/dist/dist-CPyrAOfS.js.map +0 -1
- package/dist/dist-DU1nH3y8.js +0 -1247
- package/dist/dist-DU1nH3y8.js.map +0 -1
- package/dist/dist-_mWRIrTg.js.map +0 -1
- package/dist/element-class-DWoLXp_r-ms67Krq-.js.map +0 -1
- package/dist/item-toolbar-element-DFppTi_H.js +0 -6015
- package/dist/item-toolbar-element-DFppTi_H.js.map +0 -1
- package/dist/pie-assessment-toolkit-element-DlSFT_I2.js +0 -28479
- package/dist/pie-assessment-toolkit-element-DlSFT_I2.js.map +0 -1
- package/dist/pie-tool-calculator-BGp3etqJ.js +0 -2226
- package/dist/pie-tool-calculator-BGp3etqJ.js.map +0 -1
- package/dist/root-DBWhDxjY.js +0 -98
- package/dist/root-DBWhDxjY.js.map +0 -1
- package/dist/tag-names-DV56RHJk.js.map +0 -1
- package/dist/tool-tts-inline-DVUYjVnD.js +0 -2574
- package/dist/tool-tts-inline-DVUYjVnD.js.map +0 -1
|
@@ -1,5 +1,89 @@
|
|
|
1
|
-
//#region ../../node_modules/.bun/@pie-players+tts-
|
|
2
|
-
|
|
1
|
+
//#region ../../node_modules/.bun/@pie-players+tts-server-core@0.3.68/node_modules/@pie-players/tts-server-core/dist/speech-marks.js
|
|
2
|
+
var e = (e) => {
|
|
3
|
+
let t = Number(e);
|
|
4
|
+
return Number.isFinite(t) ? t : null;
|
|
5
|
+
}, t = (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), n = (n) => {
|
|
6
|
+
let r = [], i = 0;
|
|
7
|
+
for (let t of n.split(/\r?\n/)) {
|
|
8
|
+
let n = t.trim();
|
|
9
|
+
if (n) try {
|
|
10
|
+
let t = JSON.parse(n);
|
|
11
|
+
if (t.type && t.type !== "word") continue;
|
|
12
|
+
let a = e(t.time);
|
|
13
|
+
if (a === null) continue;
|
|
14
|
+
let o = typeof t.value == "string" ? t.value : "", s = e(t.start) ?? i, c = e(t.end) ?? s + Math.max(1, o.length);
|
|
15
|
+
i = Math.max(c + 1, i), r.push({
|
|
16
|
+
time: a,
|
|
17
|
+
type: "word",
|
|
18
|
+
start: s,
|
|
19
|
+
end: c,
|
|
20
|
+
value: o
|
|
21
|
+
});
|
|
22
|
+
} catch {}
|
|
23
|
+
}
|
|
24
|
+
return t(r);
|
|
25
|
+
}, r = (e) => {
|
|
26
|
+
if (e.length < 2) return e;
|
|
27
|
+
let t = e.map((e) => e.time).filter((e) => e >= 0), n = t.length ? Math.max(...t) : 0, r = [];
|
|
28
|
+
for (let e = 1; e < t.length; e += 1) {
|
|
29
|
+
let n = t[e] - t[e - 1];
|
|
30
|
+
n > 0 && Number.isFinite(n) && r.push(n);
|
|
31
|
+
}
|
|
32
|
+
let i = r.length > 0 ? [...r].sort((e, t) => e - t)[Math.floor(r.length / 2)] : 0;
|
|
33
|
+
return n > 0 && n < 100 && e.length > 3 || i > 0 && i < 10 ? e.map((e) => ({
|
|
34
|
+
...e,
|
|
35
|
+
time: e.time * 1e3
|
|
36
|
+
})) : e;
|
|
37
|
+
}, i = (e, t) => {
|
|
38
|
+
if (!e.length || !t.length) return 0;
|
|
39
|
+
let n = t.toLowerCase(), r = [], i = 0;
|
|
40
|
+
for (let t of e) {
|
|
41
|
+
let e = t.value.trim().toLowerCase();
|
|
42
|
+
if (!e) continue;
|
|
43
|
+
let a = n.indexOf(e, i);
|
|
44
|
+
if (a < 0) continue;
|
|
45
|
+
let o = t.start - a;
|
|
46
|
+
if (o >= 0 && r.push(o), i = a + e.length, r.length >= 8) break;
|
|
47
|
+
}
|
|
48
|
+
if (r.length > 0) {
|
|
49
|
+
let e = [...r].sort((e, t) => e - t);
|
|
50
|
+
return e[Math.floor(e.length / 2)];
|
|
51
|
+
}
|
|
52
|
+
return Math.max(0, Math.floor(e[0].start));
|
|
53
|
+
}, a = (e, t) => {
|
|
54
|
+
if (!e.length || !t.length) return e;
|
|
55
|
+
let n = t.length;
|
|
56
|
+
if (Math.max(...e.map((e) => e.end)) <= n + 2) return e;
|
|
57
|
+
let r = i(e, t);
|
|
58
|
+
return r <= 0 ? e : e.map((e) => ({
|
|
59
|
+
...e,
|
|
60
|
+
start: e.start - r,
|
|
61
|
+
end: e.end - r
|
|
62
|
+
}));
|
|
63
|
+
}, o = (e, n) => {
|
|
64
|
+
if (!n.length) return e;
|
|
65
|
+
let r = n.length;
|
|
66
|
+
return t(e.map((e) => {
|
|
67
|
+
let t = Math.max(0, Math.min(r, Math.floor(e.start))), n = Math.max(t + 1, Math.min(r, Math.floor(e.end)));
|
|
68
|
+
return {
|
|
69
|
+
...e,
|
|
70
|
+
start: t,
|
|
71
|
+
end: n
|
|
72
|
+
};
|
|
73
|
+
}));
|
|
74
|
+
};
|
|
75
|
+
function s(e, t) {
|
|
76
|
+
return o(a(r(n(e)), t), t);
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region ../../node_modules/.bun/@pie-players+tts-server-core@0.3.68/node_modules/@pie-players/tts-server-core/dist/speed-rate.js
|
|
80
|
+
function c(e, t = "medium") {
|
|
81
|
+
let n = Number(e ?? 1);
|
|
82
|
+
return Number.isFinite(n) ? n <= .95 ? "slow" : n >= 1.5 ? "fast" : t : t;
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region ../../node_modules/.bun/@pie-players+tts-client-server@0.3.68/node_modules/@pie-players/tts-client-server/dist/ServerTTSProvider.js
|
|
86
|
+
function l(e, t) {
|
|
3
87
|
if (typeof e != "string" || e.length === 0) return null;
|
|
4
88
|
try {
|
|
5
89
|
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 +92,7 @@ function e(e, t) {
|
|
|
8
92
|
return null;
|
|
9
93
|
}
|
|
10
94
|
}
|
|
11
|
-
function
|
|
95
|
+
function u(e, t) {
|
|
12
96
|
let n = Array.isArray(t.assetOrigins) ? t.assetOrigins.filter((e) => typeof e == "string" && e.length > 0).map((e) => {
|
|
13
97
|
try {
|
|
14
98
|
return new URL(e).origin;
|
|
@@ -26,7 +110,7 @@ function t(e, t) {
|
|
|
26
110
|
}
|
|
27
111
|
return n.includes(e.origin);
|
|
28
112
|
}
|
|
29
|
-
function
|
|
113
|
+
function d(e) {
|
|
30
114
|
let t = {};
|
|
31
115
|
for (let [n, r] of Object.entries(e)) {
|
|
32
116
|
let e = n.toLowerCase();
|
|
@@ -34,36 +118,23 @@ function n(e) {
|
|
|
34
118
|
}
|
|
35
119
|
return t;
|
|
36
120
|
}
|
|
37
|
-
var
|
|
121
|
+
var f = (e) => {
|
|
38
122
|
let t = (e.providerOptions && typeof e.providerOptions == "object" ? e.providerOptions : {}).__pieTelemetry;
|
|
39
123
|
return typeof t == "function" ? t : void 0;
|
|
40
|
-
},
|
|
124
|
+
}, p = {
|
|
41
125
|
pie: 3e3,
|
|
42
126
|
custom: 3e3
|
|
43
|
-
},
|
|
44
|
-
if (!e ||
|
|
127
|
+
}, m = /* @__PURE__ */ new Set(["polly", "google"]), h = (e) => {
|
|
128
|
+
if (!e || v(e) !== "pie") return !1;
|
|
45
129
|
let t = (e.provider || "polly").toLowerCase();
|
|
46
|
-
return
|
|
47
|
-
},
|
|
48
|
-
let t =
|
|
130
|
+
return m.has(t);
|
|
131
|
+
}, g = (e) => e.replace(/\/+$/, ""), _ = (e) => {
|
|
132
|
+
let t = g(e.apiEndpoint), n = (e.provider || "").toLowerCase();
|
|
49
133
|
return n === "polly" || n === "google" ? `${t}/${n}/voices` : `${t}/voices`;
|
|
50
|
-
},
|
|
134
|
+
}, v = (e) => e.transportMode === "custom" ? "custom" : e.transportMode === "pie" ? "pie" : e.provider === "custom" ? "custom" : "pie", y = (e, t) => e.endpointMode ? e.endpointMode : t === "custom" ? "rootPost" : "synthesizePath", b = (e, t) => e.endpointValidationMode ? e.endpointValidationMode : t === "custom" ? "none" : "voices", x = (e) => {
|
|
51
135
|
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) => {
|
|
136
|
+
return typeof t.speedRate == "string" ? t.speedRate : c(e.rate);
|
|
137
|
+
}, S = (e) => {
|
|
67
138
|
if (!Array.isArray(e)) return [];
|
|
68
139
|
let t = [], n = 0;
|
|
69
140
|
for (let r of e) {
|
|
@@ -78,11 +149,11 @@ var r = (e) => {
|
|
|
78
149
|
});
|
|
79
150
|
}
|
|
80
151
|
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
|
-
},
|
|
152
|
+
}, C = {
|
|
82
153
|
pie: {
|
|
83
154
|
id: "pie",
|
|
84
155
|
resolveSynthesisUrl: (e) => {
|
|
85
|
-
let t =
|
|
156
|
+
let t = y(e, "pie"), n = g(e.apiEndpoint);
|
|
86
157
|
return t === "rootPost" ? n : `${n}/synthesize`;
|
|
87
158
|
},
|
|
88
159
|
buildRequestBody: (e, t) => {
|
|
@@ -100,61 +171,61 @@ var r = (e) => {
|
|
|
100
171
|
includeSpeechMarks: !0
|
|
101
172
|
};
|
|
102
173
|
},
|
|
103
|
-
parseResponse: async (e) => {
|
|
104
|
-
let
|
|
174
|
+
parseResponse: async (e, t, n, r, i) => {
|
|
175
|
+
let a = await e.json();
|
|
105
176
|
return {
|
|
106
177
|
audio: {
|
|
107
178
|
kind: "base64",
|
|
108
|
-
data:
|
|
109
|
-
contentType:
|
|
179
|
+
data: a.audio,
|
|
180
|
+
contentType: a.contentType
|
|
110
181
|
},
|
|
111
|
-
speechMarks: Array.isArray(
|
|
182
|
+
speechMarks: Array.isArray(a.speechMarks) ? a.speechMarks : []
|
|
112
183
|
};
|
|
113
184
|
}
|
|
114
185
|
},
|
|
115
186
|
custom: {
|
|
116
187
|
id: "custom",
|
|
117
188
|
resolveSynthesisUrl: (e) => {
|
|
118
|
-
let t =
|
|
189
|
+
let t = y(e, "custom"), n = g(e.apiEndpoint);
|
|
119
190
|
return t === "synthesizePath" ? `${n}/synthesize` : n;
|
|
120
191
|
},
|
|
121
192
|
buildRequestBody: (e, t) => {
|
|
122
193
|
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
194
|
return {
|
|
124
195
|
text: e,
|
|
125
|
-
speedRate:
|
|
196
|
+
speedRate: x(t),
|
|
126
197
|
lang_id: r,
|
|
127
198
|
cache: i
|
|
128
199
|
};
|
|
129
200
|
},
|
|
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:
|
|
201
|
+
parseResponse: async (e, t, n, r, i) => {
|
|
202
|
+
let a = await e.json(), o = {};
|
|
203
|
+
if (t.includeAuthOnAssetFetch) for (let [e, t] of Object.entries(n)) e.toLowerCase() === "authorization" && (o[e] = t);
|
|
204
|
+
let c = [], f = S(a.speechMarks);
|
|
205
|
+
if (f.length > 0) c = f;
|
|
206
|
+
else if (typeof a.word == "string" && a.word.length > 0) {
|
|
207
|
+
let e = l(a.word, t);
|
|
208
|
+
if (e !== null) {
|
|
209
|
+
let n = u(e, t) ? o : d(o), a = await fetch(e.toString(), {
|
|
210
|
+
headers: n,
|
|
211
|
+
signal: r,
|
|
141
212
|
redirect: "error"
|
|
142
213
|
});
|
|
143
|
-
a.ok && (
|
|
214
|
+
a.ok && (c = s(await a.text(), i));
|
|
144
215
|
}
|
|
145
216
|
}
|
|
146
|
-
let
|
|
147
|
-
if (
|
|
217
|
+
let p = l(a.audioContent, t);
|
|
218
|
+
if (p === null) throw Error("TTS server returned an invalid audio URL");
|
|
148
219
|
return {
|
|
149
220
|
audio: {
|
|
150
221
|
kind: "url",
|
|
151
|
-
url:
|
|
222
|
+
url: p.toString()
|
|
152
223
|
},
|
|
153
|
-
speechMarks:
|
|
224
|
+
speechMarks: c
|
|
154
225
|
};
|
|
155
226
|
}
|
|
156
227
|
}
|
|
157
|
-
},
|
|
228
|
+
}, w = class {
|
|
158
229
|
config;
|
|
159
230
|
adapter;
|
|
160
231
|
currentAudio = null;
|
|
@@ -165,9 +236,10 @@ var r = (e) => {
|
|
|
165
236
|
activeSynthesisController = null;
|
|
166
237
|
synthesisRunId = 0;
|
|
167
238
|
telemetryReporter;
|
|
239
|
+
onPlaybackStart;
|
|
168
240
|
onWordBoundary;
|
|
169
241
|
constructor(e, t) {
|
|
170
|
-
this.config = e, this.adapter = t, this.telemetryReporter =
|
|
242
|
+
this.config = e, this.adapter = t, this.telemetryReporter = f(e);
|
|
171
243
|
}
|
|
172
244
|
async emitTelemetry(e, t) {
|
|
173
245
|
try {
|
|
@@ -185,110 +257,118 @@ var r = (e) => {
|
|
|
185
257
|
URL.revokeObjectURL(r);
|
|
186
258
|
return;
|
|
187
259
|
}
|
|
188
|
-
return this.wordTimings = i, new Promise((e,
|
|
189
|
-
let
|
|
190
|
-
this.currentAudio =
|
|
191
|
-
|
|
192
|
-
|
|
260
|
+
return this.wordTimings = i, new Promise((e, n) => {
|
|
261
|
+
let i = new Audio(r);
|
|
262
|
+
this.currentAudio = i, this.config.volume !== void 0 && (i.volume = Math.max(0, Math.min(1, this.config.volume))), i.onplay = () => {
|
|
263
|
+
if (t === this.synthesisRunId && this.currentAudio === i) {
|
|
264
|
+
this.pausedState = !1;
|
|
265
|
+
try {
|
|
266
|
+
this.onPlaybackStart?.();
|
|
267
|
+
} catch (e) {
|
|
268
|
+
console.warn("[ServerTTSProvider] playback-start callback failed:", e);
|
|
269
|
+
}
|
|
270
|
+
this.onWordBoundary && this.wordTimings.length > 0 && this.startWordHighlighting();
|
|
271
|
+
}
|
|
272
|
+
}, i.onended = () => {
|
|
193
273
|
this.stopWordHighlighting(), URL.revokeObjectURL(r), this.currentAudio = null, this.wordTimings = [], e();
|
|
194
|
-
},
|
|
195
|
-
this.stopWordHighlighting(), URL.revokeObjectURL(r), this.currentAudio = null, this.wordTimings = [], this.intentionallyStopped ? e() :
|
|
196
|
-
},
|
|
274
|
+
}, i.onerror = (t) => {
|
|
275
|
+
this.stopWordHighlighting(), URL.revokeObjectURL(r), this.currentAudio = null, this.wordTimings = [], this.intentionallyStopped ? e() : n(/* @__PURE__ */ Error("Failed to play audio from server"));
|
|
276
|
+
}, i.onpause = () => {
|
|
197
277
|
this.stopWordHighlighting(), this.pausedState = !0;
|
|
198
|
-
},
|
|
278
|
+
}, i.play().catch(n);
|
|
199
279
|
});
|
|
200
280
|
}
|
|
201
|
-
async synthesizeSpeech(
|
|
202
|
-
let
|
|
281
|
+
async synthesizeSpeech(e, t, n) {
|
|
282
|
+
let r = Date.now();
|
|
203
283
|
await this.emitTelemetry("pie-tool-backend-call-start", {
|
|
204
284
|
toolId: "tts",
|
|
205
285
|
backend: this.config.provider || "server",
|
|
206
286
|
operation: "synthesize-speech"
|
|
207
287
|
});
|
|
208
|
-
let
|
|
288
|
+
let i = {
|
|
209
289
|
"Content-Type": "application/json",
|
|
210
290
|
...this.config.headers
|
|
211
291
|
};
|
|
212
|
-
this.config.authToken && (
|
|
213
|
-
let
|
|
292
|
+
this.config.authToken && (i.Authorization = `Bearer ${this.config.authToken}`);
|
|
293
|
+
let a = this.adapter.resolveSynthesisUrl(this.config), o = this.adapter.buildRequestBody(e, this.config), s = await (async () => {
|
|
214
294
|
try {
|
|
215
|
-
return await fetch(
|
|
295
|
+
return await fetch(a, {
|
|
216
296
|
method: "POST",
|
|
217
|
-
headers:
|
|
218
|
-
body: JSON.stringify(
|
|
219
|
-
signal:
|
|
297
|
+
headers: i,
|
|
298
|
+
body: JSON.stringify(o),
|
|
299
|
+
signal: t
|
|
220
300
|
});
|
|
221
301
|
} catch (e) {
|
|
222
302
|
throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
223
303
|
toolId: "tts",
|
|
224
304
|
backend: this.config.provider || "server",
|
|
225
305
|
operation: "synthesize-speech",
|
|
226
|
-
duration: Date.now() -
|
|
306
|
+
duration: Date.now() - r,
|
|
227
307
|
errorType: "TTSBackendNetworkError",
|
|
228
308
|
message: e instanceof Error ? e.message : String(e)
|
|
229
309
|
}), e;
|
|
230
310
|
}
|
|
231
311
|
})();
|
|
232
|
-
if (!
|
|
233
|
-
let
|
|
234
|
-
if (
|
|
235
|
-
|
|
236
|
-
} catch (
|
|
312
|
+
if (!s.ok) {
|
|
313
|
+
let t = await s.text().catch(() => ""), n = {};
|
|
314
|
+
if (t) try {
|
|
315
|
+
n = JSON.parse(t);
|
|
316
|
+
} catch (e) {
|
|
237
317
|
console.warn("[ServerTTSProvider] non-OK response body was not JSON", {
|
|
238
|
-
status:
|
|
239
|
-
url:
|
|
240
|
-
rawBodyPreview:
|
|
241
|
-
parseError:
|
|
318
|
+
status: s.status,
|
|
319
|
+
url: a,
|
|
320
|
+
rawBodyPreview: t.slice(0, 500),
|
|
321
|
+
parseError: e instanceof Error ? e.message : String(e)
|
|
242
322
|
});
|
|
243
323
|
}
|
|
244
|
-
let
|
|
324
|
+
let i = typeof n.message == "string" && n.message || (typeof n.error?.message == "string" ? n.error.message : void 0) || `Server returned ${s.status}`;
|
|
245
325
|
await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
246
326
|
toolId: "tts",
|
|
247
327
|
backend: this.config.provider || "server",
|
|
248
328
|
operation: "synthesize-speech",
|
|
249
|
-
duration: Date.now() -
|
|
250
|
-
statusCode:
|
|
329
|
+
duration: Date.now() - r,
|
|
330
|
+
statusCode: s.status,
|
|
251
331
|
errorType: "TTSBackendRequestError",
|
|
252
|
-
message:
|
|
332
|
+
message: i
|
|
253
333
|
});
|
|
254
|
-
let
|
|
334
|
+
let o = e.replace(/\s+/g, " ").trim().slice(0, 120);
|
|
255
335
|
throw console.error("[ServerTTSProvider] synthesize request failed", {
|
|
256
|
-
status:
|
|
257
|
-
url:
|
|
336
|
+
status: s.status,
|
|
337
|
+
url: a,
|
|
258
338
|
backend: this.config.provider || "server",
|
|
259
|
-
message:
|
|
260
|
-
responseBody:
|
|
261
|
-
textLength:
|
|
262
|
-
textPreview:
|
|
263
|
-
}), Error(
|
|
339
|
+
message: i,
|
|
340
|
+
responseBody: n,
|
|
341
|
+
textLength: e.length,
|
|
342
|
+
textPreview: o.length < e.length ? `${o}…` : o
|
|
343
|
+
}), Error(i);
|
|
264
344
|
}
|
|
265
|
-
let
|
|
266
|
-
if (
|
|
345
|
+
let c = await this.adapter.parseResponse(s, this.config, i, t, e);
|
|
346
|
+
if (n !== this.synthesisRunId || t.aborted) throw Error("Synthesis superseded by a newer request");
|
|
267
347
|
let f;
|
|
268
|
-
if (
|
|
348
|
+
if (c.audio.kind === "base64") f = this.base64ToBlob(c.audio.data, c.audio.contentType);
|
|
269
349
|
else {
|
|
270
|
-
let
|
|
350
|
+
let e = c.audio.url, n = Date.now();
|
|
271
351
|
await this.emitTelemetry("pie-tool-backend-call-start", {
|
|
272
352
|
toolId: "tts",
|
|
273
353
|
backend: this.config.provider || "server",
|
|
274
354
|
operation: "fetch-synthesized-audio-asset"
|
|
275
355
|
});
|
|
276
|
-
let
|
|
277
|
-
this.config.includeAuthOnAssetFetch && this.config.authToken && (
|
|
278
|
-
let
|
|
279
|
-
if (
|
|
356
|
+
let r = {};
|
|
357
|
+
this.config.includeAuthOnAssetFetch && this.config.authToken && (r.Authorization = `Bearer ${this.config.authToken}`);
|
|
358
|
+
let i = l(e, this.config);
|
|
359
|
+
if (i === null) throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
280
360
|
toolId: "tts",
|
|
281
361
|
backend: this.config.provider || "server",
|
|
282
362
|
operation: "fetch-synthesized-audio-asset",
|
|
283
|
-
duration: Date.now() -
|
|
363
|
+
duration: Date.now() - n,
|
|
284
364
|
errorType: "TTSAssetInvalidUrl",
|
|
285
365
|
message: "TTS asset URL rejected (non-http(s) or malformed)"
|
|
286
366
|
}), Error("TTS asset URL rejected (non-http(s) or malformed)");
|
|
287
|
-
let
|
|
367
|
+
let a = u(i, this.config) ? r : d(r), o = await (async () => {
|
|
288
368
|
try {
|
|
289
|
-
return await fetch(
|
|
290
|
-
headers:
|
|
291
|
-
signal:
|
|
369
|
+
return await fetch(i.toString(), {
|
|
370
|
+
headers: a,
|
|
371
|
+
signal: t,
|
|
292
372
|
redirect: "error"
|
|
293
373
|
});
|
|
294
374
|
} catch (e) {
|
|
@@ -296,34 +376,34 @@ var r = (e) => {
|
|
|
296
376
|
toolId: "tts",
|
|
297
377
|
backend: this.config.provider || "server",
|
|
298
378
|
operation: "fetch-synthesized-audio-asset",
|
|
299
|
-
duration: Date.now() -
|
|
379
|
+
duration: Date.now() - n,
|
|
300
380
|
errorType: "TTSAssetNetworkError",
|
|
301
381
|
message: e instanceof Error ? e.message : String(e)
|
|
302
382
|
}), e;
|
|
303
383
|
}
|
|
304
384
|
})();
|
|
305
|
-
if (!
|
|
385
|
+
if (!o.ok) throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
306
386
|
toolId: "tts",
|
|
307
387
|
backend: this.config.provider || "server",
|
|
308
388
|
operation: "fetch-synthesized-audio-asset",
|
|
309
|
-
duration: Date.now() -
|
|
310
|
-
statusCode:
|
|
389
|
+
duration: Date.now() - n,
|
|
390
|
+
statusCode: o.status,
|
|
311
391
|
errorType: "TTSAssetFetchError",
|
|
312
|
-
message: `Failed to download synthesized audio (${
|
|
313
|
-
}), Error(`Failed to download synthesized audio (${
|
|
314
|
-
f = await
|
|
392
|
+
message: `Failed to download synthesized audio (${o.status})`
|
|
393
|
+
}), Error(`Failed to download synthesized audio (${o.status})`);
|
|
394
|
+
f = await o.blob(), await this.emitTelemetry("pie-tool-backend-call-success", {
|
|
315
395
|
toolId: "tts",
|
|
316
396
|
backend: this.config.provider || "server",
|
|
317
397
|
operation: "fetch-synthesized-audio-asset",
|
|
318
|
-
duration: Date.now() -
|
|
398
|
+
duration: Date.now() - n
|
|
319
399
|
});
|
|
320
400
|
}
|
|
321
|
-
let p = URL.createObjectURL(f), m = this.parseSpeechMarks(
|
|
401
|
+
let p = URL.createObjectURL(f), m = this.parseSpeechMarks(c.speechMarks);
|
|
322
402
|
return await this.emitTelemetry("pie-tool-backend-call-success", {
|
|
323
403
|
toolId: "tts",
|
|
324
404
|
backend: this.config.provider || "server",
|
|
325
405
|
operation: "synthesize-speech",
|
|
326
|
-
duration: Date.now() -
|
|
406
|
+
duration: Date.now() - r
|
|
327
407
|
}), {
|
|
328
408
|
audioUrl: p,
|
|
329
409
|
wordTimings: m
|
|
@@ -391,10 +471,10 @@ var r = (e) => {
|
|
|
391
471
|
updateSettings(e) {
|
|
392
472
|
e.rate !== void 0 && (this.config.rate = e.rate, this.config.providerOptions = {
|
|
393
473
|
...this.config.providerOptions || {},
|
|
394
|
-
speedRate:
|
|
474
|
+
speedRate: c(e.rate)
|
|
395
475
|
}), e.pitch !== void 0 && (this.config.pitch = e.pitch), e.voice !== void 0 && (this.config.voice = e.voice);
|
|
396
476
|
}
|
|
397
|
-
},
|
|
477
|
+
}, T = class {
|
|
398
478
|
providerId = "server-tts";
|
|
399
479
|
providerName = "Server TTS";
|
|
400
480
|
version = "1.0.0";
|
|
@@ -411,9 +491,9 @@ var r = (e) => {
|
|
|
411
491
|
async initialize(e) {
|
|
412
492
|
let t = e;
|
|
413
493
|
if (!t.apiEndpoint) throw Error("apiEndpoint is required for ServerTTSProvider");
|
|
414
|
-
this.config = t, this.telemetryReporter =
|
|
415
|
-
let n =
|
|
416
|
-
if (this.adapter =
|
|
494
|
+
this.config = t, this.telemetryReporter = f(t);
|
|
495
|
+
let n = v(t);
|
|
496
|
+
if (this.adapter = C[n], t.validateEndpoint) {
|
|
417
497
|
let e = Date.now();
|
|
418
498
|
if (await this.emitTelemetry("pie-tool-backend-call-start", {
|
|
419
499
|
toolId: "tts",
|
|
@@ -434,16 +514,16 @@ var r = (e) => {
|
|
|
434
514
|
duration: Date.now() - e
|
|
435
515
|
});
|
|
436
516
|
}
|
|
437
|
-
return new
|
|
517
|
+
return new w(t, this.adapter);
|
|
438
518
|
}
|
|
439
519
|
async testAPIAvailability() {
|
|
440
520
|
if (!this.config || !this.adapter) return !1;
|
|
441
521
|
try {
|
|
442
522
|
let e = { ...this.config.headers };
|
|
443
523
|
this.config.authToken && (e.Authorization = `Bearer ${this.config.authToken}`);
|
|
444
|
-
let t = new AbortController(), n = setTimeout(() => t.abort(), 5e3), r =
|
|
524
|
+
let t = new AbortController(), n = setTimeout(() => t.abort(), 5e3), r = b(this.config, this.adapter.id);
|
|
445
525
|
if (r === "none") return clearTimeout(n), !0;
|
|
446
|
-
let i = r === "voices" ?
|
|
526
|
+
let i = r === "voices" ? _(this.config) : this.adapter.resolveSynthesisUrl(this.config), a = r === "voices" ? "GET" : "OPTIONS";
|
|
447
527
|
try {
|
|
448
528
|
let r = await fetch(i, {
|
|
449
529
|
method: a,
|
|
@@ -470,7 +550,7 @@ var r = (e) => {
|
|
|
470
550
|
}
|
|
471
551
|
}
|
|
472
552
|
getCapabilities() {
|
|
473
|
-
let e = this.config ?
|
|
553
|
+
let e = this.config ? v(this.config) : "pie";
|
|
474
554
|
return {
|
|
475
555
|
supportsPause: !0,
|
|
476
556
|
supportsResume: !0,
|
|
@@ -478,8 +558,8 @@ var r = (e) => {
|
|
|
478
558
|
supportsVoiceSelection: !0,
|
|
479
559
|
supportsRateControl: !0,
|
|
480
560
|
supportsPitchControl: !1,
|
|
481
|
-
supportsSSML:
|
|
482
|
-
maxTextLength:
|
|
561
|
+
supportsSSML: h(this.config),
|
|
562
|
+
maxTextLength: p[e]
|
|
483
563
|
};
|
|
484
564
|
}
|
|
485
565
|
destroy() {
|
|
@@ -487,6 +567,6 @@ var r = (e) => {
|
|
|
487
567
|
}
|
|
488
568
|
};
|
|
489
569
|
//#endregion
|
|
490
|
-
export {
|
|
570
|
+
export { T as ServerTTSProvider };
|
|
491
571
|
|
|
492
|
-
//# sourceMappingURL=dist-
|
|
572
|
+
//# sourceMappingURL=dist-BaQdJU08.js.map
|