ssml-builder-js 2.12.0 → 2.13.0

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.
@@ -0,0 +1,1745 @@
1
+ // packages/ssml-core/dist/index.mjs
2
+ var __typeError = (msg) => {
3
+ throw TypeError(msg);
4
+ };
5
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
6
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
7
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
8
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
9
+ var SYNTHESIS_NAMESPACE = "http://www.w3.org/2001/10/synthesis";
10
+ var MSTTS_NAMESPACE = "http://www.w3.org/2001/mstts";
11
+ var DEFAULT_SSML_VERSION = "1.0";
12
+ var DEFAULT_SSML_LANGUAGE = "en-US";
13
+ var MAX_NESTING_DEPTH = 1e3;
14
+ var XML_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_.:-]*$/;
15
+ var MSTTS_TAG_PREFIX = "mstts:";
16
+ var SSML_TAGS = {
17
+ SPEAK: "speak",
18
+ VOICE: "voice",
19
+ PROSODY: "prosody",
20
+ BREAK: "break",
21
+ EXPRESS_AS: "express-as",
22
+ EXPRESS_AS_CAMEL: "expressAs",
23
+ MSTTS_EXPRESS_AS: "mstts:express-as",
24
+ SAY_AS: "say-as",
25
+ SAY_AS_CAMEL: "sayAs",
26
+ PHONEME: "phoneme",
27
+ EMPHASIS: "emphasis",
28
+ AUDIO: "audio",
29
+ SUB: "sub",
30
+ LANG: "lang",
31
+ MARK: "mark",
32
+ BOOKMARK: "bookmark",
33
+ LEXICON: "lexicon",
34
+ PARAGRAPH: "p",
35
+ SENTENCE: "s",
36
+ WORD: "w",
37
+ MSTTS_SILENCE: "mstts:silence",
38
+ SILENCE: "silence",
39
+ MSTTS_VISEME: "mstts:viseme",
40
+ VISEME: "viseme",
41
+ MSTTS_AUDIO_DURATION: "mstts:audioduration",
42
+ MSTTS_DIALOG: "mstts:dialog",
43
+ MSTTS_TURN: "mstts:turn",
44
+ MSTTS_BACKGROUND_AUDIO: "mstts:backgroundaudio",
45
+ MSTTS_TTS_EMBEDDING: "mstts:ttsembedding",
46
+ MSTTS_EMBEDDING: "mstts:embedding",
47
+ MSTTS_VOICE_CONVERSION: "mstts:voiceconversion"
48
+ };
49
+ var SSML_ATTRS = {
50
+ VERSION: "version",
51
+ XMLNS: "xmlns",
52
+ XML_LANG: "xml:lang",
53
+ LANG: "lang",
54
+ MSTTS_XMLNS: "xmlns:mstts",
55
+ NAME: "name",
56
+ VOICE: "voice",
57
+ SPEAKER: "speaker",
58
+ EFFECT: "effect",
59
+ RATE: "rate",
60
+ PITCH: "pitch",
61
+ VOLUME: "volume",
62
+ CONTOUR: "contour",
63
+ RANGE: "range",
64
+ TIME: "time",
65
+ STRENGTH: "strength",
66
+ STYLE: "style",
67
+ STYLE_DEGREE: "styledegree",
68
+ STYLE_DEGREE_CAMEL: "styleDegree",
69
+ STYLE_DEGREE_HYPHEN: "style-degree",
70
+ ROLE: "role",
71
+ INTERPRET_AS: "interpret-as",
72
+ FORMAT: "format",
73
+ DETAIL: "detail",
74
+ ALPHABET: "alphabet",
75
+ PH: "ph",
76
+ LEVEL: "level",
77
+ SRC: "src",
78
+ DESC: "desc",
79
+ CLIP_BEGIN: "clipBegin",
80
+ CLIP_END: "clipEnd",
81
+ SPEED: "speed",
82
+ REPEAT_COUNT: "repeatCount",
83
+ REPEAT_DURATION: "repeatDuration",
84
+ SOUND_LEVEL: "soundLevel",
85
+ ALIAS: "alias",
86
+ MARK: "mark",
87
+ URI: "uri",
88
+ ID: "id",
89
+ MODEL: "model",
90
+ PROFILE: "profile",
91
+ URL: "url",
92
+ SPEAKER_PROFILE_ID: "speakerProfileId",
93
+ TYPE: "type",
94
+ VALUE: "value",
95
+ FADE_IN: "fadein",
96
+ FADE_OUT: "fadeout"
97
+ };
98
+ function escapeText(value) {
99
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
100
+ }
101
+ function escapeAttribute(value) {
102
+ return escapeText(value).replace(/"/g, "&quot;").replace(/'/g, "&apos;");
103
+ }
104
+ function addAttribute(attributes, name, value) {
105
+ if (value !== void 0) {
106
+ attributes[name] = value;
107
+ }
108
+ }
109
+ function getAttributes(element) {
110
+ const attributes = {
111
+ ...element.attributes ?? {}
112
+ };
113
+ switch (element.type) {
114
+ case SSML_TAGS.VOICE:
115
+ addAttribute(attributes, SSML_ATTRS.NAME, element.name);
116
+ addAttribute(attributes, SSML_ATTRS.EFFECT, element.effect);
117
+ break;
118
+ case SSML_TAGS.PROSODY:
119
+ addAttribute(attributes, SSML_ATTRS.RATE, element.rate);
120
+ addAttribute(attributes, SSML_ATTRS.PITCH, element.pitch);
121
+ addAttribute(attributes, SSML_ATTRS.VOLUME, element.volume);
122
+ addAttribute(attributes, SSML_ATTRS.CONTOUR, element.contour);
123
+ addAttribute(attributes, SSML_ATTRS.RANGE, element.range);
124
+ break;
125
+ case SSML_TAGS.BREAK:
126
+ addAttribute(attributes, SSML_ATTRS.TIME, element.time);
127
+ addAttribute(attributes, SSML_ATTRS.STRENGTH, element.strength);
128
+ break;
129
+ case SSML_TAGS.EXPRESS_AS:
130
+ case SSML_TAGS.EXPRESS_AS_CAMEL:
131
+ case SSML_TAGS.MSTTS_EXPRESS_AS:
132
+ addAttribute(attributes, SSML_ATTRS.STYLE, element.style);
133
+ addAttribute(attributes, SSML_ATTRS.STYLE_DEGREE, element.styleDegree);
134
+ addAttribute(attributes, SSML_ATTRS.ROLE, element.role);
135
+ break;
136
+ case SSML_TAGS.SAY_AS:
137
+ case SSML_TAGS.SAY_AS_CAMEL:
138
+ addAttribute(attributes, SSML_ATTRS.INTERPRET_AS, element.interpretAs);
139
+ addAttribute(attributes, SSML_ATTRS.FORMAT, element.format);
140
+ addAttribute(attributes, SSML_ATTRS.DETAIL, element.detail);
141
+ break;
142
+ case SSML_TAGS.PHONEME:
143
+ addAttribute(attributes, SSML_ATTRS.ALPHABET, element.alphabet);
144
+ addAttribute(attributes, SSML_ATTRS.PH, element.ph);
145
+ break;
146
+ case SSML_TAGS.EMPHASIS:
147
+ addAttribute(attributes, SSML_ATTRS.LEVEL, element.level);
148
+ break;
149
+ case SSML_TAGS.AUDIO:
150
+ addAttribute(attributes, SSML_ATTRS.SRC, element.src);
151
+ addAttribute(attributes, SSML_ATTRS.DESC, element.desc);
152
+ addAttribute(attributes, SSML_ATTRS.CLIP_BEGIN, element.clipBegin);
153
+ addAttribute(attributes, SSML_ATTRS.CLIP_END, element.clipEnd);
154
+ addAttribute(attributes, SSML_ATTRS.SPEED, element.speed);
155
+ addAttribute(attributes, SSML_ATTRS.REPEAT_COUNT, element.repeatCount);
156
+ addAttribute(attributes, SSML_ATTRS.REPEAT_DURATION, element.repeatDuration);
157
+ addAttribute(attributes, SSML_ATTRS.SOUND_LEVEL, element.soundLevel);
158
+ break;
159
+ case SSML_TAGS.SUB:
160
+ addAttribute(attributes, SSML_ATTRS.ALIAS, element.alias);
161
+ break;
162
+ case SSML_TAGS.LANG:
163
+ addAttribute(attributes, SSML_ATTRS.XML_LANG, element.lang);
164
+ break;
165
+ case SSML_TAGS.MARK:
166
+ addAttribute(attributes, SSML_ATTRS.NAME, element.name);
167
+ break;
168
+ case SSML_TAGS.BOOKMARK:
169
+ addAttribute(attributes, SSML_ATTRS.MARK, element.mark);
170
+ break;
171
+ case SSML_TAGS.LEXICON:
172
+ addAttribute(attributes, SSML_ATTRS.URI, element.uri);
173
+ break;
174
+ case SSML_TAGS.MSTTS_SILENCE:
175
+ case SSML_TAGS.SILENCE:
176
+ addAttribute(attributes, SSML_ATTRS.TYPE, element.typeValue ?? element.silenceType);
177
+ addAttribute(attributes, SSML_ATTRS.VALUE, element.value);
178
+ break;
179
+ case SSML_TAGS.MSTTS_VISEME:
180
+ case SSML_TAGS.VISEME:
181
+ addAttribute(attributes, SSML_ATTRS.TYPE, element.typeValue ?? element.visemeType);
182
+ break;
183
+ case SSML_TAGS.MSTTS_AUDIO_DURATION:
184
+ addAttribute(attributes, SSML_ATTRS.VALUE, element.value);
185
+ break;
186
+ case SSML_TAGS.MSTTS_TURN:
187
+ addAttribute(attributes, SSML_ATTRS.VOICE, element.voice);
188
+ addAttribute(attributes, SSML_ATTRS.SPEAKER, element.speaker);
189
+ break;
190
+ case SSML_TAGS.MSTTS_BACKGROUND_AUDIO:
191
+ addAttribute(attributes, SSML_ATTRS.SRC, element.src);
192
+ addAttribute(attributes, SSML_ATTRS.VOLUME, element.volume);
193
+ addAttribute(attributes, SSML_ATTRS.FADE_IN, element.fadeIn ?? element.fadein);
194
+ addAttribute(attributes, SSML_ATTRS.FADE_OUT, element.fadeOut ?? element.fadeout);
195
+ break;
196
+ case SSML_TAGS.MSTTS_DIALOG:
197
+ break;
198
+ case SSML_TAGS.MSTTS_TTS_EMBEDDING:
199
+ addAttribute(attributes, SSML_ATTRS.SPEAKER_PROFILE_ID, element.speakerProfileId);
200
+ break;
201
+ case SSML_TAGS.MSTTS_EMBEDDING:
202
+ addAttribute(attributes, SSML_ATTRS.ID, element.id);
203
+ addAttribute(attributes, SSML_ATTRS.SPEAKER_PROFILE_ID, element.speakerProfileId);
204
+ break;
205
+ case SSML_TAGS.MSTTS_VOICE_CONVERSION:
206
+ addAttribute(attributes, SSML_ATTRS.URL, element.url);
207
+ addAttribute(attributes, SSML_ATTRS.PROFILE, element.profile);
208
+ addAttribute(attributes, SSML_ATTRS.SPEAKER_PROFILE_ID, element.speakerProfileId);
209
+ break;
210
+ case SSML_TAGS.PARAGRAPH:
211
+ case SSML_TAGS.SENTENCE:
212
+ case SSML_TAGS.WORD:
213
+ case "element":
214
+ case "custom":
215
+ break;
216
+ }
217
+ return attributes;
218
+ }
219
+ function getTagName(element) {
220
+ switch (element.type) {
221
+ case SSML_TAGS.EXPRESS_AS:
222
+ case SSML_TAGS.EXPRESS_AS_CAMEL:
223
+ case SSML_TAGS.MSTTS_EXPRESS_AS:
224
+ return SSML_TAGS.MSTTS_EXPRESS_AS;
225
+ case SSML_TAGS.SAY_AS:
226
+ case SSML_TAGS.SAY_AS_CAMEL:
227
+ return SSML_TAGS.SAY_AS;
228
+ case SSML_TAGS.SILENCE:
229
+ case SSML_TAGS.MSTTS_SILENCE:
230
+ return SSML_TAGS.MSTTS_SILENCE;
231
+ case SSML_TAGS.VISEME:
232
+ case SSML_TAGS.MSTTS_VISEME:
233
+ return SSML_TAGS.MSTTS_VISEME;
234
+ case SSML_TAGS.MSTTS_AUDIO_DURATION:
235
+ return SSML_TAGS.MSTTS_AUDIO_DURATION;
236
+ case "element":
237
+ case "custom":
238
+ return element.name;
239
+ default:
240
+ return element.type;
241
+ }
242
+ }
243
+ function getChildren(element) {
244
+ return element.children ?? [];
245
+ }
246
+ function validateName(name, kind) {
247
+ if (!XML_NAME_PATTERN.test(name)) {
248
+ throw new Error(`Invalid XML ${kind} name: ${name}`);
249
+ }
250
+ }
251
+ function serializeAttributes(attributes) {
252
+ return Object.entries(attributes).map(([name, value]) => {
253
+ validateName(name, "attribute");
254
+ return ` ${name}="${escapeAttribute(String(value))}"`;
255
+ }).join("");
256
+ }
257
+ function serializeNode(node) {
258
+ if (typeof node === "string") {
259
+ return escapeText(node);
260
+ }
261
+ if (node.type === "text") {
262
+ return escapeText(node.value);
263
+ }
264
+ const tagName = getTagName(node);
265
+ validateName(tagName, "element");
266
+ const attributes = serializeAttributes(getAttributes(node));
267
+ const children = getChildren(node);
268
+ if (children.length === 0) {
269
+ return `<${tagName}${attributes}/>`;
270
+ }
271
+ return `<${tagName}${attributes}>${children.map(serializeNode).join("")}</${tagName}>`;
272
+ }
273
+ function usesMsttsNamespace(nodes) {
274
+ return nodes.some((node) => {
275
+ if (typeof node === "string" || node.type === "text") {
276
+ return false;
277
+ }
278
+ const tagName = getTagName(node);
279
+ return tagName.startsWith(MSTTS_TAG_PREFIX) || usesMsttsNamespace(getChildren(node));
280
+ });
281
+ }
282
+ function serializeDocument(document) {
283
+ const children = document.children ?? (document.content === void 0 ? [] : [document.content]);
284
+ const attributes = {
285
+ ...document.attributes ?? {},
286
+ [SSML_ATTRS.VERSION]: document.version,
287
+ [SSML_ATTRS.XMLNS]: SYNTHESIS_NAMESPACE,
288
+ [SSML_ATTRS.XML_LANG]: document.lang
289
+ };
290
+ if (usesMsttsNamespace(children) && attributes[SSML_ATTRS.MSTTS_XMLNS] === void 0) {
291
+ attributes[SSML_ATTRS.MSTTS_XMLNS] = MSTTS_NAMESPACE;
292
+ }
293
+ return `<${SSML_TAGS.SPEAK}${serializeAttributes(attributes)}>${children.map(serializeNode).join("")}</${SSML_TAGS.SPEAK}>`;
294
+ }
295
+ function buildSsml(documentOrContent, lang = DEFAULT_SSML_LANGUAGE) {
296
+ if (typeof documentOrContent === "string") {
297
+ return {
298
+ version: DEFAULT_SSML_VERSION,
299
+ lang,
300
+ content: documentOrContent
301
+ };
302
+ }
303
+ return serializeDocument(documentOrContent);
304
+ }
305
+ var XML_ENTITIES = {
306
+ amp: "&",
307
+ apos: "'",
308
+ gt: ">",
309
+ lt: "<",
310
+ quot: '"'
311
+ };
312
+ function hasOwn(object, property) {
313
+ return Object.getOwnPropertyDescriptor(object, property) !== void 0;
314
+ }
315
+ function setAttribute(attributes, name, value) {
316
+ Object.defineProperty(attributes, name, {
317
+ configurable: true,
318
+ enumerable: true,
319
+ value,
320
+ writable: true
321
+ });
322
+ }
323
+ function decodeEntity(entity) {
324
+ const namedValue = hasOwn(XML_ENTITIES, entity) ? XML_ENTITIES[entity] : void 0;
325
+ if (namedValue !== void 0) {
326
+ return namedValue;
327
+ }
328
+ const isHexadecimal = entity.startsWith("#x") || entity.startsWith("#X");
329
+ const isDecimal = entity.startsWith("#");
330
+ if (!isHexadecimal && !isDecimal) {
331
+ throw new Error(`Unknown XML entity: &${entity};`);
332
+ }
333
+ const digits = entity.slice(isHexadecimal ? 2 : 1);
334
+ const codePoint = Number.parseInt(digits, isHexadecimal ? 16 : 10);
335
+ if (!digits || !Number.isInteger(codePoint) || codePoint < 0 || codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343 || codePoint < 32 && ![9, 10, 13].includes(codePoint)) {
336
+ throw new Error(`Invalid XML character reference: &${entity};`);
337
+ }
338
+ return String.fromCodePoint(codePoint);
339
+ }
340
+ function decodeXmlEntities(value) {
341
+ let result = "";
342
+ let start = 0;
343
+ while (true) {
344
+ const ampersand = value.indexOf("&", start);
345
+ if (ampersand === -1) {
346
+ return result + value.slice(start);
347
+ }
348
+ result += value.slice(start, ampersand);
349
+ const semicolon = value.indexOf(";", ampersand + 1);
350
+ if (semicolon === -1) {
351
+ throw new Error("Unterminated XML entity reference");
352
+ }
353
+ result += decodeEntity(value.slice(ampersand + 1, semicolon));
354
+ start = semicolon + 1;
355
+ }
356
+ }
357
+ function isXmlNameStart(value) {
358
+ return value !== void 0 && /[A-Za-z_]/.test(value);
359
+ }
360
+ function isXmlNameCharacter(value) {
361
+ return value !== void 0 && /[A-Za-z0-9_.:-]/.test(value);
362
+ }
363
+ function isXmlWhitespace(value) {
364
+ return value === " " || value === " " || value === "\r" || value === "\n";
365
+ }
366
+ function removeStandardNamespaceAttributes(attributes) {
367
+ if (attributes[SSML_ATTRS.XMLNS] === SYNTHESIS_NAMESPACE) {
368
+ delete attributes[SSML_ATTRS.XMLNS];
369
+ }
370
+ if (attributes[SSML_ATTRS.MSTTS_XMLNS] === MSTTS_NAMESPACE) {
371
+ delete attributes[SSML_ATTRS.MSTTS_XMLNS];
372
+ }
373
+ }
374
+ var _index;
375
+ var XmlParser = class {
376
+ constructor(source) {
377
+ __privateAdd(this, _index, 0);
378
+ this.source = source;
379
+ }
380
+ parse() {
381
+ if (this.source.charCodeAt(0) === 65279) {
382
+ __privateSet(this, _index, __privateGet(this, _index) + 1);
383
+ }
384
+ this.skipMisc();
385
+ if (__privateGet(this, _index) >= this.source.length) {
386
+ this.fail("SSML input is empty");
387
+ }
388
+ if (this.source[__privateGet(this, _index)] !== "<") {
389
+ this.fail("SSML input must start with an XML element");
390
+ }
391
+ const root = this.parseElement(0);
392
+ this.skipMisc();
393
+ if (__privateGet(this, _index) !== this.source.length) {
394
+ this.fail("Unexpected content after the root XML element");
395
+ }
396
+ return root;
397
+ }
398
+ parseElement(depth) {
399
+ if (depth > MAX_NESTING_DEPTH) {
400
+ this.fail("XML nesting depth exceeds the supported limit");
401
+ }
402
+ this.expect("<");
403
+ if (this.source[__privateGet(this, _index)] === "/") {
404
+ this.fail("Unexpected closing XML element");
405
+ }
406
+ const name = this.parseName();
407
+ const { attributes, selfClosing } = this.parseStartTag();
408
+ if (selfClosing) {
409
+ return { name, attributes, children: [] };
410
+ }
411
+ const children = [];
412
+ while (__privateGet(this, _index) < this.source.length) {
413
+ if (this.source.startsWith("</", __privateGet(this, _index))) {
414
+ __privateSet(this, _index, __privateGet(this, _index) + 2);
415
+ const closingName = this.parseName();
416
+ this.skipWhitespace();
417
+ this.expect(">");
418
+ if (closingName !== name) {
419
+ this.fail(`Mismatched closing element: expected </${name}> but found </${closingName}>`);
420
+ }
421
+ return { name, attributes, children };
422
+ }
423
+ if (this.source.startsWith("<!--", __privateGet(this, _index))) {
424
+ this.skipComment();
425
+ continue;
426
+ }
427
+ if (this.source.startsWith("<![CDATA[", __privateGet(this, _index))) {
428
+ this.appendText(children, this.parseCdata());
429
+ continue;
430
+ }
431
+ if (this.source.startsWith("<?", __privateGet(this, _index))) {
432
+ this.skipProcessingInstruction();
433
+ continue;
434
+ }
435
+ if (this.source.startsWith("<!", __privateGet(this, _index))) {
436
+ this.fail("Unsupported XML declaration inside an element");
437
+ }
438
+ if (this.source[__privateGet(this, _index)] === "<") {
439
+ children.push(this.parseElement(depth + 1));
440
+ } else {
441
+ this.appendText(children, this.parseText());
442
+ }
443
+ }
444
+ this.fail(`Unclosed XML element: <${name}>`);
445
+ }
446
+ parseStartTag() {
447
+ const attributes = {};
448
+ while (__privateGet(this, _index) < this.source.length) {
449
+ this.skipWhitespace();
450
+ if (this.source.startsWith("/>", __privateGet(this, _index))) {
451
+ __privateSet(this, _index, __privateGet(this, _index) + 2);
452
+ return { attributes, selfClosing: true };
453
+ }
454
+ if (this.source[__privateGet(this, _index)] === ">") {
455
+ __privateSet(this, _index, __privateGet(this, _index) + 1);
456
+ return { attributes, selfClosing: false };
457
+ }
458
+ const name = this.parseName();
459
+ this.skipWhitespace();
460
+ this.expect("=");
461
+ this.skipWhitespace();
462
+ const quote = this.source[__privateGet(this, _index)];
463
+ if (quote !== '"' && quote !== "'") {
464
+ this.fail(`XML attribute ${name} must use a quoted value`);
465
+ }
466
+ __privateSet(this, _index, __privateGet(this, _index) + 1);
467
+ const valueStart = __privateGet(this, _index);
468
+ while (__privateGet(this, _index) < this.source.length && this.source[__privateGet(this, _index)] !== quote) {
469
+ if (this.source[__privateGet(this, _index)] === "<") {
470
+ this.fail(`Invalid "<" in XML attribute ${name}`);
471
+ }
472
+ __privateSet(this, _index, __privateGet(this, _index) + 1);
473
+ }
474
+ if (__privateGet(this, _index) >= this.source.length) {
475
+ this.fail(`Unclosed XML attribute ${name}`);
476
+ }
477
+ const value = decodeXmlEntities(this.source.slice(valueStart, __privateGet(this, _index)));
478
+ __privateSet(this, _index, __privateGet(this, _index) + 1);
479
+ if (hasOwn(attributes, name)) {
480
+ this.fail(`Duplicate XML attribute: ${name}`);
481
+ }
482
+ setAttribute(attributes, name, value);
483
+ }
484
+ this.fail("Unclosed XML start tag");
485
+ }
486
+ parseText() {
487
+ const start = __privateGet(this, _index);
488
+ while (__privateGet(this, _index) < this.source.length && this.source[__privateGet(this, _index)] !== "<") {
489
+ __privateSet(this, _index, __privateGet(this, _index) + 1);
490
+ }
491
+ const value = this.source.slice(start, __privateGet(this, _index));
492
+ if (value.includes("]]>")) {
493
+ this.fail("CDATA termination is not valid in ordinary XML text");
494
+ }
495
+ return decodeXmlEntities(value);
496
+ }
497
+ parseCdata() {
498
+ __privateSet(this, _index, __privateGet(this, _index) + "<![CDATA[".length);
499
+ const end = this.source.indexOf("]]>", __privateGet(this, _index));
500
+ if (end === -1) {
501
+ this.fail("Unclosed XML CDATA section");
502
+ }
503
+ const value = this.source.slice(__privateGet(this, _index), end);
504
+ __privateSet(this, _index, end + 3);
505
+ return value;
506
+ }
507
+ skipComment() {
508
+ __privateSet(this, _index, __privateGet(this, _index) + "<!--".length);
509
+ const end = this.source.indexOf("-->", __privateGet(this, _index));
510
+ if (end === -1) {
511
+ this.fail("Unclosed XML comment");
512
+ }
513
+ if (this.source.slice(__privateGet(this, _index), end).includes("--")) {
514
+ this.fail("XML comments cannot contain consecutive hyphens");
515
+ }
516
+ __privateSet(this, _index, end + 3);
517
+ }
518
+ skipProcessingInstruction() {
519
+ __privateSet(this, _index, __privateGet(this, _index) + "<?".length);
520
+ this.parseName();
521
+ const end = this.source.indexOf("?>", __privateGet(this, _index));
522
+ if (end === -1) {
523
+ this.fail("Unclosed XML processing instruction");
524
+ }
525
+ __privateSet(this, _index, end + 2);
526
+ }
527
+ skipMisc() {
528
+ while (__privateGet(this, _index) < this.source.length) {
529
+ this.skipWhitespace();
530
+ if (this.source.startsWith("<!--", __privateGet(this, _index))) {
531
+ this.skipComment();
532
+ continue;
533
+ }
534
+ if (this.source.startsWith("<?", __privateGet(this, _index))) {
535
+ this.skipProcessingInstruction();
536
+ continue;
537
+ }
538
+ if (this.source.startsWith("<!DOCTYPE", __privateGet(this, _index))) {
539
+ this.fail("DOCTYPE declarations are not supported");
540
+ }
541
+ break;
542
+ }
543
+ }
544
+ parseName() {
545
+ const first = this.source[__privateGet(this, _index)];
546
+ if (!isXmlNameStart(first)) {
547
+ this.fail("Invalid XML name");
548
+ }
549
+ const start = __privateGet(this, _index);
550
+ __privateSet(this, _index, __privateGet(this, _index) + 1);
551
+ while (isXmlNameCharacter(this.source[__privateGet(this, _index)])) {
552
+ __privateSet(this, _index, __privateGet(this, _index) + 1);
553
+ }
554
+ return this.source.slice(start, __privateGet(this, _index));
555
+ }
556
+ appendText(children, value) {
557
+ if (!value) {
558
+ return;
559
+ }
560
+ const previous = children[children.length - 1];
561
+ if (typeof previous === "string") {
562
+ children[children.length - 1] = previous + value;
563
+ } else {
564
+ children.push(value);
565
+ }
566
+ }
567
+ skipWhitespace() {
568
+ while (isXmlWhitespace(this.source[__privateGet(this, _index)])) {
569
+ __privateSet(this, _index, __privateGet(this, _index) + 1);
570
+ }
571
+ }
572
+ expect(value) {
573
+ if (!this.source.startsWith(value, __privateGet(this, _index))) {
574
+ this.fail(`Expected "${value}"`);
575
+ }
576
+ __privateSet(this, _index, __privateGet(this, _index) + value.length);
577
+ }
578
+ fail(message) {
579
+ throw new Error(`${message} at position ${__privateGet(this, _index)}`);
580
+ }
581
+ };
582
+ _index = /* @__PURE__ */ new WeakMap();
583
+ function readAttribute(attributes, ...names) {
584
+ let found = false;
585
+ let value;
586
+ for (const name of names) {
587
+ if (hasOwn(attributes, name)) {
588
+ if (!found) {
589
+ value = String(attributes[name]);
590
+ found = true;
591
+ }
592
+ delete attributes[name];
593
+ }
594
+ }
595
+ return value;
596
+ }
597
+ function getElementAttributes(node) {
598
+ const attributes = { ...node.attributes };
599
+ removeStandardNamespaceAttributes(attributes);
600
+ return attributes;
601
+ }
602
+ function finishElement(element, node, attributes) {
603
+ if (node.children.length > 0) {
604
+ element.children = node.children.map(convertNode);
605
+ }
606
+ if (Object.keys(attributes).length > 0) {
607
+ element.attributes = attributes;
608
+ }
609
+ return element;
610
+ }
611
+ function convertElement(node) {
612
+ const attributes = getElementAttributes(node);
613
+ switch (node.name) {
614
+ case SSML_TAGS.VOICE: {
615
+ const element = { type: SSML_TAGS.VOICE };
616
+ const name = readAttribute(attributes, SSML_ATTRS.NAME);
617
+ const effect = readAttribute(attributes, SSML_ATTRS.EFFECT);
618
+ if (name !== void 0) element.name = name;
619
+ if (effect !== void 0) element.effect = effect;
620
+ return finishElement(element, node, attributes);
621
+ }
622
+ case SSML_TAGS.PROSODY: {
623
+ const element = { type: SSML_TAGS.PROSODY };
624
+ const rate = readAttribute(attributes, SSML_ATTRS.RATE);
625
+ const pitch = readAttribute(attributes, SSML_ATTRS.PITCH);
626
+ const volume = readAttribute(attributes, SSML_ATTRS.VOLUME);
627
+ const contour = readAttribute(attributes, SSML_ATTRS.CONTOUR);
628
+ const range = readAttribute(attributes, SSML_ATTRS.RANGE);
629
+ if (rate !== void 0) element.rate = rate;
630
+ if (pitch !== void 0) element.pitch = pitch;
631
+ if (volume !== void 0) element.volume = volume;
632
+ if (contour !== void 0) element.contour = contour;
633
+ if (range !== void 0) element.range = range;
634
+ return finishElement(element, node, attributes);
635
+ }
636
+ case SSML_TAGS.BREAK: {
637
+ const element = { type: SSML_TAGS.BREAK };
638
+ const time = readAttribute(attributes, SSML_ATTRS.TIME);
639
+ const strength = readAttribute(attributes, SSML_ATTRS.STRENGTH);
640
+ if (time !== void 0) element.time = time;
641
+ if (strength !== void 0) element.strength = strength;
642
+ return finishElement(element, node, attributes);
643
+ }
644
+ case SSML_TAGS.EXPRESS_AS:
645
+ case SSML_TAGS.EXPRESS_AS_CAMEL:
646
+ case SSML_TAGS.MSTTS_EXPRESS_AS: {
647
+ const element = { type: node.name };
648
+ const style = readAttribute(attributes, SSML_ATTRS.STYLE);
649
+ const styleDegree = readAttribute(
650
+ attributes,
651
+ SSML_ATTRS.STYLE_DEGREE,
652
+ SSML_ATTRS.STYLE_DEGREE_CAMEL,
653
+ SSML_ATTRS.STYLE_DEGREE_HYPHEN
654
+ );
655
+ const role = readAttribute(attributes, SSML_ATTRS.ROLE);
656
+ if (style !== void 0) element.style = style;
657
+ if (styleDegree !== void 0) element.styleDegree = styleDegree;
658
+ if (role !== void 0) element.role = role;
659
+ return finishElement(element, node, attributes);
660
+ }
661
+ case SSML_TAGS.SAY_AS:
662
+ case SSML_TAGS.SAY_AS_CAMEL: {
663
+ const element = { type: node.name };
664
+ const interpretAs = readAttribute(attributes, SSML_ATTRS.INTERPRET_AS);
665
+ const format = readAttribute(attributes, SSML_ATTRS.FORMAT);
666
+ const detail = readAttribute(attributes, SSML_ATTRS.DETAIL);
667
+ if (interpretAs !== void 0) element.interpretAs = interpretAs;
668
+ if (format !== void 0) element.format = format;
669
+ if (detail !== void 0) element.detail = detail;
670
+ return finishElement(element, node, attributes);
671
+ }
672
+ case SSML_TAGS.PHONEME: {
673
+ const element = { type: SSML_TAGS.PHONEME };
674
+ const alphabet = readAttribute(attributes, SSML_ATTRS.ALPHABET);
675
+ const ph = readAttribute(attributes, SSML_ATTRS.PH);
676
+ if (alphabet !== void 0) element.alphabet = alphabet;
677
+ if (ph !== void 0) element.ph = ph;
678
+ return finishElement(element, node, attributes);
679
+ }
680
+ case SSML_TAGS.EMPHASIS: {
681
+ const element = { type: SSML_TAGS.EMPHASIS };
682
+ const level = readAttribute(attributes, SSML_ATTRS.LEVEL);
683
+ if (level !== void 0) element.level = level;
684
+ return finishElement(element, node, attributes);
685
+ }
686
+ case SSML_TAGS.AUDIO: {
687
+ const element = { type: SSML_TAGS.AUDIO };
688
+ const src = readAttribute(attributes, SSML_ATTRS.SRC);
689
+ const desc = readAttribute(attributes, SSML_ATTRS.DESC);
690
+ const clipBegin = readAttribute(attributes, SSML_ATTRS.CLIP_BEGIN);
691
+ const clipEnd = readAttribute(attributes, SSML_ATTRS.CLIP_END);
692
+ const speed = readAttribute(attributes, SSML_ATTRS.SPEED);
693
+ const repeatCount = readAttribute(attributes, SSML_ATTRS.REPEAT_COUNT);
694
+ const repeatDuration = readAttribute(attributes, SSML_ATTRS.REPEAT_DURATION);
695
+ const soundLevel = readAttribute(attributes, SSML_ATTRS.SOUND_LEVEL);
696
+ if (src !== void 0) element.src = src;
697
+ if (desc !== void 0) element.desc = desc;
698
+ if (clipBegin !== void 0) element.clipBegin = clipBegin;
699
+ if (clipEnd !== void 0) element.clipEnd = clipEnd;
700
+ if (speed !== void 0) element.speed = speed;
701
+ if (repeatCount !== void 0) element.repeatCount = repeatCount;
702
+ if (repeatDuration !== void 0) element.repeatDuration = repeatDuration;
703
+ if (soundLevel !== void 0) element.soundLevel = soundLevel;
704
+ return finishElement(element, node, attributes);
705
+ }
706
+ case SSML_TAGS.SUB: {
707
+ const element = { type: SSML_TAGS.SUB };
708
+ const alias = readAttribute(attributes, SSML_ATTRS.ALIAS);
709
+ if (alias !== void 0) element.alias = alias;
710
+ return finishElement(element, node, attributes);
711
+ }
712
+ case SSML_TAGS.LANG: {
713
+ const element = { type: SSML_TAGS.LANG };
714
+ const lang = readAttribute(attributes, SSML_ATTRS.XML_LANG, SSML_ATTRS.LANG);
715
+ if (lang !== void 0) element.lang = lang;
716
+ return finishElement(element, node, attributes);
717
+ }
718
+ case SSML_TAGS.MARK: {
719
+ const element = { type: SSML_TAGS.MARK };
720
+ const name = readAttribute(attributes, SSML_ATTRS.NAME);
721
+ if (name !== void 0) element.name = name;
722
+ return finishElement(element, node, attributes);
723
+ }
724
+ case SSML_TAGS.BOOKMARK: {
725
+ const element = { type: SSML_TAGS.BOOKMARK };
726
+ const mark = readAttribute(attributes, SSML_ATTRS.MARK);
727
+ if (mark !== void 0) element.mark = mark;
728
+ return finishElement(element, node, attributes);
729
+ }
730
+ case SSML_TAGS.LEXICON: {
731
+ const element = { type: SSML_TAGS.LEXICON };
732
+ const uri = readAttribute(attributes, SSML_ATTRS.URI);
733
+ if (uri !== void 0) element.uri = uri;
734
+ return finishElement(element, node, attributes);
735
+ }
736
+ case SSML_TAGS.PARAGRAPH: {
737
+ const element = { type: SSML_TAGS.PARAGRAPH };
738
+ return finishElement(element, node, attributes);
739
+ }
740
+ case SSML_TAGS.SENTENCE: {
741
+ const element = { type: SSML_TAGS.SENTENCE };
742
+ return finishElement(element, node, attributes);
743
+ }
744
+ case SSML_TAGS.WORD: {
745
+ const element = { type: SSML_TAGS.WORD };
746
+ return finishElement(element, node, attributes);
747
+ }
748
+ case SSML_TAGS.MSTTS_SILENCE:
749
+ case SSML_TAGS.SILENCE: {
750
+ const element = {
751
+ type: node.name === SSML_TAGS.MSTTS_SILENCE ? SSML_TAGS.MSTTS_SILENCE : SSML_TAGS.SILENCE
752
+ };
753
+ const typeValue = readAttribute(attributes, SSML_ATTRS.TYPE);
754
+ const value = readAttribute(attributes, SSML_ATTRS.VALUE);
755
+ if (typeValue !== void 0) element.typeValue = typeValue;
756
+ if (value !== void 0) element.value = value;
757
+ return finishElement(element, node, attributes);
758
+ }
759
+ case SSML_TAGS.MSTTS_VISEME:
760
+ case SSML_TAGS.VISEME: {
761
+ const element = {
762
+ type: node.name === SSML_TAGS.MSTTS_VISEME ? SSML_TAGS.MSTTS_VISEME : SSML_TAGS.VISEME
763
+ };
764
+ const typeValue = readAttribute(attributes, SSML_ATTRS.TYPE);
765
+ if (typeValue !== void 0) element.typeValue = typeValue;
766
+ return finishElement(element, node, attributes);
767
+ }
768
+ case SSML_TAGS.MSTTS_AUDIO_DURATION: {
769
+ const element = { type: SSML_TAGS.MSTTS_AUDIO_DURATION };
770
+ const value = readAttribute(attributes, SSML_ATTRS.VALUE);
771
+ if (value !== void 0) element.value = value;
772
+ return finishElement(element, node, attributes);
773
+ }
774
+ case SSML_TAGS.MSTTS_DIALOG: {
775
+ const element = { type: SSML_TAGS.MSTTS_DIALOG };
776
+ return finishElement(element, node, attributes);
777
+ }
778
+ case SSML_TAGS.MSTTS_TURN: {
779
+ const element = { type: SSML_TAGS.MSTTS_TURN };
780
+ const voice = readAttribute(attributes, SSML_ATTRS.VOICE);
781
+ const speaker = readAttribute(attributes, SSML_ATTRS.SPEAKER);
782
+ if (voice !== void 0) element.voice = voice;
783
+ if (speaker !== void 0) element.speaker = speaker;
784
+ return finishElement(element, node, attributes);
785
+ }
786
+ case SSML_TAGS.MSTTS_BACKGROUND_AUDIO: {
787
+ const element = { type: SSML_TAGS.MSTTS_BACKGROUND_AUDIO };
788
+ const src = readAttribute(attributes, SSML_ATTRS.SRC);
789
+ const volume = readAttribute(attributes, SSML_ATTRS.VOLUME);
790
+ const fadeIn = readAttribute(attributes, SSML_ATTRS.FADE_IN);
791
+ const fadeOut = readAttribute(attributes, SSML_ATTRS.FADE_OUT);
792
+ if (src !== void 0) element.src = src;
793
+ if (volume !== void 0) element.volume = volume;
794
+ if (fadeIn !== void 0) element.fadeIn = fadeIn;
795
+ if (fadeOut !== void 0) element.fadeOut = fadeOut;
796
+ return finishElement(element, node, attributes);
797
+ }
798
+ case SSML_TAGS.MSTTS_TTS_EMBEDDING: {
799
+ const element = { type: SSML_TAGS.MSTTS_TTS_EMBEDDING };
800
+ const speakerProfileId = readAttribute(attributes, SSML_ATTRS.SPEAKER_PROFILE_ID);
801
+ if (speakerProfileId !== void 0) element.speakerProfileId = speakerProfileId;
802
+ return finishElement(element, node, attributes);
803
+ }
804
+ case SSML_TAGS.MSTTS_EMBEDDING: {
805
+ const element = { type: SSML_TAGS.MSTTS_EMBEDDING };
806
+ const id = readAttribute(attributes, SSML_ATTRS.ID);
807
+ const speakerProfileId = readAttribute(attributes, SSML_ATTRS.SPEAKER_PROFILE_ID);
808
+ if (id !== void 0) element.id = id;
809
+ if (speakerProfileId !== void 0) element.speakerProfileId = speakerProfileId;
810
+ return finishElement(element, node, attributes);
811
+ }
812
+ case SSML_TAGS.MSTTS_VOICE_CONVERSION: {
813
+ const element = { type: SSML_TAGS.MSTTS_VOICE_CONVERSION };
814
+ const url = readAttribute(attributes, SSML_ATTRS.URL);
815
+ const profile = readAttribute(attributes, SSML_ATTRS.PROFILE);
816
+ const speakerProfileId = readAttribute(attributes, SSML_ATTRS.SPEAKER_PROFILE_ID);
817
+ if (url !== void 0) element.url = url;
818
+ if (profile !== void 0) element.profile = profile;
819
+ if (speakerProfileId !== void 0) element.speakerProfileId = speakerProfileId;
820
+ return finishElement(element, node, attributes);
821
+ }
822
+ default: {
823
+ const element = {
824
+ name: node.name,
825
+ type: "custom"
826
+ };
827
+ return finishElement(element, node, attributes);
828
+ }
829
+ }
830
+ }
831
+ function convertNode(node) {
832
+ return typeof node === "string" ? node : convertElement(node);
833
+ }
834
+ function parseSsml(xmlString) {
835
+ if (typeof xmlString !== "string") {
836
+ throw new TypeError("SSML input must be a string");
837
+ }
838
+ const root = new XmlParser(xmlString).parse();
839
+ if (root.name !== SSML_TAGS.SPEAK) {
840
+ throw new Error(`SSML root element must be <${SSML_TAGS.SPEAK}>, found <${root.name}>`);
841
+ }
842
+ const attributes = { ...root.attributes };
843
+ const version = readAttribute(attributes, SSML_ATTRS.VERSION);
844
+ const lang = readAttribute(attributes, SSML_ATTRS.XML_LANG, SSML_ATTRS.LANG);
845
+ if (version === void 0) {
846
+ throw new Error(`SSML <${SSML_TAGS.SPEAK}> element is missing the "${SSML_ATTRS.VERSION}" attribute`);
847
+ }
848
+ if (lang === void 0) {
849
+ throw new Error(`SSML <${SSML_TAGS.SPEAK}> element is missing the "${SSML_ATTRS.XML_LANG}" attribute`);
850
+ }
851
+ removeStandardNamespaceAttributes(attributes);
852
+ const document = {
853
+ children: root.children.map(convertNode),
854
+ lang,
855
+ type: SSML_TAGS.SPEAK,
856
+ version
857
+ };
858
+ if (Object.keys(attributes).length > 0) {
859
+ document.attributes = attributes;
860
+ }
861
+ return document;
862
+ }
863
+ function escapeAttribute2(value) {
864
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/'/g, "&apos;");
865
+ }
866
+ function getPartialTextNodes(text, version, lang) {
867
+ if (!text.includes("<")) {
868
+ return [text];
869
+ }
870
+ try {
871
+ const openingTag = `<${SSML_TAGS.SPEAK} ${SSML_ATTRS.VERSION}="${escapeAttribute2(version)}" ${SSML_ATTRS.XMLNS}="${SYNTHESIS_NAMESPACE}" ${SSML_ATTRS.XML_LANG}="${escapeAttribute2(lang)}">`;
872
+ return parseSsml(`${openingTag}${text}</${SSML_TAGS.SPEAK}>`).children ?? [];
873
+ } catch {
874
+ return [{ type: "text", value: text }];
875
+ }
876
+ }
877
+ function getVoiceContext(context) {
878
+ const voice = context.voice;
879
+ if (typeof voice === "object" && voice !== null) {
880
+ return voice;
881
+ }
882
+ if (context.voiceName === void 0 && context.voiceEffect === void 0 && typeof voice !== "string") {
883
+ return void 0;
884
+ }
885
+ return {
886
+ name: context.voiceName ?? voice,
887
+ effect: context.voiceEffect
888
+ };
889
+ }
890
+ function serializePartialSsml(text, context) {
891
+ const version = context.version ?? DEFAULT_SSML_VERSION;
892
+ const lang = context.lang ?? DEFAULT_SSML_LANGUAGE;
893
+ let children = getPartialTextNodes(text, version, lang);
894
+ if (context.prosody) {
895
+ children = [
896
+ {
897
+ type: SSML_TAGS.PROSODY,
898
+ ...context.prosody,
899
+ children
900
+ }
901
+ ];
902
+ }
903
+ const voice = getVoiceContext(context);
904
+ if (voice) {
905
+ children = [
906
+ {
907
+ type: SSML_TAGS.VOICE,
908
+ ...voice,
909
+ children
910
+ }
911
+ ];
912
+ }
913
+ const document = {
914
+ type: SSML_TAGS.SPEAK,
915
+ version,
916
+ lang,
917
+ attributes: context.attributes,
918
+ children
919
+ };
920
+ return buildSsml(document);
921
+ }
922
+ function buildPartialSsml(textOrOptions, context) {
923
+ if (typeof textOrOptions === "string") {
924
+ return serializePartialSsml(textOrOptions, context ?? {});
925
+ }
926
+ return serializePartialSsml(textOrOptions.text, textOrOptions);
927
+ }
928
+ var PARSER_POSITION_SUFFIX = / at position (\d+)$/;
929
+ function validateSsml(xmlString) {
930
+ try {
931
+ parseSsml(xmlString);
932
+ return null;
933
+ } catch (error) {
934
+ const rawMessage = error instanceof Error ? error.message : String(error);
935
+ const positionMatch = PARSER_POSITION_SUFFIX.exec(rawMessage);
936
+ return {
937
+ message: positionMatch ? rawMessage.slice(0, positionMatch.index) : rawMessage,
938
+ position: positionMatch ? Number.parseInt(positionMatch[1], 10) : 0
939
+ };
940
+ }
941
+ }
942
+ var AZURE_VOICE_DEFINITIONS = [
943
+ { name: "de-DE-ConradNeural", locale: "de-DE", styles: ["cheerful", "sad"] },
944
+ { name: "de-DE-KatjaNeural", locale: "de-DE", styles: ["cheerful", "sad"] },
945
+ { name: "en-US-AndrewNeural", locale: "en-US", styles: ["empathetic", "relieved"] },
946
+ {
947
+ name: "en-US-GuyNeural",
948
+ locale: "en-US",
949
+ styles: [
950
+ "angry",
951
+ "cheerful",
952
+ "excited",
953
+ "friendly",
954
+ "hopeful",
955
+ "newscast",
956
+ "sad",
957
+ "shouting",
958
+ "terrified",
959
+ "unfriendly",
960
+ "whispering"
961
+ ]
962
+ },
963
+ {
964
+ name: "en-US-JennyMultilingualNeural",
965
+ locale: "en-US",
966
+ styles: [
967
+ "cheerful",
968
+ "empathetic",
969
+ "excited",
970
+ "friendly",
971
+ "hopeful",
972
+ "sad",
973
+ "shouting",
974
+ "terrified",
975
+ "unfriendly",
976
+ "whispering"
977
+ ]
978
+ },
979
+ {
980
+ name: "en-US-JennyNeural",
981
+ locale: "en-US",
982
+ styles: [
983
+ "assistant",
984
+ "chat",
985
+ "customerservice",
986
+ "newscast",
987
+ "cheerful",
988
+ "empathetic",
989
+ "excited",
990
+ "friendly",
991
+ "hopeful",
992
+ "sad",
993
+ "shouting",
994
+ "terrified",
995
+ "unfriendly",
996
+ "whispering"
997
+ ]
998
+ },
999
+ { name: "es-ES-ElviraNeural", locale: "es-ES" },
1000
+ { name: "fil-PH-AngeloNeural", locale: "fil-PH" },
1001
+ { name: "fil-PH-Angelo:DragonHDLatestNeural", locale: "fil-PH" },
1002
+ { name: "fil-PH-BlessicaNeural", locale: "fil-PH" },
1003
+ { name: "fil-PH-Blessica:DragonHDLatestNeural", locale: "fil-PH" },
1004
+ { name: "fr-FR-DeniseNeural", locale: "fr-FR", styles: ["cheerful", "sad"] },
1005
+ { name: "fr-FR-HenriNeural", locale: "fr-FR", styles: ["cheerful", "sad"] },
1006
+ { name: "id-ID-GadisNeural", locale: "id-ID" },
1007
+ { name: "it-IT-ElsaNeural", locale: "it-IT", styles: ["cheerful", "sad"] },
1008
+ { name: "ja-JP-KeitaNeural", locale: "ja-JP", styles: ["chat"] },
1009
+ { name: "ja-JP-MayuNeural", locale: "ja-JP", styles: ["calm", "cheerful", "sad"] },
1010
+ { name: "ja-JP-NanamiNeural", locale: "ja-JP", styles: ["chat", "customerservice", "cheerful", "whispering", "sad"] },
1011
+ { name: "ko-KR-SunHiNeural", locale: "ko-KR", styles: ["cheerful", "sad"] },
1012
+ { name: "ms-MY-YasminNeural", locale: "ms-MY" },
1013
+ { name: "pt-BR-FranciscaNeural", locale: "pt-BR", styles: ["calm"] },
1014
+ {
1015
+ name: "ru-RU-SvetlanaNeural",
1016
+ locale: "ru-RU",
1017
+ styles: ["cheerful", "sad", "angry", "disgruntled", "embarrassed", "fearful"]
1018
+ },
1019
+ { name: "th-TH-PremwadeeNeural", locale: "th-TH" },
1020
+ { name: "vi-VN-HoaiMyNeural", locale: "vi-VN" },
1021
+ {
1022
+ name: "zh-CN-XiaoxiaoNeural",
1023
+ locale: "zh-CN",
1024
+ styles: [
1025
+ "assistant",
1026
+ "chat",
1027
+ "customerservice",
1028
+ "newscast",
1029
+ "cheerful",
1030
+ "empathetic",
1031
+ "excited",
1032
+ "friendly",
1033
+ "hopeful",
1034
+ "sad",
1035
+ "terrified",
1036
+ "whispering",
1037
+ "poetry-reading",
1038
+ "sports_commentary",
1039
+ "sports_commentary_excited",
1040
+ "story"
1041
+ ]
1042
+ },
1043
+ {
1044
+ name: "zh-CN-YunxiNeural",
1045
+ locale: "zh-CN",
1046
+ styles: [
1047
+ "narration-relaxed",
1048
+ "embarrassed",
1049
+ "fearful",
1050
+ "sad",
1051
+ "disgruntled",
1052
+ "serious",
1053
+ "angry",
1054
+ "depressed",
1055
+ "chat",
1056
+ "cheerful",
1057
+ "assistant"
1058
+ ]
1059
+ },
1060
+ { name: "zh-TW-HsiaoChenNeural", locale: "zh-TW" }
1061
+ ];
1062
+ var ALLOWED_BREAK_STRENGTHS = /* @__PURE__ */ new Set(["none", "x-weak", "weak", "medium", "strong", "x-strong"]);
1063
+ var ALLOWED_SAY_AS = /* @__PURE__ */ new Set([
1064
+ "characters",
1065
+ "spell-out",
1066
+ "cardinal",
1067
+ "ordinal",
1068
+ "number",
1069
+ "date",
1070
+ "time",
1071
+ "telephone",
1072
+ "fraction",
1073
+ "address",
1074
+ "name",
1075
+ "currency",
1076
+ "number_digit"
1077
+ ]);
1078
+ var ALLOWED_ROLES = /* @__PURE__ */ new Set([
1079
+ "Girl",
1080
+ "Boy",
1081
+ "YoungAdultFemale",
1082
+ "YoungAdultMale",
1083
+ "OlderAdultFemale",
1084
+ "OlderAdultMale",
1085
+ "SeniorFemale",
1086
+ "SeniorMale"
1087
+ ]);
1088
+ var ALLOWED_EMPHASIS_LEVELS = /* @__PURE__ */ new Set(["strong", "moderate", "reduced", "none"]);
1089
+ var ALLOWED_SILENCE_TYPES = /* @__PURE__ */ new Set([
1090
+ "Leading",
1091
+ "Tailing",
1092
+ "Sentenceboundary",
1093
+ "Comma",
1094
+ "Semicolon",
1095
+ "Enumerationcomma"
1096
+ ]);
1097
+ var ALLOWED_VISEME_TYPES = /* @__PURE__ */ new Set(["redlips_front", "FacialExpression"]);
1098
+ var DEFAULT_PREVIEW_TAGS = /* @__PURE__ */ new Set(["mstts:voiceconversion"]);
1099
+ function featureStatusForTag(name, options) {
1100
+ const tagName = canonicalTagName(name);
1101
+ const configured = Object.entries(options.tagStatuses ?? {}).find(
1102
+ ([candidate]) => canonicalTagName(candidate) === tagName
1103
+ )?.[1];
1104
+ if (configured) return configured;
1105
+ if ((options.previewTags ?? [...DEFAULT_PREVIEW_TAGS]).some((candidate) => canonicalTagName(candidate) === tagName))
1106
+ return "preview";
1107
+ if ((options.deprecatedTags ?? []).some((candidate) => canonicalTagName(candidate) === tagName)) return "deprecated";
1108
+ return void 0;
1109
+ }
1110
+ function decodeAttribute(value) {
1111
+ return value.replace(
1112
+ /&(?:amp|apos|gt|lt|quot);/gi,
1113
+ (entity) => ({ "&amp;": "&", "&apos;": "'", "&gt;": ">", "&lt;": "<", "&quot;": '"' })[entity.toLowerCase()] ?? entity
1114
+ );
1115
+ }
1116
+ function findTagEnd2(source, start) {
1117
+ let quote = "";
1118
+ for (let index = start; index < source.length; index += 1) {
1119
+ const character = source[index];
1120
+ if (quote) {
1121
+ if (character === quote) quote = "";
1122
+ } else if (character === '"' || character === "'") quote = character;
1123
+ else if (character === ">") return index;
1124
+ }
1125
+ return source.length - 1;
1126
+ }
1127
+ function tokenizeElements(source) {
1128
+ const tokens = [];
1129
+ const openElements = [];
1130
+ let index = 0;
1131
+ while (index < source.length) {
1132
+ const start = source.indexOf("<", index);
1133
+ if (start === -1) break;
1134
+ if (source.startsWith("<!--", start)) {
1135
+ const end2 = source.indexOf("-->", start + 4);
1136
+ index = end2 === -1 ? source.length : end2 + 3;
1137
+ continue;
1138
+ }
1139
+ if (source.startsWith("<![CDATA[", start)) {
1140
+ const end2 = source.indexOf("]]>", start + 9);
1141
+ index = end2 === -1 ? source.length : end2 + 3;
1142
+ continue;
1143
+ }
1144
+ if (source.startsWith("<?", start)) {
1145
+ const end2 = source.indexOf("?>", start + 2);
1146
+ index = end2 === -1 ? source.length : end2 + 2;
1147
+ continue;
1148
+ }
1149
+ const end = findTagEnd2(source, start + 1);
1150
+ const raw = source.slice(start, end + 1);
1151
+ if (raw.startsWith("</")) {
1152
+ openElements.pop();
1153
+ index = end + 1;
1154
+ continue;
1155
+ }
1156
+ const nameMatch = /^<\s*([A-Za-z_][A-Za-z0-9_.:-]*)/.exec(raw);
1157
+ if (!nameMatch?.[1]) {
1158
+ index = end + 1;
1159
+ continue;
1160
+ }
1161
+ const attributes = /* @__PURE__ */ new Map();
1162
+ const attributeSource = raw.slice(nameMatch[0].length, raw.length - 1).replace(/\/\s*$/, "");
1163
+ const attributePattern = /([A-Za-z_][A-Za-z0-9_.:-]*)\s*=\s*(["'])([\s\S]*?)\2/g;
1164
+ for (const match of attributeSource.matchAll(attributePattern)) {
1165
+ attributes.set(match[1].toLowerCase(), decodeAttribute(match[3]));
1166
+ }
1167
+ const selfClosing = /\/\s*>$/.test(raw);
1168
+ const parent = openElements[openElements.length - 1];
1169
+ const childElementIndex = parent?.childElementCount;
1170
+ if (parent) parent.childElementCount += 1;
1171
+ const parentVoiceName = [...openElements].reverse().find((element) => element.voiceName)?.voiceName;
1172
+ const tokenName = nameMatch[1];
1173
+ const tokenVoiceName = tokenName.toLowerCase() === "voice" ? attributes.get("name") : tokenName.toLowerCase() === "mstts:turn" ? attributes.get("voice") ?? parentVoiceName : parentVoiceName;
1174
+ tokens.push({
1175
+ attributes,
1176
+ childElementIndex,
1177
+ end,
1178
+ depth: openElements.length + 1,
1179
+ name: tokenName,
1180
+ parentName: parent?.name,
1181
+ parentVoiceName,
1182
+ selfClosing,
1183
+ start
1184
+ });
1185
+ if (!selfClosing) {
1186
+ openElements.push({
1187
+ childElementCount: 0,
1188
+ name: tokenName,
1189
+ voiceName: tokenVoiceName
1190
+ });
1191
+ }
1192
+ index = end + 1;
1193
+ }
1194
+ return tokens;
1195
+ }
1196
+ function location(source, offset) {
1197
+ const before = source.slice(0, Math.max(0, offset));
1198
+ const line = before.split("\n").length;
1199
+ return { line, column: before.length - (before.lastIndexOf("\n") + 1) + 1 };
1200
+ }
1201
+ function addDiagnostic(diagnostics, source, offset, message, severity = "error", code) {
1202
+ diagnostics.push({
1203
+ ...location(source, offset),
1204
+ message,
1205
+ severity,
1206
+ source: "ssml-static-validator",
1207
+ ...code ? { code } : {}
1208
+ });
1209
+ }
1210
+ function isSupportedProsodyRate(value) {
1211
+ const trimmed = value.trim();
1212
+ if (/^(x-slow|slow|medium|fast|x-fast|[+-]?\d+(?:\.\d+)?%)$/.test(trimmed)) return true;
1213
+ const multiplier = /^(\d+(?:\.\d+)?)(x)?$/i.exec(trimmed);
1214
+ if (!multiplier) return false;
1215
+ const numericValue = Number(multiplier[1]);
1216
+ return numericValue >= 0.5 && numericValue <= 2;
1217
+ }
1218
+ function isValidAzureAudioDuration(value) {
1219
+ const trimmed = value.trim();
1220
+ const numeric = /^(\d+(?:\.\d+)?)(ms|s)$/.exec(trimmed);
1221
+ if (numeric) return Number(numeric[1]) > 0;
1222
+ const clock = /^(\d{2,}):([0-5]\d):([0-5]\d)(?:\.(\d{1,3}))?$/.exec(trimmed);
1223
+ if (!clock) return false;
1224
+ return Number(clock[1]) > 0 || Number(clock[2]) > 0 || Number(clock[3]) > 0 || Number(clock[4] ?? 0) > 0;
1225
+ }
1226
+ function isValidAzureBackgroundAudioDuration(value) {
1227
+ const match = /^(\d+)$/.exec(value.trim());
1228
+ if (!match) return false;
1229
+ const milliseconds = Number(match[1]);
1230
+ return Number.isFinite(milliseconds) && milliseconds >= 0 && milliseconds <= 1e4;
1231
+ }
1232
+ function attr(token, name) {
1233
+ return token.attributes.get(name.toLowerCase());
1234
+ }
1235
+ var DEFAULT_LANGUAGE_ALIASES = {
1236
+ "zh-CN": ["zh-Hans"],
1237
+ "zh-TW": ["zh-Hant"]
1238
+ };
1239
+ function canonicalLanguageTag(language) {
1240
+ const trimmed = language.trim();
1241
+ if (!trimmed) return "";
1242
+ try {
1243
+ return new Intl.Locale(trimmed).toString().toLowerCase();
1244
+ } catch {
1245
+ return trimmed.toLowerCase();
1246
+ }
1247
+ }
1248
+ function createLanguageNormalizer(options) {
1249
+ const aliases = /* @__PURE__ */ new Map();
1250
+ const addAliasGroup = (canonical, values) => {
1251
+ const normalizedCanonical = canonicalLanguageTag(canonical);
1252
+ if (!normalizedCanonical) return;
1253
+ aliases.set(normalizedCanonical, normalizedCanonical);
1254
+ for (const value of values) {
1255
+ const normalizedValue = canonicalLanguageTag(value);
1256
+ if (normalizedValue) aliases.set(normalizedValue, normalizedCanonical);
1257
+ }
1258
+ };
1259
+ for (const [canonical, values] of Object.entries(DEFAULT_LANGUAGE_ALIASES)) addAliasGroup(canonical, values);
1260
+ for (const [canonical, valueOrValues] of Object.entries(options.languageAliases ?? {}))
1261
+ addAliasGroup(canonical, typeof valueOrValues === "string" ? [valueOrValues] : valueOrValues);
1262
+ return (language) => {
1263
+ const customValue = options.normalizeLanguage ? options.normalizeLanguage(language) : language;
1264
+ const normalized = canonicalLanguageTag(customValue);
1265
+ return aliases.get(normalized) ?? normalized;
1266
+ };
1267
+ }
1268
+ function voiceLocalePrefix(voiceName) {
1269
+ const match = /^(?<language>[A-Za-z]{2,3})-(?<region>[A-Za-z]{2}|\d{3})(?:-|$)/.exec(voiceName.trim());
1270
+ if (!match?.groups) return void 0;
1271
+ const tag = `${match.groups.language}-${match.groups.region}`;
1272
+ return {
1273
+ language: match.groups.language.toLowerCase(),
1274
+ region: match.groups.region.toLowerCase(),
1275
+ tag
1276
+ };
1277
+ }
1278
+ function definitionFromStyleMap(voiceName, styles) {
1279
+ return {
1280
+ name: voiceName,
1281
+ locale: voiceLocalePrefix(voiceName)?.tag ?? "",
1282
+ styles
1283
+ };
1284
+ }
1285
+ function normalizeVoiceCatalog(options) {
1286
+ const definitions = /* @__PURE__ */ new Map();
1287
+ for (const definition of AZURE_VOICE_DEFINITIONS) definitions.set(definition.name.toLowerCase(), definition);
1288
+ for (const definition of options.voiceCatalog ?? []) definitions.set(definition.name.toLowerCase(), definition);
1289
+ for (const definition of options.voiceDefinitions ?? []) definitions.set(definition.name.toLowerCase(), definition);
1290
+ for (const definition of options.customVoiceDefinitions ?? [])
1291
+ definitions.set(definition.name.toLowerCase(), definition);
1292
+ for (const [voiceName, styles] of Object.entries(options.customVoiceStyleMap ?? {})) {
1293
+ const key = voiceName.toLowerCase();
1294
+ const current = definitions.get(key);
1295
+ definitions.set(key, {
1296
+ ...current ?? definitionFromStyleMap(voiceName, styles),
1297
+ name: current?.name ?? voiceName,
1298
+ styles: styles.map((style) => style.toLowerCase())
1299
+ });
1300
+ }
1301
+ return definitions;
1302
+ }
1303
+ function diagnosticSeverity(policy) {
1304
+ if (policy === "ignore") return void 0;
1305
+ return policy === "error" ? "error" : "warning";
1306
+ }
1307
+ function languagePart(language) {
1308
+ try {
1309
+ return new Intl.Locale(language).language.toLowerCase();
1310
+ } catch {
1311
+ return language.split("-")[0]?.toLowerCase() ?? "";
1312
+ }
1313
+ }
1314
+ function definitionMatchesLanguage(definition, voiceName, language, normalizeLanguage) {
1315
+ const candidateLanguages = definition ? [definition.locale, ...definition.secondaryLocales ?? []].filter(Boolean) : [voiceLocalePrefix(voiceName)?.tag ?? ""];
1316
+ if (candidateLanguages.length === 0 || !language.trim()) return void 0;
1317
+ const normalizedLanguage = normalizeLanguage(language);
1318
+ const normalizedCandidates = candidateLanguages.map(normalizeLanguage);
1319
+ if (normalizedCandidates.includes(normalizedLanguage)) return true;
1320
+ if (!normalizedLanguage || !normalizedCandidates.some(Boolean)) return void 0;
1321
+ return normalizedLanguage === languagePart(normalizedLanguage) ? normalizedCandidates.some((candidate) => languagePart(candidate) === normalizedLanguage) : false;
1322
+ }
1323
+ function canonicalTagName(name) {
1324
+ const normalized = name.toLowerCase();
1325
+ if (normalized === "express-as" || normalized === "expressas") return "mstts:express-as";
1326
+ if (normalized === "sayas") return "say-as";
1327
+ return normalized;
1328
+ }
1329
+ function validateVoiceFeatureMatrix(token, source, diagnostics, voiceName, definition) {
1330
+ if (!voiceName || !definition || token.name.toLowerCase() === "voice" || token.name.toLowerCase() === "mstts:turn")
1331
+ return;
1332
+ const tagName = canonicalTagName(token.name);
1333
+ const unsupportedTags = new Set((definition.unsupportedTags ?? []).map(canonicalTagName));
1334
+ const supportedTags = definition.supportedTags?.map(canonicalTagName);
1335
+ if (unsupportedTags.has(tagName) || supportedTags !== void 0 && !supportedTags.includes(tagName)) {
1336
+ addDiagnostic(
1337
+ diagnostics,
1338
+ source,
1339
+ token.start,
1340
+ `Tag <${token.name}> is not supported by voice "${voiceName}" according to the configured feature matrix.`,
1341
+ "error",
1342
+ "azure-unsupported-tag-for-voice"
1343
+ );
1344
+ }
1345
+ }
1346
+ function validateAudioSource(token, source, diagnostics, options, elementName2) {
1347
+ const src = attr(token, "src");
1348
+ if (!src) {
1349
+ addDiagnostic(diagnostics, source, token.start, `<${elementName2}> requires a "src" attribute.`);
1350
+ return;
1351
+ }
1352
+ let parsed;
1353
+ try {
1354
+ parsed = new URL(src);
1355
+ } catch {
1356
+ addDiagnostic(diagnostics, source, token.start, `<${elementName2} src> must be an absolute HTTP(S) URL.`);
1357
+ return;
1358
+ }
1359
+ if (parsed.username || parsed.password)
1360
+ addDiagnostic(diagnostics, source, token.start, `<${elementName2} src> must not contain URL credentials.`);
1361
+ if (parsed.protocol !== "https:" && !(options.allowHttpAudio && parsed.protocol === "http:"))
1362
+ addDiagnostic(diagnostics, source, token.start, `<${elementName2} src> must use HTTPS.`);
1363
+ const isAllowedOrigin = options.allowedAudioOrigins?.some((allowedOrigin) => {
1364
+ try {
1365
+ const configured = new URL(allowedOrigin);
1366
+ if (configured.protocol !== "https:" && configured.protocol !== "http:" || configured.username || configured.password || configured.pathname !== "/" || configured.search || configured.hash)
1367
+ return false;
1368
+ return configured.origin === parsed.origin;
1369
+ } catch {
1370
+ return false;
1371
+ }
1372
+ }) ?? false;
1373
+ if (options.allowedAudioOrigins && !isAllowedOrigin)
1374
+ addDiagnostic(diagnostics, source, token.start, `<${elementName2} src> origin "${parsed.origin}" is not allowed.`);
1375
+ else if (!isAllowedOrigin && !options.allowExternalAudio)
1376
+ addDiagnostic(
1377
+ diagnostics,
1378
+ source,
1379
+ token.start,
1380
+ `<${elementName2} src> external origin "${parsed.origin}" is blocked by default; set allowExternalAudio to true or provide allowedAudioOrigins.`
1381
+ );
1382
+ }
1383
+ function validateElement(token, source, diagnostics, voiceName, options, voiceCatalog) {
1384
+ const name = token.name.toLowerCase();
1385
+ const tagStatus = featureStatusForTag(token.name, options);
1386
+ if (tagStatus === "preview")
1387
+ addDiagnostic(
1388
+ diagnostics,
1389
+ source,
1390
+ token.start,
1391
+ `<${token.name}> is an Azure Speech preview feature and may change or require preview access.`,
1392
+ "warning",
1393
+ "azure-preview-tag"
1394
+ );
1395
+ if (tagStatus === "deprecated")
1396
+ addDiagnostic(
1397
+ diagnostics,
1398
+ source,
1399
+ token.start,
1400
+ `<${token.name}> is deprecated by Azure Speech; migrate to a supported alternative.`,
1401
+ "info",
1402
+ "azure-deprecated-tag"
1403
+ );
1404
+ if (name === "voice" && !attr(token, "name")?.trim())
1405
+ addDiagnostic(diagnostics, source, token.start, '<voice> requires a non-empty "name" attribute.');
1406
+ if (name === "break") {
1407
+ const time = attr(token, "time");
1408
+ const strength = attr(token, "strength");
1409
+ if (!time && !strength)
1410
+ addDiagnostic(diagnostics, source, token.start, '<break> requires either "time" or "strength".');
1411
+ if (time && strength)
1412
+ addDiagnostic(diagnostics, source, token.start, '<break> must not specify both "time" and "strength".');
1413
+ if (time && !/^\d+(?:\.\d+)?(?:ms|s)$/.test(time.trim()))
1414
+ addDiagnostic(diagnostics, source, token.start, '<break time> must use a numeric value followed by "ms" or "s".');
1415
+ if (strength && !ALLOWED_BREAK_STRENGTHS.has(strength))
1416
+ addDiagnostic(diagnostics, source, token.start, `Unsupported <break strength> value "${strength}".`);
1417
+ }
1418
+ if (name === "prosody") {
1419
+ const rate = attr(token, "rate");
1420
+ const pitch = attr(token, "pitch");
1421
+ const volume = attr(token, "volume");
1422
+ if (rate && !isSupportedProsodyRate(rate))
1423
+ addDiagnostic(diagnostics, source, token.start, `Unsupported <prosody rate> value "${rate}".`);
1424
+ if (pitch && !/^(x-low|low|medium|high|x-high|[+-]?\d+(?:\.\d+)?(?:st|Hz|%)?)$/.test(pitch.trim()))
1425
+ addDiagnostic(diagnostics, source, token.start, `Unsupported <prosody pitch> value "${pitch}".`);
1426
+ if (volume && !/^(silent|x-soft|soft|medium|loud|x-loud|[+-]?\d+(?:\.\d+)?(?:dB|%)?)$/.test(volume.trim()))
1427
+ addDiagnostic(diagnostics, source, token.start, `Unsupported <prosody volume> value "${volume}".`);
1428
+ }
1429
+ if (name === "mstts:express-as" || name === "express-as" || name === "expressas") {
1430
+ const style = attr(token, "style");
1431
+ if (!style?.trim())
1432
+ addDiagnostic(diagnostics, source, token.start, '<mstts:express-as> requires a non-empty "style" attribute.');
1433
+ const degree = attr(token, "styledegree") ?? attr(token, "style-degree");
1434
+ if (degree && (!/^\d+(?:\.\d+)?$/.test(degree) || Number(degree) < 0.01 || Number(degree) > 2))
1435
+ addDiagnostic(
1436
+ diagnostics,
1437
+ source,
1438
+ token.start,
1439
+ "<mstts:express-as styledegree> must be a number between 0.01 and 2."
1440
+ );
1441
+ const role = attr(token, "role");
1442
+ if (role && !ALLOWED_ROLES.has(role))
1443
+ addDiagnostic(diagnostics, source, token.start, `Unsupported <mstts:express-as role> value "${role}".`);
1444
+ const definition = voiceName ? voiceCatalog.get(voiceName.toLowerCase()) : void 0;
1445
+ const supportedStyles = definition?.styles;
1446
+ const severity = diagnosticSeverity(options.unsupportedStylePolicy ?? options.unknownVoicePolicy ?? "warn");
1447
+ if (style && definition && !supportedStyles?.some((candidate) => candidate.toLowerCase() === style.toLowerCase()) && severity)
1448
+ addDiagnostic(
1449
+ diagnostics,
1450
+ source,
1451
+ token.start,
1452
+ `Unknown style "${style}" is not supported by voice "${voiceName}" according to the configured voice style map.`,
1453
+ severity,
1454
+ "azure-unsupported-style"
1455
+ );
1456
+ if (style && voiceName && !definition && severity)
1457
+ addDiagnostic(
1458
+ diagnostics,
1459
+ source,
1460
+ token.start,
1461
+ `Unknown style "${style}" cannot be verified because voice "${voiceName}" is not registered in the voice style map.`,
1462
+ severity
1463
+ );
1464
+ }
1465
+ if (name === "say-as" || name === "sayas") {
1466
+ const interpretAs = attr(token, "interpret-as");
1467
+ if (!interpretAs || !ALLOWED_SAY_AS.has(interpretAs))
1468
+ addDiagnostic(diagnostics, source, token.start, `<say-as> requires a supported "interpret-as" value.`);
1469
+ }
1470
+ if (name === "phoneme" && (!attr(token, "alphabet") || !attr(token, "ph")))
1471
+ addDiagnostic(diagnostics, source, token.start, '<phoneme> requires both "alphabet" and "ph" attributes.');
1472
+ if (name === "emphasis" && attr(token, "level") && !ALLOWED_EMPHASIS_LEVELS.has(attr(token, "level") ?? ""))
1473
+ addDiagnostic(diagnostics, source, token.start, `Unsupported <emphasis level> value "${attr(token, "level")}".`);
1474
+ if (name === "sub" && !attr(token, "alias")?.trim())
1475
+ addDiagnostic(diagnostics, source, token.start, '<sub> requires a non-empty "alias" attribute.');
1476
+ if (name === "lang" && !attr(token, "xml:lang")?.trim() && !attr(token, "lang")?.trim())
1477
+ addDiagnostic(diagnostics, source, token.start, '<lang> requires an "xml:lang" attribute.');
1478
+ if (name === "mark" && !attr(token, "name")?.trim())
1479
+ addDiagnostic(diagnostics, source, token.start, '<mark> requires a non-empty "name" attribute.');
1480
+ if (name === "bookmark" && !attr(token, "mark")?.trim())
1481
+ addDiagnostic(diagnostics, source, token.start, '<bookmark> requires a non-empty "mark" attribute.');
1482
+ if (name === "lexicon") {
1483
+ const uri = attr(token, "uri");
1484
+ if (!uri) addDiagnostic(diagnostics, source, token.start, '<lexicon> requires a "uri" attribute.');
1485
+ else {
1486
+ try {
1487
+ const parsed = new URL(uri);
1488
+ if (parsed.protocol !== "https:")
1489
+ addDiagnostic(diagnostics, source, token.start, "<lexicon uri> must use HTTPS.");
1490
+ } catch {
1491
+ addDiagnostic(diagnostics, source, token.start, "<lexicon uri> must be an absolute HTTPS URL.");
1492
+ }
1493
+ }
1494
+ }
1495
+ if (name === "mstts:silence") {
1496
+ const type = attr(token, "type");
1497
+ const value = attr(token, "value");
1498
+ if (!type || !ALLOWED_SILENCE_TYPES.has(type))
1499
+ addDiagnostic(diagnostics, source, token.start, '<mstts:silence> requires a supported "type" attribute.');
1500
+ if (!value || !/^\d+(?:\.\d+)?(?:ms|s)$/.test(value.trim()))
1501
+ addDiagnostic(diagnostics, source, token.start, '<mstts:silence> requires a time-valued "value" attribute.');
1502
+ }
1503
+ if (name === "mstts:audioduration") {
1504
+ const value = attr(token, "value");
1505
+ if (!value || !isValidAzureAudioDuration(value))
1506
+ addDiagnostic(
1507
+ diagnostics,
1508
+ source,
1509
+ token.start,
1510
+ '<mstts:audioduration> requires a positive duration such as "10s", "5000ms", or "00:00:10".'
1511
+ );
1512
+ if (!token.selfClosing)
1513
+ addDiagnostic(diagnostics, source, token.start, "<mstts:audioduration> must be self-closing.");
1514
+ }
1515
+ if (name === "mstts:viseme") {
1516
+ const type = attr(token, "type");
1517
+ if (!type || !ALLOWED_VISEME_TYPES.has(type))
1518
+ addDiagnostic(diagnostics, source, token.start, '<mstts:viseme> requires a supported "type" attribute.');
1519
+ }
1520
+ if (name === "audio") {
1521
+ validateAudioSource(token, source, diagnostics, options, "audio");
1522
+ }
1523
+ if (name === "mstts:turn") {
1524
+ if (!attr(token, "voice")?.trim() && !attr(token, "speaker")?.trim())
1525
+ addDiagnostic(
1526
+ diagnostics,
1527
+ source,
1528
+ token.start,
1529
+ '<mstts:turn> requires a non-empty "voice" or "speaker" attribute.'
1530
+ );
1531
+ if (token.parentName?.toLowerCase() !== "mstts:dialog")
1532
+ addDiagnostic(diagnostics, source, token.start, "<mstts:turn> is only allowed directly inside <mstts:dialog>.");
1533
+ }
1534
+ if (name === "mstts:backgroundaudio") {
1535
+ validateAudioSource(token, source, diagnostics, options, "mstts:backgroundaudio");
1536
+ const volume = attr(token, "volume");
1537
+ if (volume !== void 0 && (!/^\d+(?:\.\d+)?$/.test(volume.trim()) || Number(volume) > 100))
1538
+ addDiagnostic(diagnostics, source, token.start, `Unsupported <mstts:backgroundaudio volume> value "${volume}".`);
1539
+ for (const [attribute, value] of [
1540
+ ["fadein", attr(token, "fadein")],
1541
+ ["fadeout", attr(token, "fadeout")]
1542
+ ]) {
1543
+ if (value !== void 0 && !isValidAzureBackgroundAudioDuration(value))
1544
+ addDiagnostic(
1545
+ diagnostics,
1546
+ source,
1547
+ token.start,
1548
+ `<mstts:backgroundaudio ${attribute}> must be between 0 and 10000 milliseconds, for example "500ms" or "10s".`
1549
+ );
1550
+ }
1551
+ if (token.parentName?.toLowerCase() !== "speak" || token.childElementIndex !== 0)
1552
+ addDiagnostic(
1553
+ diagnostics,
1554
+ source,
1555
+ token.start,
1556
+ "<mstts:backgroundaudio> must be the first element directly under <speak>."
1557
+ );
1558
+ if (!token.selfClosing)
1559
+ addDiagnostic(diagnostics, source, token.start, "<mstts:backgroundaudio> must be self-closing.");
1560
+ }
1561
+ }
1562
+ function validateAzureSsmlStatic(ssml, options = {}) {
1563
+ const diagnostics = [];
1564
+ if (typeof ssml !== "string") {
1565
+ return [
1566
+ {
1567
+ line: 1,
1568
+ column: 1,
1569
+ message: "SSML input must be a string",
1570
+ severity: "error",
1571
+ source: "ssml-static-validator"
1572
+ }
1573
+ ];
1574
+ }
1575
+ const maxLength = options.maxLength ?? 1e4;
1576
+ if (ssml.length > maxLength)
1577
+ addDiagnostic(diagnostics, ssml, maxLength, `SSML exceeds the maximum length of ${maxLength} characters.`);
1578
+ if (options.maxXmlDepth !== void 0 && (!Number.isInteger(options.maxXmlDepth) || options.maxXmlDepth <= 0)) {
1579
+ addDiagnostic(diagnostics, ssml, 0, "maxXmlDepth must be a positive integer.");
1580
+ }
1581
+ try {
1582
+ parseSsml(ssml);
1583
+ } catch (error) {
1584
+ const message = error instanceof Error ? error.message.replace(/ at position \d+$/, "") : String(error);
1585
+ const match = / at position (\d+)$/.exec(error instanceof Error ? error.message : "");
1586
+ addDiagnostic(diagnostics, ssml, match ? Number(match[1]) : 0, message);
1587
+ return diagnostics;
1588
+ }
1589
+ const tokens = tokenizeElements(ssml);
1590
+ if (options.maxXmlDepth !== void 0) {
1591
+ for (const token of tokens) {
1592
+ if (token.depth > options.maxXmlDepth) {
1593
+ addDiagnostic(
1594
+ diagnostics,
1595
+ ssml,
1596
+ token.start,
1597
+ `XML nesting depth ${token.depth} exceeds the configured maximum of ${options.maxXmlDepth}.`
1598
+ );
1599
+ }
1600
+ }
1601
+ }
1602
+ const speak = tokens.find((token) => token.name.toLowerCase() === "speak");
1603
+ const voices = tokens.filter((token) => token.name.toLowerCase() === "voice");
1604
+ const backgroundAudioTokens = tokens.filter((token) => token.name.toLowerCase() === "mstts:backgroundaudio");
1605
+ for (const [index, token] of backgroundAudioTokens.entries()) {
1606
+ if (index > 0)
1607
+ addDiagnostic(
1608
+ diagnostics,
1609
+ ssml,
1610
+ token.start,
1611
+ "An SSML document can contain at most one <mstts:backgroundaudio> element."
1612
+ );
1613
+ }
1614
+ if (!speak || voices.length === 0)
1615
+ addDiagnostic(
1616
+ diagnostics,
1617
+ ssml,
1618
+ speak?.start ?? 0,
1619
+ "Azure SSML requires at least one <voice> element under <speak>."
1620
+ );
1621
+ const voiceName = voices[0] ? attr(voices[0], "name") : void 0;
1622
+ const voiceCatalog = normalizeVoiceCatalog(options);
1623
+ const normalizeLanguage = createLanguageNormalizer(options);
1624
+ const policySeverity = diagnosticSeverity(options.unknownVoicePolicy ?? "warn");
1625
+ const voicesToValidate = options.validateNestedVoices === false ? voices.slice(0, 1) : voices;
1626
+ for (const token of voicesToValidate) {
1627
+ const name = attr(token, "name")?.trim();
1628
+ const language = attr(token, "xml:lang")?.trim() || (speak ? attr(speak, "xml:lang")?.trim() : void 0);
1629
+ const definition = name ? voiceCatalog.get(name.toLowerCase()) : void 0;
1630
+ if (name && definition?.status === "preview")
1631
+ addDiagnostic(
1632
+ diagnostics,
1633
+ ssml,
1634
+ token.start,
1635
+ `Voice "${name}" is an Azure Speech preview voice and may change or require preview access.`,
1636
+ "warning",
1637
+ "azure-preview-voice"
1638
+ );
1639
+ if (name && definition?.status === "deprecated")
1640
+ addDiagnostic(
1641
+ diagnostics,
1642
+ ssml,
1643
+ token.start,
1644
+ `Voice "${name}" is deprecated by Azure Speech; migrate to a supported voice.`,
1645
+ "info",
1646
+ "azure-deprecated-voice"
1647
+ );
1648
+ if (name && !definition && policySeverity)
1649
+ addDiagnostic(
1650
+ diagnostics,
1651
+ ssml,
1652
+ token.start,
1653
+ `Unknown voice "${name}" is not registered in the voice catalog.`,
1654
+ policySeverity,
1655
+ "azure-unknown-voice"
1656
+ );
1657
+ if (name && language && definitionMatchesLanguage(definition, name, language, normalizeLanguage) === false)
1658
+ addDiagnostic(
1659
+ diagnostics,
1660
+ ssml,
1661
+ token.start,
1662
+ `Voice "${name}" does not match language "${language}"; the voice name prefix indicates a different language or region.`,
1663
+ "warning",
1664
+ "azure-locale-mismatch"
1665
+ );
1666
+ }
1667
+ for (const token of tokens) {
1668
+ const tokenName = token.name.toLowerCase();
1669
+ const tokenVoiceName = tokenName === "voice" ? attr(token, "name")?.trim() : tokenName === "mstts:turn" ? attr(token, "voice")?.trim() || token.parentVoiceName : options.validateNestedVoices === false ? voiceName : token.parentVoiceName;
1670
+ validateElement(token, ssml, diagnostics, tokenVoiceName, options, voiceCatalog);
1671
+ const definition = tokenVoiceName ? voiceCatalog.get(tokenVoiceName.toLowerCase()) : void 0;
1672
+ validateVoiceFeatureMatrix(token, ssml, diagnostics, tokenVoiceName, definition);
1673
+ if (tokenName === "voice" && options.model && definition?.models && !definition.models.some((model) => model.toLowerCase() === options.model?.toLowerCase())) {
1674
+ addDiagnostic(
1675
+ diagnostics,
1676
+ ssml,
1677
+ token.start,
1678
+ `Voice "${tokenVoiceName}" does not support model "${options.model}" according to the configured feature matrix.`,
1679
+ "error",
1680
+ "azure-unsupported-model-for-voice"
1681
+ );
1682
+ }
1683
+ }
1684
+ return diagnostics;
1685
+ }
1686
+ function urlAttributes(token) {
1687
+ const tag = canonicalTagName(token.name);
1688
+ const attributes = tag === "audio" || tag === "mstts:backgroundaudio" ? ["src"] : tag === "lexicon" ? ["uri"] : tag === "mstts:voiceconversion" ? ["url"] : [];
1689
+ return attributes.flatMap((attribute) => {
1690
+ const value = attr(token, attribute);
1691
+ return value === void 0 ? [] : [{ attribute, value }];
1692
+ });
1693
+ }
1694
+ function validateAzureSsml(ssml, options = {}) {
1695
+ const diagnostics = validateAzureSsmlStatic(ssml, options);
1696
+ const validator = options.urlValidator ?? options.customUrlValidator;
1697
+ if (!validator || typeof ssml !== "string") return diagnostics;
1698
+ let tokens;
1699
+ try {
1700
+ tokens = tokenizeElements(ssml);
1701
+ } catch {
1702
+ return diagnostics;
1703
+ }
1704
+ const checks = tokens.flatMap(
1705
+ (token) => urlAttributes(token).map(async ({ attribute, value }) => {
1706
+ try {
1707
+ const result = await validator(value, { tag: token.name, attribute });
1708
+ const valid = typeof result === "boolean" ? result : result.valid;
1709
+ if (!valid) {
1710
+ const reason = typeof result === "boolean" ? void 0 : result.reason;
1711
+ addDiagnostic(
1712
+ diagnostics,
1713
+ ssml,
1714
+ token.start,
1715
+ `<${token.name} ${attribute}> was rejected by the custom URL validator${reason ? `: ${reason}` : "."}`
1716
+ );
1717
+ }
1718
+ } catch (error) {
1719
+ const reason = error instanceof Error ? error.message : String(error);
1720
+ addDiagnostic(
1721
+ diagnostics,
1722
+ ssml,
1723
+ token.start,
1724
+ `<${token.name} ${attribute}> could not be validated by the custom URL validator: ${reason}`
1725
+ );
1726
+ }
1727
+ })
1728
+ );
1729
+ return Promise.all(checks).then(() => diagnostics);
1730
+ }
1731
+ var AZURE_VOICE_CATALOG_METADATA = {
1732
+ apiVersion: "2025-10-01",
1733
+ generatedAt: "2026-08-28T00:00:00.000Z",
1734
+ regions: [],
1735
+ voiceCount: AZURE_VOICE_DEFINITIONS.length
1736
+ };
1737
+
1738
+ export {
1739
+ buildSsml,
1740
+ parseSsml,
1741
+ buildPartialSsml,
1742
+ validateSsml,
1743
+ validateAzureSsml
1744
+ };
1745
+ //# sourceMappingURL=chunk-CZ2F3TET.mjs.map