@pie-players/pie-section-player 0.3.20 → 0.3.22
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/{dist-BIgX-aC4-C5B4fLQK.js → dist-Bud4G4lv-DvJKILlA.js} +70 -52
- package/dist/{dist-BCuSaTvi.js → dist-C2B1t0Ov.js} +75 -57
- package/dist/pie-section-player.js +3227 -3115
- package/dist/{player-preload-C_CjM5hv.js → player-preload-DHibXasK.js} +1463 -1319
- package/dist/{tool-annotation-toolbar-BS_MjvXd.js → tool-annotation-toolbar-CltCGj49.js} +612 -608
- package/dist/utils/player-preload.js +1 -1
- package/package.json +10 -10
|
@@ -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"}
|
|
@@ -19,18 +19,34 @@ var b = (e) => {
|
|
|
19
19
|
const r = e.split(`
|
|
20
20
|
`).map((o) => o.trim()).filter(Boolean);
|
|
21
21
|
for (const o of r) try {
|
|
22
|
-
const s = JSON.parse(o),
|
|
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
23
|
i = Math.max(c + 1, i), t.push({
|
|
24
|
-
time:
|
|
25
|
-
type:
|
|
26
|
-
start:
|
|
24
|
+
time: h,
|
|
25
|
+
type: a,
|
|
26
|
+
start: m,
|
|
27
27
|
end: c,
|
|
28
|
-
value:
|
|
28
|
+
value: n
|
|
29
29
|
});
|
|
30
30
|
} catch {
|
|
31
31
|
}
|
|
32
32
|
return t;
|
|
33
|
-
}, M = {
|
|
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 = {
|
|
34
50
|
pie: {
|
|
35
51
|
id: "pie",
|
|
36
52
|
resolveSynthesisUrl: (e) => {
|
|
@@ -38,7 +54,7 @@ var b = (e) => {
|
|
|
38
54
|
return t === "rootPost" ? i : `${i}/synthesize`;
|
|
39
55
|
},
|
|
40
56
|
buildRequestBody: (e, t) => {
|
|
41
|
-
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,
|
|
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;
|
|
42
58
|
return {
|
|
43
59
|
text: e,
|
|
44
60
|
provider: t.provider || "polly",
|
|
@@ -48,7 +64,7 @@ var b = (e) => {
|
|
|
48
64
|
engine: r,
|
|
49
65
|
sampleRate: o,
|
|
50
66
|
format: s,
|
|
51
|
-
speechMarkTypes:
|
|
67
|
+
speechMarkTypes: a,
|
|
52
68
|
includeSpeechMarks: !0
|
|
53
69
|
};
|
|
54
70
|
},
|
|
@@ -81,25 +97,27 @@ var b = (e) => {
|
|
|
81
97
|
},
|
|
82
98
|
parseResponse: async (e, t, i, r) => {
|
|
83
99
|
const o = await e.json(), s = {};
|
|
84
|
-
if (t.includeAuthOnAssetFetch) for (const [n,
|
|
85
|
-
let
|
|
86
|
-
|
|
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) {
|
|
87
105
|
const n = await fetch(o.word, {
|
|
88
106
|
headers: s,
|
|
89
107
|
signal: r
|
|
90
108
|
});
|
|
91
|
-
n.ok && (
|
|
109
|
+
n.ok && (a = I(await n.text()));
|
|
92
110
|
}
|
|
93
111
|
return {
|
|
94
112
|
audio: {
|
|
95
113
|
kind: "url",
|
|
96
114
|
url: o.audioContent
|
|
97
115
|
},
|
|
98
|
-
speechMarks:
|
|
116
|
+
speechMarks: a
|
|
99
117
|
};
|
|
100
118
|
}
|
|
101
119
|
}
|
|
102
|
-
},
|
|
120
|
+
}, E = class {
|
|
103
121
|
constructor(e, t) {
|
|
104
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);
|
|
105
123
|
}
|
|
@@ -120,20 +138,20 @@ var b = (e) => {
|
|
|
120
138
|
return;
|
|
121
139
|
}
|
|
122
140
|
const s = this.config.rate || 1;
|
|
123
|
-
return this.wordTimings = o.map((
|
|
124
|
-
...
|
|
125
|
-
time:
|
|
126
|
-
})), new Promise((
|
|
127
|
-
const
|
|
128
|
-
this.currentAudio =
|
|
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 = () => {
|
|
129
147
|
this.pausedState = !1, this.onWordBoundary && this.wordTimings.length > 0 && this.startWordHighlighting();
|
|
130
|
-
},
|
|
131
|
-
this.stopWordHighlighting(), URL.revokeObjectURL(r), this.currentAudio = null, this.wordTimings = [],
|
|
132
|
-
},
|
|
133
|
-
this.stopWordHighlighting(), URL.revokeObjectURL(r), this.currentAudio = null, this.wordTimings = [], this.intentionallyStopped ?
|
|
134
|
-
},
|
|
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 = () => {
|
|
135
153
|
this.stopWordHighlighting(), this.pausedState = !0;
|
|
136
|
-
},
|
|
154
|
+
}, n.play().catch(h);
|
|
137
155
|
});
|
|
138
156
|
}
|
|
139
157
|
async synthesizeSpeech(e, t, i) {
|
|
@@ -148,12 +166,12 @@ var b = (e) => {
|
|
|
148
166
|
...this.config.headers
|
|
149
167
|
};
|
|
150
168
|
this.config.authToken && (o.Authorization = `Bearer ${this.config.authToken}`);
|
|
151
|
-
const s = this.adapter.resolveSynthesisUrl(this.config),
|
|
169
|
+
const s = this.adapter.resolveSynthesisUrl(this.config), a = this.adapter.buildRequestBody(e, this.config), h = await (async () => {
|
|
152
170
|
try {
|
|
153
171
|
return await fetch(s, {
|
|
154
172
|
method: "POST",
|
|
155
173
|
headers: o,
|
|
156
|
-
body: JSON.stringify(
|
|
174
|
+
body: JSON.stringify(a),
|
|
157
175
|
signal: t
|
|
158
176
|
});
|
|
159
177
|
} catch (c) {
|
|
@@ -167,24 +185,24 @@ var b = (e) => {
|
|
|
167
185
|
}), c;
|
|
168
186
|
}
|
|
169
187
|
})();
|
|
170
|
-
if (!
|
|
171
|
-
const c = await
|
|
188
|
+
if (!h.ok) {
|
|
189
|
+
const c = await h.json().catch(() => ({})), p = c.message || c.error?.message || `Server returned ${h.status}`;
|
|
172
190
|
throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
173
191
|
toolId: "tts",
|
|
174
192
|
backend: this.config.provider || "server",
|
|
175
193
|
operation: "synthesize-speech",
|
|
176
194
|
duration: Date.now() - r,
|
|
177
|
-
statusCode:
|
|
195
|
+
statusCode: h.status,
|
|
178
196
|
errorType: "TTSBackendRequestError",
|
|
179
|
-
message:
|
|
180
|
-
}), new Error(
|
|
197
|
+
message: p
|
|
198
|
+
}), new Error(p);
|
|
181
199
|
}
|
|
182
|
-
const
|
|
200
|
+
const n = await this.adapter.parseResponse(h, this.config, o, t);
|
|
183
201
|
if (i !== this.synthesisRunId || t.aborted) throw new Error("Synthesis superseded by a newer request");
|
|
184
202
|
let l;
|
|
185
|
-
if (
|
|
203
|
+
if (n.audio.kind === "base64") l = this.base64ToBlob(n.audio.data, n.audio.contentType);
|
|
186
204
|
else {
|
|
187
|
-
const c =
|
|
205
|
+
const c = n.audio.url, p = Date.now();
|
|
188
206
|
await this.emitTelemetry("pie-tool-backend-call-start", {
|
|
189
207
|
toolId: "tts",
|
|
190
208
|
backend: this.config.provider || "server",
|
|
@@ -192,7 +210,7 @@ var b = (e) => {
|
|
|
192
210
|
});
|
|
193
211
|
const f = {};
|
|
194
212
|
this.config.includeAuthOnAssetFetch && this.config.authToken && (f.Authorization = `Bearer ${this.config.authToken}`);
|
|
195
|
-
const
|
|
213
|
+
const g = await (async () => {
|
|
196
214
|
try {
|
|
197
215
|
return await fetch(c, {
|
|
198
216
|
headers: f,
|
|
@@ -203,37 +221,37 @@ var b = (e) => {
|
|
|
203
221
|
toolId: "tts",
|
|
204
222
|
backend: this.config.provider || "server",
|
|
205
223
|
operation: "fetch-synthesized-audio-asset",
|
|
206
|
-
duration: Date.now() -
|
|
224
|
+
duration: Date.now() - p,
|
|
207
225
|
errorType: "TTSAssetNetworkError",
|
|
208
226
|
message: y instanceof Error ? y.message : String(y)
|
|
209
227
|
}), y;
|
|
210
228
|
}
|
|
211
229
|
})();
|
|
212
|
-
if (!
|
|
230
|
+
if (!g.ok) throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
213
231
|
toolId: "tts",
|
|
214
232
|
backend: this.config.provider || "server",
|
|
215
233
|
operation: "fetch-synthesized-audio-asset",
|
|
216
|
-
duration: Date.now() -
|
|
217
|
-
statusCode:
|
|
234
|
+
duration: Date.now() - p,
|
|
235
|
+
statusCode: g.status,
|
|
218
236
|
errorType: "TTSAssetFetchError",
|
|
219
|
-
message: `Failed to download synthesized audio (${
|
|
220
|
-
}), /* @__PURE__ */ new Error(`Failed to download synthesized audio (${
|
|
221
|
-
l = await
|
|
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", {
|
|
222
240
|
toolId: "tts",
|
|
223
241
|
backend: this.config.provider || "server",
|
|
224
242
|
operation: "fetch-synthesized-audio-asset",
|
|
225
|
-
duration: Date.now() -
|
|
243
|
+
duration: Date.now() - p
|
|
226
244
|
});
|
|
227
245
|
}
|
|
228
|
-
const
|
|
246
|
+
const u = URL.createObjectURL(l), m = this.parseSpeechMarks(n.speechMarks);
|
|
229
247
|
return await this.emitTelemetry("pie-tool-backend-call-success", {
|
|
230
248
|
toolId: "tts",
|
|
231
249
|
backend: this.config.provider || "server",
|
|
232
250
|
operation: "synthesize-speech",
|
|
233
251
|
duration: Date.now() - r
|
|
234
252
|
}), {
|
|
235
|
-
audioUrl:
|
|
236
|
-
wordTimings:
|
|
253
|
+
audioUrl: u,
|
|
254
|
+
wordTimings: m
|
|
237
255
|
};
|
|
238
256
|
}
|
|
239
257
|
base64ToBlob(e, t) {
|
|
@@ -310,7 +328,7 @@ var b = (e) => {
|
|
|
310
328
|
async initialize(e) {
|
|
311
329
|
const t = e;
|
|
312
330
|
if (!t.apiEndpoint) throw new Error("apiEndpoint is required for ServerTTSProvider");
|
|
313
|
-
if (this.config = t, this.telemetryReporter = b(t), this.adapter =
|
|
331
|
+
if (this.config = t, this.telemetryReporter = b(t), this.adapter = P[w(t)], t.validateEndpoint) {
|
|
314
332
|
const i = Date.now();
|
|
315
333
|
if (await this.emitTelemetry("pie-tool-backend-call-start", {
|
|
316
334
|
toolId: "tts",
|
|
@@ -331,7 +349,7 @@ var b = (e) => {
|
|
|
331
349
|
duration: Date.now() - i
|
|
332
350
|
});
|
|
333
351
|
}
|
|
334
|
-
return new
|
|
352
|
+
return new E(t, this.adapter);
|
|
335
353
|
}
|
|
336
354
|
async testAPIAvailability() {
|
|
337
355
|
if (!this.config || !this.adapter) return !1;
|
|
@@ -342,12 +360,12 @@ var b = (e) => {
|
|
|
342
360
|
if (r === "none") return clearTimeout(i), !0;
|
|
343
361
|
const o = r === "voices" ? k(this.config) : this.adapter.resolveSynthesisUrl(this.config), s = r === "voices" ? "GET" : "OPTIONS";
|
|
344
362
|
try {
|
|
345
|
-
const
|
|
363
|
+
const a = await fetch(o, {
|
|
346
364
|
method: s,
|
|
347
365
|
headers: e,
|
|
348
366
|
signal: t.signal
|
|
349
367
|
});
|
|
350
|
-
return clearTimeout(i),
|
|
368
|
+
return clearTimeout(i), a.ok || a.status === 405;
|
|
351
369
|
} catch {
|
|
352
370
|
return clearTimeout(i), !1;
|
|
353
371
|
}
|
|
@@ -19,18 +19,34 @@ var b = (t) => {
|
|
|
19
19
|
const i = t.split(`
|
|
20
20
|
`).map((o) => o.trim()).filter(Boolean);
|
|
21
21
|
for (const o of i) try {
|
|
22
|
-
const s = JSON.parse(o),
|
|
22
|
+
const s = JSON.parse(o), a = typeof s.type == "string" ? s.type : "word", d = typeof s.time == "number" && Number.isFinite(s.time) ? s.time : 0, n = typeof s.value == "string" ? s.value : "", c = typeof s.start == "number" && Number.isFinite(s.start) ? s.start : null, u = typeof s.end == "number" && Number.isFinite(s.end) ? s.end : null, y = c ?? r, l = u ?? y + Math.max(1, n.length || String(s.value || "").length);
|
|
23
23
|
r = Math.max(l + 1, r), e.push({
|
|
24
|
-
time:
|
|
25
|
-
type:
|
|
26
|
-
start:
|
|
24
|
+
time: d,
|
|
25
|
+
type: a,
|
|
26
|
+
start: y,
|
|
27
27
|
end: l,
|
|
28
|
-
value:
|
|
28
|
+
value: n
|
|
29
29
|
});
|
|
30
30
|
} catch {
|
|
31
31
|
}
|
|
32
32
|
return e;
|
|
33
|
-
}, M = {
|
|
33
|
+
}, M = (t) => {
|
|
34
|
+
if (!Array.isArray(t)) return [];
|
|
35
|
+
const e = [];
|
|
36
|
+
let r = 0;
|
|
37
|
+
for (const i of t) {
|
|
38
|
+
if (!i || typeof i != "object") continue;
|
|
39
|
+
const o = typeof i.type == "string" ? i.type : "word", s = typeof i.time == "number" && Number.isFinite(i.time) ? i.time : 0, a = typeof i.value == "string" ? i.value : "", d = typeof i.start == "number" && Number.isFinite(i.start) ? i.start : null, n = typeof i.end == "number" && Number.isFinite(i.end) ? i.end : null, c = d ?? r, u = n ?? c + Math.max(1, a.length || 1);
|
|
40
|
+
r = Math.max(r, u + 1), e.push({
|
|
41
|
+
time: s,
|
|
42
|
+
type: o,
|
|
43
|
+
start: c,
|
|
44
|
+
end: u,
|
|
45
|
+
value: a
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return e.sort((i, o) => i.time !== o.time ? i.time - o.time : i.start !== o.start ? i.start - o.start : i.end - o.end);
|
|
49
|
+
}, E = {
|
|
34
50
|
pie: {
|
|
35
51
|
id: "pie",
|
|
36
52
|
resolveSynthesisUrl: (t) => {
|
|
@@ -38,7 +54,7 @@ var b = (t) => {
|
|
|
38
54
|
return e === "rootPost" ? r : `${r}/synthesize`;
|
|
39
55
|
},
|
|
40
56
|
buildRequestBody: (t, e) => {
|
|
41
|
-
const r = e.providerOptions || {}, i = typeof e.engine == "string" ? e.engine : typeof r.engine == "string" ? r.engine : void 0, o = typeof r.sampleRate == "number" && Number.isFinite(r.sampleRate) ? r.sampleRate : void 0, s = r.format === "mp3" || r.format === "ogg" || r.format === "pcm" ? r.format : void 0,
|
|
57
|
+
const r = e.providerOptions || {}, i = typeof e.engine == "string" ? e.engine : typeof r.engine == "string" ? r.engine : void 0, o = typeof r.sampleRate == "number" && Number.isFinite(r.sampleRate) ? r.sampleRate : void 0, s = r.format === "mp3" || r.format === "ogg" || r.format === "pcm" ? r.format : void 0, a = Array.isArray(r.speechMarkTypes) ? r.speechMarkTypes.filter((d) => d === "word" || d === "sentence" || d === "ssml") : void 0;
|
|
42
58
|
return {
|
|
43
59
|
text: t,
|
|
44
60
|
provider: e.provider || "polly",
|
|
@@ -48,7 +64,7 @@ var b = (t) => {
|
|
|
48
64
|
engine: i,
|
|
49
65
|
sampleRate: o,
|
|
50
66
|
format: s,
|
|
51
|
-
speechMarkTypes:
|
|
67
|
+
speechMarkTypes: a,
|
|
52
68
|
includeSpeechMarks: !0
|
|
53
69
|
};
|
|
54
70
|
},
|
|
@@ -82,25 +98,27 @@ var b = (t) => {
|
|
|
82
98
|
parseResponse: async (t, e, r, i) => {
|
|
83
99
|
const o = await t.json(), s = {};
|
|
84
100
|
if (e.includeAuthOnAssetFetch)
|
|
85
|
-
for (const [n,
|
|
86
|
-
let
|
|
87
|
-
|
|
101
|
+
for (const [n, c] of Object.entries(r)) n.toLowerCase() === "authorization" && (s[n] = c);
|
|
102
|
+
let a = [];
|
|
103
|
+
const d = M(o.speechMarks);
|
|
104
|
+
if (d.length > 0) a = d;
|
|
105
|
+
else if (typeof o.word == "string" && o.word.length > 0) {
|
|
88
106
|
const n = await fetch(o.word, {
|
|
89
107
|
headers: s,
|
|
90
108
|
signal: i
|
|
91
109
|
});
|
|
92
|
-
n.ok && (
|
|
110
|
+
n.ok && (a = I(await n.text()));
|
|
93
111
|
}
|
|
94
112
|
return {
|
|
95
113
|
audio: {
|
|
96
114
|
kind: "url",
|
|
97
115
|
url: o.audioContent
|
|
98
116
|
},
|
|
99
|
-
speechMarks:
|
|
117
|
+
speechMarks: a
|
|
100
118
|
};
|
|
101
119
|
}
|
|
102
120
|
}
|
|
103
|
-
},
|
|
121
|
+
}, P = class {
|
|
104
122
|
constructor(t, e) {
|
|
105
123
|
h(this, "config", void 0), h(this, "adapter", void 0), h(this, "currentAudio", null), h(this, "pausedState", !1), h(this, "wordTimings", []), h(this, "highlightInterval", null), h(this, "intentionallyStopped", !1), h(this, "activeSynthesisController", null), h(this, "synthesisRunId", 0), h(this, "telemetryReporter", void 0), h(this, "onWordBoundary", void 0), this.config = t, this.adapter = e, this.telemetryReporter = b(t);
|
|
106
124
|
}
|
|
@@ -121,20 +139,20 @@ var b = (t) => {
|
|
|
121
139
|
return;
|
|
122
140
|
}
|
|
123
141
|
const s = this.config.rate || 1;
|
|
124
|
-
return this.wordTimings = o.map((
|
|
125
|
-
...
|
|
126
|
-
time:
|
|
127
|
-
})), new Promise((
|
|
128
|
-
const
|
|
129
|
-
this.currentAudio =
|
|
142
|
+
return this.wordTimings = o.map((a) => ({
|
|
143
|
+
...a,
|
|
144
|
+
time: a.time / s
|
|
145
|
+
})), new Promise((a, d) => {
|
|
146
|
+
const n = new Audio(i);
|
|
147
|
+
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 = () => {
|
|
130
148
|
this.pausedState = !1, this.onWordBoundary && this.wordTimings.length > 0 && this.startWordHighlighting();
|
|
131
|
-
},
|
|
132
|
-
this.stopWordHighlighting(), URL.revokeObjectURL(i), this.currentAudio = null, this.wordTimings = [],
|
|
133
|
-
},
|
|
134
|
-
this.stopWordHighlighting(), URL.revokeObjectURL(i), this.currentAudio = null, this.wordTimings = [], this.intentionallyStopped ?
|
|
135
|
-
},
|
|
149
|
+
}, n.onended = () => {
|
|
150
|
+
this.stopWordHighlighting(), URL.revokeObjectURL(i), this.currentAudio = null, this.wordTimings = [], a();
|
|
151
|
+
}, n.onerror = (c) => {
|
|
152
|
+
this.stopWordHighlighting(), URL.revokeObjectURL(i), this.currentAudio = null, this.wordTimings = [], this.intentionallyStopped ? a() : d(/* @__PURE__ */ new Error("Failed to play audio from server"));
|
|
153
|
+
}, n.onpause = () => {
|
|
136
154
|
this.stopWordHighlighting(), this.pausedState = !0;
|
|
137
|
-
},
|
|
155
|
+
}, n.play().catch(d);
|
|
138
156
|
});
|
|
139
157
|
}
|
|
140
158
|
async synthesizeSpeech(t, e, r) {
|
|
@@ -149,12 +167,12 @@ var b = (t) => {
|
|
|
149
167
|
...this.config.headers
|
|
150
168
|
};
|
|
151
169
|
this.config.authToken && (o.Authorization = `Bearer ${this.config.authToken}`);
|
|
152
|
-
const s = this.adapter.resolveSynthesisUrl(this.config),
|
|
170
|
+
const s = this.adapter.resolveSynthesisUrl(this.config), a = this.adapter.buildRequestBody(t, this.config), d = await (async () => {
|
|
153
171
|
try {
|
|
154
172
|
return await fetch(s, {
|
|
155
173
|
method: "POST",
|
|
156
174
|
headers: o,
|
|
157
|
-
body: JSON.stringify(
|
|
175
|
+
body: JSON.stringify(a),
|
|
158
176
|
signal: e
|
|
159
177
|
});
|
|
160
178
|
} catch (l) {
|
|
@@ -168,24 +186,24 @@ var b = (t) => {
|
|
|
168
186
|
}), l;
|
|
169
187
|
}
|
|
170
188
|
})();
|
|
171
|
-
if (!
|
|
172
|
-
const l = await
|
|
189
|
+
if (!d.ok) {
|
|
190
|
+
const l = await d.json().catch(() => ({})), p = l.message || l.error?.message || `Server returned ${d.status}`;
|
|
173
191
|
throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
174
192
|
toolId: "tts",
|
|
175
193
|
backend: this.config.provider || "server",
|
|
176
194
|
operation: "synthesize-speech",
|
|
177
195
|
duration: Date.now() - i,
|
|
178
|
-
statusCode:
|
|
196
|
+
statusCode: d.status,
|
|
179
197
|
errorType: "TTSBackendRequestError",
|
|
180
|
-
message:
|
|
181
|
-
}), new Error(
|
|
198
|
+
message: p
|
|
199
|
+
}), new Error(p);
|
|
182
200
|
}
|
|
183
|
-
const
|
|
201
|
+
const n = await this.adapter.parseResponse(d, this.config, o, e);
|
|
184
202
|
if (r !== this.synthesisRunId || e.aborted) throw new Error("Synthesis superseded by a newer request");
|
|
185
203
|
let c;
|
|
186
|
-
if (
|
|
204
|
+
if (n.audio.kind === "base64") c = this.base64ToBlob(n.audio.data, n.audio.contentType);
|
|
187
205
|
else {
|
|
188
|
-
const l =
|
|
206
|
+
const l = n.audio.url, p = Date.now();
|
|
189
207
|
await this.emitTelemetry("pie-tool-backend-call-start", {
|
|
190
208
|
toolId: "tts",
|
|
191
209
|
backend: this.config.provider || "server",
|
|
@@ -193,49 +211,49 @@ var b = (t) => {
|
|
|
193
211
|
});
|
|
194
212
|
const f = {};
|
|
195
213
|
this.config.includeAuthOnAssetFetch && this.config.authToken && (f.Authorization = `Bearer ${this.config.authToken}`);
|
|
196
|
-
const
|
|
214
|
+
const m = await (async () => {
|
|
197
215
|
try {
|
|
198
216
|
return await fetch(l, {
|
|
199
217
|
headers: f,
|
|
200
218
|
signal: e
|
|
201
219
|
});
|
|
202
|
-
} catch (
|
|
220
|
+
} catch (g) {
|
|
203
221
|
throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
204
222
|
toolId: "tts",
|
|
205
223
|
backend: this.config.provider || "server",
|
|
206
224
|
operation: "fetch-synthesized-audio-asset",
|
|
207
|
-
duration: Date.now() -
|
|
225
|
+
duration: Date.now() - p,
|
|
208
226
|
errorType: "TTSAssetNetworkError",
|
|
209
|
-
message:
|
|
210
|
-
}),
|
|
227
|
+
message: g instanceof Error ? g.message : String(g)
|
|
228
|
+
}), g;
|
|
211
229
|
}
|
|
212
230
|
})();
|
|
213
|
-
if (!
|
|
231
|
+
if (!m.ok)
|
|
214
232
|
throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
215
233
|
toolId: "tts",
|
|
216
234
|
backend: this.config.provider || "server",
|
|
217
235
|
operation: "fetch-synthesized-audio-asset",
|
|
218
|
-
duration: Date.now() -
|
|
219
|
-
statusCode:
|
|
236
|
+
duration: Date.now() - p,
|
|
237
|
+
statusCode: m.status,
|
|
220
238
|
errorType: "TTSAssetFetchError",
|
|
221
|
-
message: `Failed to download synthesized audio (${
|
|
222
|
-
}), new Error(`Failed to download synthesized audio (${
|
|
223
|
-
c = await
|
|
239
|
+
message: `Failed to download synthesized audio (${m.status})`
|
|
240
|
+
}), new Error(`Failed to download synthesized audio (${m.status})`);
|
|
241
|
+
c = await m.blob(), await this.emitTelemetry("pie-tool-backend-call-success", {
|
|
224
242
|
toolId: "tts",
|
|
225
243
|
backend: this.config.provider || "server",
|
|
226
244
|
operation: "fetch-synthesized-audio-asset",
|
|
227
|
-
duration: Date.now() -
|
|
245
|
+
duration: Date.now() - p
|
|
228
246
|
});
|
|
229
247
|
}
|
|
230
|
-
const
|
|
248
|
+
const u = URL.createObjectURL(c), y = this.parseSpeechMarks(n.speechMarks);
|
|
231
249
|
return await this.emitTelemetry("pie-tool-backend-call-success", {
|
|
232
250
|
toolId: "tts",
|
|
233
251
|
backend: this.config.provider || "server",
|
|
234
252
|
operation: "synthesize-speech",
|
|
235
253
|
duration: Date.now() - i
|
|
236
254
|
}), {
|
|
237
|
-
audioUrl:
|
|
238
|
-
wordTimings:
|
|
255
|
+
audioUrl: u,
|
|
256
|
+
wordTimings: y
|
|
239
257
|
};
|
|
240
258
|
}
|
|
241
259
|
base64ToBlob(t, e) {
|
|
@@ -298,7 +316,7 @@ var b = (t) => {
|
|
|
298
316
|
updateSettings(t) {
|
|
299
317
|
t.rate !== void 0 && (this.config.rate = t.rate, this.currentAudio && (this.currentAudio.playbackRate = Math.max(0.25, Math.min(4, t.rate)))), t.pitch !== void 0 && (this.config.pitch = t.pitch), t.voice !== void 0 && (this.config.voice = t.voice);
|
|
300
318
|
}
|
|
301
|
-
},
|
|
319
|
+
}, B = class {
|
|
302
320
|
constructor() {
|
|
303
321
|
h(this, "providerId", "server-tts"), h(this, "providerName", "Server TTS"), h(this, "version", "1.0.0"), h(this, "config", null), h(this, "adapter", null), h(this, "telemetryReporter", void 0);
|
|
304
322
|
}
|
|
@@ -312,7 +330,7 @@ var b = (t) => {
|
|
|
312
330
|
async initialize(t) {
|
|
313
331
|
const e = t;
|
|
314
332
|
if (!e.apiEndpoint) throw new Error("apiEndpoint is required for ServerTTSProvider");
|
|
315
|
-
if (this.config = e, this.telemetryReporter = b(e), this.adapter =
|
|
333
|
+
if (this.config = e, this.telemetryReporter = b(e), this.adapter = E[T(e)], e.validateEndpoint) {
|
|
316
334
|
const r = Date.now();
|
|
317
335
|
if (await this.emitTelemetry("pie-tool-backend-call-start", {
|
|
318
336
|
toolId: "tts",
|
|
@@ -334,7 +352,7 @@ var b = (t) => {
|
|
|
334
352
|
duration: Date.now() - r
|
|
335
353
|
});
|
|
336
354
|
}
|
|
337
|
-
return new
|
|
355
|
+
return new P(e, this.adapter);
|
|
338
356
|
}
|
|
339
357
|
async testAPIAvailability() {
|
|
340
358
|
if (!this.config || !this.adapter) return !1;
|
|
@@ -346,12 +364,12 @@ var b = (t) => {
|
|
|
346
364
|
return clearTimeout(r), !0;
|
|
347
365
|
const o = i === "voices" ? k(this.config) : this.adapter.resolveSynthesisUrl(this.config), s = i === "voices" ? "GET" : "OPTIONS";
|
|
348
366
|
try {
|
|
349
|
-
const
|
|
367
|
+
const a = await fetch(o, {
|
|
350
368
|
method: s,
|
|
351
369
|
headers: t,
|
|
352
370
|
signal: e.signal
|
|
353
371
|
});
|
|
354
|
-
return clearTimeout(r),
|
|
372
|
+
return clearTimeout(r), a.ok || a.status === 405;
|
|
355
373
|
} catch {
|
|
356
374
|
return clearTimeout(r), !1;
|
|
357
375
|
}
|
|
@@ -389,5 +407,5 @@ var b = (t) => {
|
|
|
389
407
|
}
|
|
390
408
|
};
|
|
391
409
|
export {
|
|
392
|
-
|
|
410
|
+
B as ServerTTSProvider
|
|
393
411
|
};
|