ssml-builder-js 2.4.0 → 2.6.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.
@@ -864,6 +864,9 @@ function decodeXmlText(value) {
864
864
  function encodeXmlText(value) {
865
865
  return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
866
866
  }
867
+ function decodeXmlAttribute(value) {
868
+ return decodeXmlText(value);
869
+ }
867
870
  function findTagEnd(source, start) {
868
871
  let quote = "";
869
872
  for (let index = start; index < source.length; index += 1) {
@@ -882,14 +885,31 @@ function readTagName(tag) {
882
885
  const match = /^<\s*([A-Za-z_][A-Za-z0-9_.:-]*)/.exec(tag);
883
886
  return match?.[1];
884
887
  }
888
+ function readTagAttributes(tag, name) {
889
+ const attributes = {};
890
+ const nameStart = tag.indexOf(name);
891
+ const attributeSource = tag.slice(nameStart + name.length, tag.length - 1).replace(/\/\s*$/, "");
892
+ const attributePattern = /([A-Za-z_][A-Za-z0-9_.:-]*)\s*=\s*(["'])([\s\S]*?)\2/g;
893
+ for (const match of attributeSource.matchAll(attributePattern)) {
894
+ attributes[match[1].toLowerCase()] = decodeXmlAttribute(match[3]);
895
+ }
896
+ return attributes;
897
+ }
885
898
  function collectTextNodes(source) {
886
899
  const nodes = [];
887
- const path = [];
900
+ const elements = [];
888
901
  let index = 0;
889
902
  const addText = (start, end, rawText, sourceStart = start, sourceEnd = end) => {
890
903
  if (!rawText) return;
904
+ const path = elements.map((element) => element.name);
905
+ const parent = elements[elements.length - 1];
891
906
  nodes.push({
892
- context: { parentTag: path[path.length - 1] ?? "", path: [...path] },
907
+ context: {
908
+ ancestorTags: path.slice(0, -1),
909
+ parentAttributes: { ...parent?.attributes ?? {} },
910
+ parentTag: parent?.name ?? "",
911
+ path
912
+ },
893
913
  decodedText: decodeXmlText(rawText),
894
914
  end,
895
915
  sourceEnd,
@@ -931,14 +951,14 @@ function collectTextNodes(source) {
931
951
  }
932
952
  if (source.startsWith("</", index)) {
933
953
  const end2 = findTagEnd(source, index + 2);
934
- path.pop();
954
+ elements.pop();
935
955
  index = end2 + 1;
936
956
  continue;
937
957
  }
938
958
  const end = findTagEnd(source, index + 1);
939
959
  const tag = source.slice(index, end + 1);
940
960
  const name = readTagName(tag);
941
- if (name && !/\/\s*>$/.test(tag)) path.push(name);
961
+ if (name && !/\/\s*>$/.test(tag)) elements.push({ attributes: readTagAttributes(tag, name), name });
942
962
  index = end + 1;
943
963
  }
944
964
  return nodes;
@@ -947,15 +967,21 @@ function extractSsmlText(ssml) {
947
967
  parseSsml(ssml);
948
968
  return collectTextNodes(ssml).map((node) => node.decodedText);
949
969
  }
950
- async function mapSsmlTextNodes(ssml, transform) {
970
+ async function mapSsmlTextNodes(ssml, transform, options = {}) {
951
971
  parseSsml(ssml);
952
972
  const nodes = collectTextNodes(ssml);
973
+ const skipTags = new Set((options.skipTags ?? ["phoneme", "say-as", "sub"]).map((tag) => tag.toLowerCase()));
953
974
  const replacements = await Promise.all(
954
975
  nodes.map(async (node) => {
955
- const transformed = await transform(node.decodedText, {
976
+ const context = {
977
+ ancestorTags: [...node.context.ancestorTags],
978
+ parentAttributes: { ...node.context.parentAttributes },
956
979
  parentTag: node.context.parentTag,
957
980
  path: [...node.context.path]
958
- });
981
+ };
982
+ const shouldTransform = !skipTags.has(context.parentTag.toLowerCase()) && (options.filter?.(context) ?? true);
983
+ if (!shouldTransform) return ssml.slice(node.sourceStart, node.sourceEnd);
984
+ const transformed = await transform(node.decodedText, context);
959
985
  if (typeof transformed !== "string") {
960
986
  throw new TypeError("SSML text node transform must return a string");
961
987
  }
@@ -1112,6 +1138,7 @@ function findTagEnd2(source, start) {
1112
1138
  }
1113
1139
  function tokenizeElements(source) {
1114
1140
  const tokens = [];
1141
+ const openElements = [];
1115
1142
  let index = 0;
1116
1143
  while (index < source.length) {
1117
1144
  const start = source.indexOf("<", index);
@@ -1133,8 +1160,13 @@ function tokenizeElements(source) {
1133
1160
  }
1134
1161
  const end = findTagEnd2(source, start + 1);
1135
1162
  const raw = source.slice(start, end + 1);
1163
+ if (raw.startsWith("</")) {
1164
+ openElements.pop();
1165
+ index = end + 1;
1166
+ continue;
1167
+ }
1136
1168
  const nameMatch = /^<\s*([A-Za-z_][A-Za-z0-9_.:-]*)/.exec(raw);
1137
- if (!nameMatch?.[1] || raw.startsWith("</")) {
1169
+ if (!nameMatch?.[1]) {
1138
1170
  index = end + 1;
1139
1171
  continue;
1140
1172
  }
@@ -1144,7 +1176,15 @@ function tokenizeElements(source) {
1144
1176
  for (const match of attributeSource.matchAll(attributePattern)) {
1145
1177
  attributes.set(match[1].toLowerCase(), decodeAttribute(match[3]));
1146
1178
  }
1147
- tokens.push({ attributes, end, name: nameMatch[1], selfClosing: /\/\s*>$/.test(raw), start });
1179
+ const selfClosing = /\/\s*>$/.test(raw);
1180
+ const parentVoiceName = [...openElements].reverse().find((element) => element.voiceName)?.voiceName;
1181
+ tokens.push({ attributes, end, name: nameMatch[1], parentVoiceName, selfClosing, start });
1182
+ if (!selfClosing) {
1183
+ openElements.push({
1184
+ name: nameMatch[1],
1185
+ voiceName: nameMatch[1].toLowerCase() === "voice" ? attributes.get("name") : parentVoiceName
1186
+ });
1187
+ }
1148
1188
  index = end + 1;
1149
1189
  }
1150
1190
  return tokens;
@@ -1160,7 +1200,45 @@ function addDiagnostic(diagnostics, source, offset, message, severity = "error")
1160
1200
  function attr(token, name) {
1161
1201
  return token.attributes.get(name.toLowerCase());
1162
1202
  }
1163
- function validateElement(token, source, diagnostics, voiceName, options) {
1203
+ function normalizeVoiceStyleMap(customVoiceStyleMap) {
1204
+ const map = new Map(
1205
+ Object.entries(EXPRESS_AS_STYLES).map(([voiceName, styles]) => [voiceName.toLowerCase(), styles])
1206
+ );
1207
+ for (const [voiceName, styles] of Object.entries(customVoiceStyleMap ?? {})) {
1208
+ map.set(
1209
+ voiceName.toLowerCase(),
1210
+ styles.map((style) => style.toLowerCase())
1211
+ );
1212
+ }
1213
+ return map;
1214
+ }
1215
+ function diagnosticSeverity(policy) {
1216
+ if (policy === "ignore") return void 0;
1217
+ return policy === "error" ? "error" : "warning";
1218
+ }
1219
+ function voiceLocalePrefix(voiceName) {
1220
+ const match = /^(?<language>[A-Za-z]{2,3})-(?<region>[A-Za-z]{2}|\d{3})(?:-|$)/.exec(voiceName.trim());
1221
+ if (!match?.groups) return void 0;
1222
+ return {
1223
+ language: match.groups.language.toLowerCase(),
1224
+ region: match.groups.region.toLowerCase()
1225
+ };
1226
+ }
1227
+ function languageLocalePrefix(language) {
1228
+ const match = /^(?<language>[A-Za-z]{2,3})(?:-(?<region>[A-Za-z]{2}|\d{3}))?(?:-|$)/.exec(language.trim());
1229
+ if (!match?.groups) return void 0;
1230
+ return {
1231
+ language: match.groups.language.toLowerCase(),
1232
+ region: match.groups.region?.toLowerCase()
1233
+ };
1234
+ }
1235
+ function voiceMatchesLanguage(voiceName, language) {
1236
+ const voiceLocale = voiceLocalePrefix(voiceName);
1237
+ const languageLocale = languageLocalePrefix(language);
1238
+ if (!voiceLocale || !languageLocale) return void 0;
1239
+ return voiceLocale.language === languageLocale.language && (languageLocale.region === void 0 || voiceLocale.region === languageLocale.region);
1240
+ }
1241
+ function validateElement(token, source, diagnostics, voiceName, options, voiceStyleMap) {
1164
1242
  const name = token.name.toLowerCase();
1165
1243
  if (name === "voice" && !attr(token, "name")?.trim())
1166
1244
  addDiagnostic(diagnostics, source, token.start, '<voice> requires a non-empty "name" attribute.');
@@ -1202,9 +1280,24 @@ function validateElement(token, source, diagnostics, voiceName, options) {
1202
1280
  const role = attr(token, "role");
1203
1281
  if (role && !ALLOWED_ROLES.has(role))
1204
1282
  addDiagnostic(diagnostics, source, token.start, `Unsupported <mstts:express-as role> value "${role}".`);
1205
- const supportedStyles = voiceName ? EXPRESS_AS_STYLES[voiceName.toLowerCase()] : void 0;
1206
- if (style && supportedStyles && !supportedStyles.includes(style.toLowerCase()))
1207
- addDiagnostic(diagnostics, source, token.start, `Style "${style}" is not supported by voice "${voiceName}".`);
1283
+ const supportedStyles = voiceName ? voiceStyleMap.get(voiceName.toLowerCase()) : void 0;
1284
+ const severity = diagnosticSeverity(options.unknownVoicePolicy ?? "warn");
1285
+ if (style && supportedStyles && !supportedStyles.includes(style.toLowerCase()) && severity)
1286
+ addDiagnostic(
1287
+ diagnostics,
1288
+ source,
1289
+ token.start,
1290
+ `Unknown style "${style}" is not supported by voice "${voiceName}" according to the configured voice style map.`,
1291
+ severity
1292
+ );
1293
+ if (style && voiceName && !supportedStyles && severity)
1294
+ addDiagnostic(
1295
+ diagnostics,
1296
+ source,
1297
+ token.start,
1298
+ `Unknown style "${style}" cannot be verified because voice "${voiceName}" is not registered in the voice style map.`,
1299
+ severity
1300
+ );
1208
1301
  }
1209
1302
  if (name === "say-as" || name === "sayas") {
1210
1303
  const interpretAs = attr(token, "interpret-as");
@@ -1264,6 +1357,14 @@ function validateElement(token, source, diagnostics, voiceName, options) {
1264
1357
  addDiagnostic(diagnostics, source, token.start, "<audio src> must use HTTPS.");
1265
1358
  if (options.allowedAudioOrigins && !options.allowedAudioOrigins.includes(parsed.origin))
1266
1359
  addDiagnostic(diagnostics, source, token.start, `<audio src> origin "${parsed.origin}" is not allowed.`);
1360
+ else if (!options.allowExternalAudio)
1361
+ addDiagnostic(
1362
+ diagnostics,
1363
+ source,
1364
+ token.start,
1365
+ `<audio src> external origin "${parsed.origin}" is blocked by default; set allowExternalAudio to true or provide allowedAudioOrigins.`,
1366
+ "error"
1367
+ );
1267
1368
  }
1268
1369
  }
1269
1370
  }
@@ -1294,7 +1395,33 @@ function validateAzureSsml(ssml, options = {}) {
1294
1395
  "Azure SSML requires at least one <voice> element under <speak>."
1295
1396
  );
1296
1397
  const voiceName = voices[0] ? attr(voices[0], "name") : void 0;
1297
- for (const token of tokens) validateElement(token, ssml, diagnostics, voiceName, options);
1398
+ const voiceStyleMap = normalizeVoiceStyleMap(options.customVoiceStyleMap);
1399
+ const policySeverity = diagnosticSeverity(options.unknownVoicePolicy ?? "warn");
1400
+ const voicesToValidate = options.validateNestedVoices === false ? voices.slice(0, 1) : voices;
1401
+ for (const token of voicesToValidate) {
1402
+ const name = attr(token, "name")?.trim();
1403
+ const language = attr(token, "xml:lang")?.trim() || (speak ? attr(speak, "xml:lang")?.trim() : void 0);
1404
+ if (name && !voiceStyleMap.has(name.toLowerCase()) && policySeverity)
1405
+ addDiagnostic(
1406
+ diagnostics,
1407
+ ssml,
1408
+ token.start,
1409
+ `Unknown voice "${name}" is not registered in the voice style map.`,
1410
+ policySeverity
1411
+ );
1412
+ if (name && language && voiceMatchesLanguage(name, language) === false)
1413
+ addDiagnostic(
1414
+ diagnostics,
1415
+ ssml,
1416
+ token.start,
1417
+ `Voice "${name}" does not match language "${language}"; the voice name prefix indicates a different language or region.`,
1418
+ "warning"
1419
+ );
1420
+ }
1421
+ for (const token of tokens) {
1422
+ const tokenVoiceName = options.validateNestedVoices === false ? voiceName : token.parentVoiceName;
1423
+ validateElement(token, ssml, diagnostics, tokenVoiceName, options, voiceStyleMap);
1424
+ }
1298
1425
  return diagnostics;
1299
1426
  }
1300
1427
 
@@ -1307,4 +1434,4 @@ export {
1307
1434
  mapSsmlTextNodes,
1308
1435
  validateAzureSsml
1309
1436
  };
1310
- //# sourceMappingURL=chunk-RUIEMCWP.mjs.map
1437
+ //# sourceMappingURL=chunk-GTARZC43.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../packages/ssml-core/src/constants/ssml.ts","../packages/ssml-core/src/builder.ts","../packages/ssml-core/src/parser.ts","../packages/ssml-core/src/partial.ts","../packages/ssml-core/src/validation.ts","../packages/ssml-core/src/textNodes.ts","../packages/ssml-core/src/azureValidation.ts"],"sourcesContent":["export const SYNTHESIS_NAMESPACE = \"http://www.w3.org/2001/10/synthesis\" as const;\nexport const MSTTS_NAMESPACE = \"http://www.w3.org/2001/mstts\" as const;\nexport const DEFAULT_SSML_VERSION = \"1.0\" as const;\nexport const DEFAULT_SSML_LANGUAGE = \"en-US\" as const;\nexport const MAX_NESTING_DEPTH = 1000;\nexport const XML_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_.:-]*$/;\nexport const MSTTS_TAG_PREFIX = \"mstts:\" as const;\n\nexport const SSML_TAGS = {\n SPEAK: \"speak\",\n VOICE: \"voice\",\n PROSODY: \"prosody\",\n BREAK: \"break\",\n EXPRESS_AS: \"express-as\",\n EXPRESS_AS_CAMEL: \"expressAs\",\n MSTTS_EXPRESS_AS: \"mstts:express-as\",\n SAY_AS: \"say-as\",\n SAY_AS_CAMEL: \"sayAs\",\n PHONEME: \"phoneme\",\n EMPHASIS: \"emphasis\",\n AUDIO: \"audio\",\n SUB: \"sub\",\n LANG: \"lang\",\n MARK: \"mark\",\n BOOKMARK: \"bookmark\",\n LEXICON: \"lexicon\",\n PARAGRAPH: \"p\",\n SENTENCE: \"s\",\n WORD: \"w\",\n MSTTS_SILENCE: \"mstts:silence\",\n SILENCE: \"silence\",\n MSTTS_VISEME: \"mstts:viseme\",\n VISEME: \"viseme\",\n} as const;\n\nexport const SSML_ATTRS = {\n VERSION: \"version\",\n XMLNS: \"xmlns\",\n XML_LANG: \"xml:lang\",\n LANG: \"lang\",\n MSTTS_XMLNS: \"xmlns:mstts\",\n NAME: \"name\",\n EFFECT: \"effect\",\n RATE: \"rate\",\n PITCH: \"pitch\",\n VOLUME: \"volume\",\n CONTOUR: \"contour\",\n RANGE: \"range\",\n TIME: \"time\",\n STRENGTH: \"strength\",\n STYLE: \"style\",\n STYLE_DEGREE: \"styledegree\",\n STYLE_DEGREE_CAMEL: \"styleDegree\",\n STYLE_DEGREE_HYPHEN: \"style-degree\",\n ROLE: \"role\",\n INTERPRET_AS: \"interpret-as\",\n FORMAT: \"format\",\n DETAIL: \"detail\",\n ALPHABET: \"alphabet\",\n PH: \"ph\",\n LEVEL: \"level\",\n SRC: \"src\",\n DESC: \"desc\",\n CLIP_BEGIN: \"clipBegin\",\n CLIP_END: \"clipEnd\",\n SPEED: \"speed\",\n REPEAT_COUNT: \"repeatCount\",\n REPEAT_DURATION: \"repeatDuration\",\n SOUND_LEVEL: \"soundLevel\",\n ALIAS: \"alias\",\n MARK: \"mark\",\n URI: \"uri\",\n TYPE: \"type\",\n VALUE: \"value\",\n} as const;\n","import type {\n SsmlAttributeValue,\n SsmlAttributes,\n SsmlDocument,\n SsmlElement,\n SsmlElementBase,\n SsmlNode,\n} from \"./types.ts\";\nimport {\n DEFAULT_SSML_LANGUAGE,\n DEFAULT_SSML_VERSION,\n MSTTS_NAMESPACE,\n MSTTS_TAG_PREFIX,\n SSML_ATTRS,\n SSML_TAGS,\n SYNTHESIS_NAMESPACE,\n XML_NAME_PATTERN,\n} from \"./constants/ssml.ts\";\n\nfunction escapeText(value: string): string {\n return value.replace(/&/g, \"&amp;\").replace(/</g, \"&lt;\").replace(/>/g, \"&gt;\");\n}\n\nfunction escapeAttribute(value: string): string {\n return escapeText(value).replace(/\"/g, \"&quot;\").replace(/'/g, \"&apos;\");\n}\n\nfunction addAttribute(attributes: SsmlAttributes, name: string, value: SsmlAttributeValue | undefined): void {\n if (value !== undefined) {\n attributes[name] = value;\n }\n}\n\nfunction getAttributes(element: SsmlElement): SsmlAttributes {\n const attributes: SsmlAttributes = {\n ...(element.attributes ?? {}),\n };\n\n switch (element.type) {\n case SSML_TAGS.VOICE:\n addAttribute(attributes, SSML_ATTRS.NAME, element.name);\n addAttribute(attributes, SSML_ATTRS.EFFECT, element.effect);\n break;\n case SSML_TAGS.PROSODY:\n addAttribute(attributes, SSML_ATTRS.RATE, element.rate);\n addAttribute(attributes, SSML_ATTRS.PITCH, element.pitch);\n addAttribute(attributes, SSML_ATTRS.VOLUME, element.volume);\n addAttribute(attributes, SSML_ATTRS.CONTOUR, element.contour);\n addAttribute(attributes, SSML_ATTRS.RANGE, element.range);\n break;\n case SSML_TAGS.BREAK:\n addAttribute(attributes, SSML_ATTRS.TIME, element.time);\n addAttribute(attributes, SSML_ATTRS.STRENGTH, element.strength);\n break;\n case SSML_TAGS.EXPRESS_AS:\n case SSML_TAGS.EXPRESS_AS_CAMEL:\n case SSML_TAGS.MSTTS_EXPRESS_AS:\n addAttribute(attributes, SSML_ATTRS.STYLE, element.style);\n addAttribute(attributes, SSML_ATTRS.STYLE_DEGREE, element.styleDegree);\n addAttribute(attributes, SSML_ATTRS.ROLE, element.role);\n break;\n case SSML_TAGS.SAY_AS:\n case SSML_TAGS.SAY_AS_CAMEL:\n addAttribute(attributes, SSML_ATTRS.INTERPRET_AS, element.interpretAs);\n addAttribute(attributes, SSML_ATTRS.FORMAT, element.format);\n addAttribute(attributes, SSML_ATTRS.DETAIL, element.detail);\n break;\n case SSML_TAGS.PHONEME:\n addAttribute(attributes, SSML_ATTRS.ALPHABET, element.alphabet);\n addAttribute(attributes, SSML_ATTRS.PH, element.ph);\n break;\n case SSML_TAGS.EMPHASIS:\n addAttribute(attributes, SSML_ATTRS.LEVEL, element.level);\n break;\n case SSML_TAGS.AUDIO:\n addAttribute(attributes, SSML_ATTRS.SRC, element.src);\n addAttribute(attributes, SSML_ATTRS.DESC, element.desc);\n addAttribute(attributes, SSML_ATTRS.CLIP_BEGIN, element.clipBegin);\n addAttribute(attributes, SSML_ATTRS.CLIP_END, element.clipEnd);\n addAttribute(attributes, SSML_ATTRS.SPEED, element.speed);\n addAttribute(attributes, SSML_ATTRS.REPEAT_COUNT, element.repeatCount);\n addAttribute(attributes, SSML_ATTRS.REPEAT_DURATION, element.repeatDuration);\n addAttribute(attributes, SSML_ATTRS.SOUND_LEVEL, element.soundLevel);\n break;\n case SSML_TAGS.SUB:\n addAttribute(attributes, SSML_ATTRS.ALIAS, element.alias);\n break;\n case SSML_TAGS.LANG:\n addAttribute(attributes, SSML_ATTRS.XML_LANG, element.lang);\n break;\n case SSML_TAGS.MARK:\n addAttribute(attributes, SSML_ATTRS.NAME, element.name);\n break;\n case SSML_TAGS.BOOKMARK:\n addAttribute(attributes, SSML_ATTRS.MARK, element.mark);\n break;\n case SSML_TAGS.LEXICON:\n addAttribute(attributes, SSML_ATTRS.URI, element.uri);\n break;\n case SSML_TAGS.MSTTS_SILENCE:\n case SSML_TAGS.SILENCE:\n addAttribute(attributes, SSML_ATTRS.TYPE, element.typeValue ?? element.silenceType);\n addAttribute(attributes, SSML_ATTRS.VALUE, element.value);\n break;\n case SSML_TAGS.MSTTS_VISEME:\n case SSML_TAGS.VISEME:\n addAttribute(attributes, SSML_ATTRS.TYPE, element.typeValue ?? element.visemeType);\n break;\n case SSML_TAGS.PARAGRAPH:\n case SSML_TAGS.SENTENCE:\n case SSML_TAGS.WORD:\n case \"element\":\n case \"custom\":\n break;\n }\n\n return attributes;\n}\n\nfunction getTagName(element: SsmlElement): string {\n switch (element.type) {\n case SSML_TAGS.EXPRESS_AS:\n case SSML_TAGS.EXPRESS_AS_CAMEL:\n case SSML_TAGS.MSTTS_EXPRESS_AS:\n return SSML_TAGS.MSTTS_EXPRESS_AS;\n case SSML_TAGS.SAY_AS:\n case SSML_TAGS.SAY_AS_CAMEL:\n return SSML_TAGS.SAY_AS;\n case SSML_TAGS.SILENCE:\n case SSML_TAGS.MSTTS_SILENCE:\n return SSML_TAGS.MSTTS_SILENCE;\n case SSML_TAGS.VISEME:\n case SSML_TAGS.MSTTS_VISEME:\n return SSML_TAGS.MSTTS_VISEME;\n case \"element\":\n case \"custom\":\n return element.name;\n default:\n return element.type;\n }\n}\n\nfunction getChildren(element: SsmlElementBase): SsmlNode[] {\n return element.children ?? [];\n}\n\nfunction validateName(name: string, kind: \"element\" | \"attribute\"): void {\n if (!XML_NAME_PATTERN.test(name)) {\n throw new Error(`Invalid XML ${kind} name: ${name}`);\n }\n}\n\nfunction serializeAttributes(attributes: SsmlAttributes): string {\n return Object.entries(attributes)\n .map(([name, value]) => {\n validateName(name, \"attribute\");\n return ` ${name}=\"${escapeAttribute(String(value))}\"`;\n })\n .join(\"\");\n}\n\nfunction serializeNode(node: SsmlNode): string {\n if (typeof node === \"string\") {\n return escapeText(node);\n }\n\n if (node.type === \"text\") {\n return escapeText(node.value);\n }\n\n const tagName = getTagName(node);\n validateName(tagName, \"element\");\n\n const attributes = serializeAttributes(getAttributes(node));\n const children = getChildren(node);\n if (children.length === 0) {\n return `<${tagName}${attributes}/>`;\n }\n\n return `<${tagName}${attributes}>${children.map(serializeNode).join(\"\")}</${tagName}>`;\n}\n\nfunction usesMsttsNamespace(nodes: SsmlNode[]): boolean {\n return nodes.some((node) => {\n if (typeof node === \"string\" || node.type === \"text\") {\n return false;\n }\n\n const tagName = getTagName(node);\n return tagName.startsWith(MSTTS_TAG_PREFIX) || usesMsttsNamespace(getChildren(node));\n });\n}\n\nfunction serializeDocument(document: SsmlDocument): string {\n const children = document.children ?? (document.content === undefined ? [] : [document.content]);\n const attributes: SsmlAttributes = {\n ...(document.attributes ?? {}),\n [SSML_ATTRS.VERSION]: document.version,\n [SSML_ATTRS.XMLNS]: SYNTHESIS_NAMESPACE,\n [SSML_ATTRS.XML_LANG]: document.lang,\n };\n\n if (usesMsttsNamespace(children) && attributes[SSML_ATTRS.MSTTS_XMLNS] === undefined) {\n attributes[SSML_ATTRS.MSTTS_XMLNS] = MSTTS_NAMESPACE;\n }\n\n return `<${SSML_TAGS.SPEAK}${serializeAttributes(attributes)}>${children.map(serializeNode).join(\"\")}</${SSML_TAGS.SPEAK}>`;\n}\n\nexport function buildSsml(document: SsmlDocument): string;\nexport function buildSsml(content: string, lang?: string): SsmlDocument;\nexport function buildSsml(\n documentOrContent: SsmlDocument | string,\n lang: string = DEFAULT_SSML_LANGUAGE,\n): string | SsmlDocument {\n if (typeof documentOrContent === \"string\") {\n return {\n version: DEFAULT_SSML_VERSION,\n lang,\n content: documentOrContent,\n };\n }\n\n return serializeDocument(documentOrContent);\n}\n","import type {\n AudioElement,\n BookmarkElement,\n BreakElement,\n CustomElement,\n EmphasisElement,\n ExpressAsElement,\n LangElement,\n LexiconElement,\n MarkElement,\n MsttsSilenceElement,\n MsttsVisemeElement,\n ParagraphElement,\n PhonemeElement,\n ProsodyElement,\n SayAsElement,\n SentenceElement,\n SsmlAttributes,\n SsmlDocument,\n SsmlElement,\n SsmlNode,\n SubElement,\n VoiceElement,\n WordElement,\n} from \"./types.ts\";\nimport { MAX_NESTING_DEPTH, MSTTS_NAMESPACE, SSML_ATTRS, SSML_TAGS, SYNTHESIS_NAMESPACE } from \"./constants/ssml.ts\";\n\ninterface XmlElementNode {\n name: string;\n attributes: SsmlAttributes;\n children: XmlNode[];\n}\n\ntype XmlNode = string | XmlElementNode;\n\nconst XML_ENTITIES: Record<string, string> = {\n amp: \"&\",\n apos: \"'\",\n gt: \">\",\n lt: \"<\",\n quot: '\"',\n};\n\nfunction hasOwn(object: object, property: PropertyKey): boolean {\n return Object.getOwnPropertyDescriptor(object, property) !== undefined;\n}\n\nfunction setAttribute(attributes: SsmlAttributes, name: string, value: string): void {\n Object.defineProperty(attributes, name, {\n configurable: true,\n enumerable: true,\n value,\n writable: true,\n });\n}\n\nfunction decodeEntity(entity: string): string {\n const namedValue = hasOwn(XML_ENTITIES, entity) ? XML_ENTITIES[entity] : undefined;\n if (namedValue !== undefined) {\n return namedValue;\n }\n\n const isHexadecimal = entity.startsWith(\"#x\") || entity.startsWith(\"#X\");\n const isDecimal = entity.startsWith(\"#\");\n if (!isHexadecimal && !isDecimal) {\n throw new Error(`Unknown XML entity: &${entity};`);\n }\n\n const digits = entity.slice(isHexadecimal ? 2 : 1);\n const codePoint = Number.parseInt(digits, isHexadecimal ? 16 : 10);\n if (\n !digits ||\n !Number.isInteger(codePoint) ||\n codePoint < 0 ||\n codePoint > 0x10ffff ||\n (codePoint >= 0xd800 && codePoint <= 0xdfff) ||\n (codePoint < 0x20 && ![9, 10, 13].includes(codePoint))\n ) {\n throw new Error(`Invalid XML character reference: &${entity};`);\n }\n\n return String.fromCodePoint(codePoint);\n}\n\nfunction decodeXmlEntities(value: string): string {\n let result = \"\";\n let start = 0;\n\n while (true) {\n const ampersand = value.indexOf(\"&\", start);\n if (ampersand === -1) {\n return result + value.slice(start);\n }\n\n result += value.slice(start, ampersand);\n const semicolon = value.indexOf(\";\", ampersand + 1);\n if (semicolon === -1) {\n throw new Error(\"Unterminated XML entity reference\");\n }\n\n result += decodeEntity(value.slice(ampersand + 1, semicolon));\n start = semicolon + 1;\n }\n}\n\nfunction isXmlNameStart(value: string | undefined): boolean {\n return value !== undefined && /[A-Za-z_]/.test(value);\n}\n\nfunction isXmlNameCharacter(value: string | undefined): boolean {\n return value !== undefined && /[A-Za-z0-9_.:-]/.test(value);\n}\n\nfunction isXmlWhitespace(value: string | undefined): boolean {\n return value === \" \" || value === \"\\t\" || value === \"\\r\" || value === \"\\n\";\n}\n\nfunction removeStandardNamespaceAttributes(attributes: SsmlAttributes): void {\n if (attributes[SSML_ATTRS.XMLNS] === SYNTHESIS_NAMESPACE) {\n delete attributes[SSML_ATTRS.XMLNS];\n }\n if (attributes[SSML_ATTRS.MSTTS_XMLNS] === MSTTS_NAMESPACE) {\n delete attributes[SSML_ATTRS.MSTTS_XMLNS];\n }\n}\n\nclass XmlParser {\n #index = 0;\n private readonly source: string;\n\n constructor(source: string) {\n this.source = source;\n }\n\n parse(): XmlElementNode {\n if (this.source.charCodeAt(0) === 0xfeff) {\n this.#index += 1;\n }\n\n this.skipMisc();\n if (this.#index >= this.source.length) {\n this.fail(\"SSML input is empty\");\n }\n if (this.source[this.#index] !== \"<\") {\n this.fail(\"SSML input must start with an XML element\");\n }\n\n const root = this.parseElement(0);\n this.skipMisc();\n if (this.#index !== this.source.length) {\n this.fail(\"Unexpected content after the root XML element\");\n }\n return root;\n }\n\n private parseElement(depth: number): XmlElementNode {\n if (depth > MAX_NESTING_DEPTH) {\n this.fail(\"XML nesting depth exceeds the supported limit\");\n }\n\n this.expect(\"<\");\n if (this.source[this.#index] === \"/\") {\n this.fail(\"Unexpected closing XML element\");\n }\n\n const name = this.parseName();\n const { attributes, selfClosing } = this.parseStartTag();\n if (selfClosing) {\n return { name, attributes, children: [] };\n }\n\n const children: XmlNode[] = [];\n while (this.#index < this.source.length) {\n if (this.source.startsWith(\"</\", this.#index)) {\n this.#index += 2;\n const closingName = this.parseName();\n this.skipWhitespace();\n this.expect(\">\");\n if (closingName !== name) {\n this.fail(`Mismatched closing element: expected </${name}> but found </${closingName}>`);\n }\n return { name, attributes, children };\n }\n\n if (this.source.startsWith(\"<!--\", this.#index)) {\n this.skipComment();\n continue;\n }\n\n if (this.source.startsWith(\"<![CDATA[\", this.#index)) {\n this.appendText(children, this.parseCdata());\n continue;\n }\n\n if (this.source.startsWith(\"<?\", this.#index)) {\n this.skipProcessingInstruction();\n continue;\n }\n\n if (this.source.startsWith(\"<!\", this.#index)) {\n this.fail(\"Unsupported XML declaration inside an element\");\n }\n\n if (this.source[this.#index] === \"<\") {\n children.push(this.parseElement(depth + 1));\n } else {\n this.appendText(children, this.parseText());\n }\n }\n\n this.fail(`Unclosed XML element: <${name}>`);\n }\n\n private parseStartTag(): {\n attributes: SsmlAttributes;\n selfClosing: boolean;\n } {\n const attributes: SsmlAttributes = {};\n\n while (this.#index < this.source.length) {\n this.skipWhitespace();\n\n if (this.source.startsWith(\"/>\", this.#index)) {\n this.#index += 2;\n return { attributes, selfClosing: true };\n }\n if (this.source[this.#index] === \">\") {\n this.#index += 1;\n return { attributes, selfClosing: false };\n }\n\n const name = this.parseName();\n this.skipWhitespace();\n this.expect(\"=\");\n this.skipWhitespace();\n\n const quote = this.source[this.#index];\n if (quote !== '\"' && quote !== \"'\") {\n this.fail(`XML attribute ${name} must use a quoted value`);\n }\n this.#index += 1;\n\n const valueStart = this.#index;\n while (this.#index < this.source.length && this.source[this.#index] !== quote) {\n if (this.source[this.#index] === \"<\") {\n this.fail(`Invalid \"<\" in XML attribute ${name}`);\n }\n this.#index += 1;\n }\n if (this.#index >= this.source.length) {\n this.fail(`Unclosed XML attribute ${name}`);\n }\n\n const value = decodeXmlEntities(this.source.slice(valueStart, this.#index));\n this.#index += 1;\n\n if (hasOwn(attributes, name)) {\n this.fail(`Duplicate XML attribute: ${name}`);\n }\n setAttribute(attributes, name, value);\n }\n\n this.fail(\"Unclosed XML start tag\");\n }\n\n private parseText(): string {\n const start = this.#index;\n while (this.#index < this.source.length && this.source[this.#index] !== \"<\") {\n this.#index += 1;\n }\n\n const value = this.source.slice(start, this.#index);\n if (value.includes(\"]]>\")) {\n this.fail(\"CDATA termination is not valid in ordinary XML text\");\n }\n return decodeXmlEntities(value);\n }\n\n private parseCdata(): string {\n this.#index += \"<![CDATA[\".length;\n const end = this.source.indexOf(\"]]>\", this.#index);\n if (end === -1) {\n this.fail(\"Unclosed XML CDATA section\");\n }\n\n const value = this.source.slice(this.#index, end);\n this.#index = end + 3;\n return value;\n }\n\n private skipComment(): void {\n this.#index += \"<!--\".length;\n const end = this.source.indexOf(\"-->\", this.#index);\n if (end === -1) {\n this.fail(\"Unclosed XML comment\");\n }\n if (this.source.slice(this.#index, end).includes(\"--\")) {\n this.fail(\"XML comments cannot contain consecutive hyphens\");\n }\n this.#index = end + 3;\n }\n\n private skipProcessingInstruction(): void {\n this.#index += \"<?\".length;\n this.parseName();\n const end = this.source.indexOf(\"?>\", this.#index);\n if (end === -1) {\n this.fail(\"Unclosed XML processing instruction\");\n }\n this.#index = end + 2;\n }\n\n private skipMisc(): void {\n while (this.#index < this.source.length) {\n this.skipWhitespace();\n if (this.source.startsWith(\"<!--\", this.#index)) {\n this.skipComment();\n continue;\n }\n if (this.source.startsWith(\"<?\", this.#index)) {\n this.skipProcessingInstruction();\n continue;\n }\n if (this.source.startsWith(\"<!DOCTYPE\", this.#index)) {\n this.fail(\"DOCTYPE declarations are not supported\");\n }\n break;\n }\n }\n\n private parseName(): string {\n const first = this.source[this.#index];\n if (!isXmlNameStart(first)) {\n this.fail(\"Invalid XML name\");\n }\n\n const start = this.#index;\n this.#index += 1;\n while (isXmlNameCharacter(this.source[this.#index])) {\n this.#index += 1;\n }\n return this.source.slice(start, this.#index);\n }\n\n private appendText(children: XmlNode[], value: string): void {\n if (!value) {\n return;\n }\n\n const previous = children[children.length - 1];\n if (typeof previous === \"string\") {\n children[children.length - 1] = previous + value;\n } else {\n children.push(value);\n }\n }\n\n private skipWhitespace(): void {\n while (isXmlWhitespace(this.source[this.#index])) {\n this.#index += 1;\n }\n }\n\n private expect(value: string): void {\n if (!this.source.startsWith(value, this.#index)) {\n this.fail(`Expected \"${value}\"`);\n }\n this.#index += value.length;\n }\n\n private fail(message: string): never {\n throw new Error(`${message} at position ${this.#index}`);\n }\n}\n\nfunction readAttribute(attributes: SsmlAttributes, ...names: string[]): string | undefined {\n let found = false;\n let value: string | undefined;\n\n for (const name of names) {\n if (hasOwn(attributes, name)) {\n if (!found) {\n value = String(attributes[name]);\n found = true;\n }\n delete attributes[name];\n }\n }\n\n return value;\n}\n\nfunction getElementAttributes(node: XmlElementNode): SsmlAttributes {\n const attributes: SsmlAttributes = { ...node.attributes };\n removeStandardNamespaceAttributes(attributes);\n return attributes;\n}\n\nfunction finishElement<T extends SsmlElement>(element: T, node: XmlElementNode, attributes: SsmlAttributes): T {\n if (node.children.length > 0) {\n element.children = node.children.map(convertNode);\n }\n if (Object.keys(attributes).length > 0) {\n element.attributes = attributes;\n }\n return element;\n}\n\nfunction convertElement(node: XmlElementNode): SsmlElement {\n const attributes = getElementAttributes(node);\n\n switch (node.name) {\n case SSML_TAGS.VOICE: {\n const element: VoiceElement = { type: SSML_TAGS.VOICE };\n const name = readAttribute(attributes, SSML_ATTRS.NAME);\n const effect = readAttribute(attributes, SSML_ATTRS.EFFECT);\n if (name !== undefined) element.name = name;\n if (effect !== undefined) element.effect = effect;\n return finishElement(element, node, attributes);\n }\n case SSML_TAGS.PROSODY: {\n const element: ProsodyElement = { type: SSML_TAGS.PROSODY };\n const rate = readAttribute(attributes, SSML_ATTRS.RATE);\n const pitch = readAttribute(attributes, SSML_ATTRS.PITCH);\n const volume = readAttribute(attributes, SSML_ATTRS.VOLUME);\n const contour = readAttribute(attributes, SSML_ATTRS.CONTOUR);\n const range = readAttribute(attributes, SSML_ATTRS.RANGE);\n if (rate !== undefined) element.rate = rate;\n if (pitch !== undefined) element.pitch = pitch;\n if (volume !== undefined) element.volume = volume;\n if (contour !== undefined) element.contour = contour;\n if (range !== undefined) element.range = range;\n return finishElement(element, node, attributes);\n }\n case SSML_TAGS.BREAK: {\n const element: BreakElement = { type: SSML_TAGS.BREAK };\n const time = readAttribute(attributes, SSML_ATTRS.TIME);\n const strength = readAttribute(attributes, SSML_ATTRS.STRENGTH);\n if (time !== undefined) element.time = time;\n if (strength !== undefined) element.strength = strength;\n return finishElement(element, node, attributes);\n }\n case SSML_TAGS.EXPRESS_AS:\n case SSML_TAGS.EXPRESS_AS_CAMEL:\n case SSML_TAGS.MSTTS_EXPRESS_AS: {\n const element: ExpressAsElement = { type: node.name };\n const style = readAttribute(attributes, SSML_ATTRS.STYLE);\n const styleDegree = readAttribute(\n attributes,\n SSML_ATTRS.STYLE_DEGREE,\n SSML_ATTRS.STYLE_DEGREE_CAMEL,\n SSML_ATTRS.STYLE_DEGREE_HYPHEN,\n );\n const role = readAttribute(attributes, SSML_ATTRS.ROLE);\n if (style !== undefined) element.style = style;\n if (styleDegree !== undefined) element.styleDegree = styleDegree;\n if (role !== undefined) element.role = role;\n return finishElement(element, node, attributes);\n }\n case SSML_TAGS.SAY_AS:\n case SSML_TAGS.SAY_AS_CAMEL: {\n const element: SayAsElement = { type: node.name };\n const interpretAs = readAttribute(attributes, SSML_ATTRS.INTERPRET_AS);\n const format = readAttribute(attributes, SSML_ATTRS.FORMAT);\n const detail = readAttribute(attributes, SSML_ATTRS.DETAIL);\n if (interpretAs !== undefined) element.interpretAs = interpretAs;\n if (format !== undefined) element.format = format;\n if (detail !== undefined) element.detail = detail;\n return finishElement(element, node, attributes);\n }\n case SSML_TAGS.PHONEME: {\n const element: PhonemeElement = { type: SSML_TAGS.PHONEME };\n const alphabet = readAttribute(attributes, SSML_ATTRS.ALPHABET);\n const ph = readAttribute(attributes, SSML_ATTRS.PH);\n if (alphabet !== undefined) element.alphabet = alphabet;\n if (ph !== undefined) element.ph = ph;\n return finishElement(element, node, attributes);\n }\n case SSML_TAGS.EMPHASIS: {\n const element: EmphasisElement = { type: SSML_TAGS.EMPHASIS };\n const level = readAttribute(attributes, SSML_ATTRS.LEVEL);\n if (level !== undefined) element.level = level;\n return finishElement(element, node, attributes);\n }\n case SSML_TAGS.AUDIO: {\n const element: AudioElement = { type: SSML_TAGS.AUDIO };\n const src = readAttribute(attributes, SSML_ATTRS.SRC);\n const desc = readAttribute(attributes, SSML_ATTRS.DESC);\n const clipBegin = readAttribute(attributes, SSML_ATTRS.CLIP_BEGIN);\n const clipEnd = readAttribute(attributes, SSML_ATTRS.CLIP_END);\n const speed = readAttribute(attributes, SSML_ATTRS.SPEED);\n const repeatCount = readAttribute(attributes, SSML_ATTRS.REPEAT_COUNT);\n const repeatDuration = readAttribute(attributes, SSML_ATTRS.REPEAT_DURATION);\n const soundLevel = readAttribute(attributes, SSML_ATTRS.SOUND_LEVEL);\n if (src !== undefined) element.src = src;\n if (desc !== undefined) element.desc = desc;\n if (clipBegin !== undefined) element.clipBegin = clipBegin;\n if (clipEnd !== undefined) element.clipEnd = clipEnd;\n if (speed !== undefined) element.speed = speed;\n if (repeatCount !== undefined) element.repeatCount = repeatCount;\n if (repeatDuration !== undefined) element.repeatDuration = repeatDuration;\n if (soundLevel !== undefined) element.soundLevel = soundLevel;\n return finishElement(element, node, attributes);\n }\n case SSML_TAGS.SUB: {\n const element: SubElement = { type: SSML_TAGS.SUB };\n const alias = readAttribute(attributes, SSML_ATTRS.ALIAS);\n if (alias !== undefined) element.alias = alias;\n return finishElement(element, node, attributes);\n }\n case SSML_TAGS.LANG: {\n const element: LangElement = { type: SSML_TAGS.LANG };\n const lang = readAttribute(attributes, SSML_ATTRS.XML_LANG, SSML_ATTRS.LANG);\n if (lang !== undefined) element.lang = lang;\n return finishElement(element, node, attributes);\n }\n case SSML_TAGS.MARK: {\n const element: MarkElement = { type: SSML_TAGS.MARK };\n const name = readAttribute(attributes, SSML_ATTRS.NAME);\n if (name !== undefined) element.name = name;\n return finishElement(element, node, attributes);\n }\n case SSML_TAGS.BOOKMARK: {\n const element: BookmarkElement = { type: SSML_TAGS.BOOKMARK };\n const mark = readAttribute(attributes, SSML_ATTRS.MARK);\n if (mark !== undefined) element.mark = mark;\n return finishElement(element, node, attributes);\n }\n case SSML_TAGS.LEXICON: {\n const element: LexiconElement = { type: SSML_TAGS.LEXICON };\n const uri = readAttribute(attributes, SSML_ATTRS.URI);\n if (uri !== undefined) element.uri = uri;\n return finishElement(element, node, attributes);\n }\n case SSML_TAGS.PARAGRAPH: {\n const element: ParagraphElement = { type: SSML_TAGS.PARAGRAPH };\n return finishElement(element, node, attributes);\n }\n case SSML_TAGS.SENTENCE: {\n const element: SentenceElement = { type: SSML_TAGS.SENTENCE };\n return finishElement(element, node, attributes);\n }\n case SSML_TAGS.WORD: {\n const element: WordElement = { type: SSML_TAGS.WORD };\n return finishElement(element, node, attributes);\n }\n case SSML_TAGS.MSTTS_SILENCE:\n case SSML_TAGS.SILENCE: {\n const element: MsttsSilenceElement = {\n type: node.name === SSML_TAGS.MSTTS_SILENCE ? SSML_TAGS.MSTTS_SILENCE : SSML_TAGS.SILENCE,\n };\n const typeValue = readAttribute(attributes, SSML_ATTRS.TYPE);\n const value = readAttribute(attributes, SSML_ATTRS.VALUE);\n if (typeValue !== undefined) element.typeValue = typeValue;\n if (value !== undefined) element.value = value;\n return finishElement(element, node, attributes);\n }\n case SSML_TAGS.MSTTS_VISEME:\n case SSML_TAGS.VISEME: {\n const element: MsttsVisemeElement = {\n type: node.name === SSML_TAGS.MSTTS_VISEME ? SSML_TAGS.MSTTS_VISEME : SSML_TAGS.VISEME,\n };\n const typeValue = readAttribute(attributes, SSML_ATTRS.TYPE);\n if (typeValue !== undefined) element.typeValue = typeValue;\n return finishElement(element, node, attributes);\n }\n default: {\n const element: CustomElement = {\n name: node.name,\n type: \"custom\",\n };\n return finishElement(element, node, attributes);\n }\n }\n}\n\nfunction convertNode(node: XmlNode): SsmlNode {\n return typeof node === \"string\" ? node : convertElement(node);\n}\n\nexport function parseSsml(xmlString: string): SsmlDocument {\n if (typeof xmlString !== \"string\") {\n throw new TypeError(\"SSML input must be a string\");\n }\n\n const root = new XmlParser(xmlString).parse();\n if (root.name !== SSML_TAGS.SPEAK) {\n throw new Error(`SSML root element must be <${SSML_TAGS.SPEAK}>, found <${root.name}>`);\n }\n\n const attributes: SsmlAttributes = { ...root.attributes };\n const version = readAttribute(attributes, SSML_ATTRS.VERSION);\n const lang = readAttribute(attributes, SSML_ATTRS.XML_LANG, SSML_ATTRS.LANG);\n if (version === undefined) {\n throw new Error(`SSML <${SSML_TAGS.SPEAK}> element is missing the \"${SSML_ATTRS.VERSION}\" attribute`);\n }\n if (lang === undefined) {\n throw new Error(`SSML <${SSML_TAGS.SPEAK}> element is missing the \"${SSML_ATTRS.XML_LANG}\" attribute`);\n }\n\n removeStandardNamespaceAttributes(attributes);\n const document: SsmlDocument = {\n children: root.children.map(convertNode),\n lang,\n type: SSML_TAGS.SPEAK,\n version,\n };\n if (Object.keys(attributes).length > 0) {\n document.attributes = attributes;\n }\n return document;\n}\n","import { buildSsml } from \"./builder.ts\";\nimport {\n DEFAULT_SSML_LANGUAGE,\n DEFAULT_SSML_VERSION,\n SSML_ATTRS,\n SSML_TAGS,\n SYNTHESIS_NAMESPACE,\n} from \"./constants/ssml.ts\";\nimport { parseSsml } from \"./parser.ts\";\nimport type { ProsodyElement, SsmlAttributes, SsmlDocument, SsmlNode, VoiceElement } from \"./types.ts\";\n\nexport type SsmlPartialVoice = Pick<VoiceElement, \"name\" | \"effect\" | \"attributes\">;\n\nexport type SsmlPartialProsody = Pick<ProsodyElement, \"rate\" | \"pitch\" | \"volume\" | \"contour\" | \"range\" | \"attributes\">;\n\nexport interface SsmlPartialContext {\n /** SSML version used for the generated document. */\n version?: string;\n /** BCP-47 language tag used for the generated document. */\n lang?: string;\n /** Preferred voice name; a voice object takes precedence, while this overrides a string `voice` shorthand. */\n voiceName?: string;\n /** Optional Azure voice effect used with `voiceName` or a string `voice` shorthand. */\n voiceEffect?: string;\n /** A voice name shorthand or a voice object whose attributes are preserved. */\n voice?: string | SsmlPartialVoice;\n /** Optional prosody values applied around the partial text. */\n prosody?: SsmlPartialProsody;\n /** Additional attributes added to the generated `speak` element. */\n attributes?: SsmlAttributes;\n}\n\nexport interface BuildPartialSsmlOptions extends SsmlPartialContext {\n text: string;\n}\n\nfunction escapeAttribute(value: string): string {\n return value\n .replace(/&/g, \"&amp;\")\n .replace(/\"/g, \"&quot;\")\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\")\n .replace(/'/g, \"&apos;\");\n}\n\nfunction getPartialTextNodes(text: string, version: string, lang: string): SsmlNode[] {\n if (!text.includes(\"<\")) {\n return [text];\n }\n\n try {\n const openingTag = `<${SSML_TAGS.SPEAK} ${SSML_ATTRS.VERSION}=\"${escapeAttribute(version)}\" ${SSML_ATTRS.XMLNS}=\"${SYNTHESIS_NAMESPACE}\" ${SSML_ATTRS.XML_LANG}=\"${escapeAttribute(lang)}\">`;\n return parseSsml(`${openingTag}${text}</${SSML_TAGS.SPEAK}>`).children ?? [];\n } catch {\n return [{ type: \"text\", value: text }];\n }\n}\n\nfunction getVoiceContext(context: SsmlPartialContext): SsmlPartialVoice | undefined {\n const voice = context.voice;\n if (typeof voice === \"object\" && voice !== null) {\n return voice;\n }\n\n if (context.voiceName === undefined && context.voiceEffect === undefined && typeof voice !== \"string\") {\n return undefined;\n }\n\n return {\n name: context.voiceName ?? voice,\n effect: context.voiceEffect,\n };\n}\n\nfunction serializePartialSsml(text: string, context: SsmlPartialContext): string {\n const version = context.version ?? DEFAULT_SSML_VERSION;\n const lang = context.lang ?? DEFAULT_SSML_LANGUAGE;\n let children = getPartialTextNodes(text, version, lang);\n\n if (context.prosody) {\n children = [\n {\n type: SSML_TAGS.PROSODY,\n ...context.prosody,\n children,\n },\n ];\n }\n\n const voice = getVoiceContext(context);\n if (voice) {\n children = [\n {\n type: SSML_TAGS.VOICE,\n ...voice,\n children,\n },\n ];\n }\n\n const document: SsmlDocument = {\n type: SSML_TAGS.SPEAK,\n version,\n lang,\n attributes: context.attributes,\n children,\n };\n return buildSsml(document);\n}\n\nexport function buildPartialSsml(text: string, context?: SsmlPartialContext): string;\nexport function buildPartialSsml(options: BuildPartialSsmlOptions): string;\nexport function buildPartialSsml(\n textOrOptions: string | BuildPartialSsmlOptions,\n context?: SsmlPartialContext,\n): string {\n if (typeof textOrOptions === \"string\") {\n return serializePartialSsml(textOrOptions, context ?? {});\n }\n\n return serializePartialSsml(textOrOptions.text, textOrOptions);\n}\n","import { parseSsml } from \"./parser.ts\";\n\nconst PARSER_POSITION_SUFFIX = / at position (\\d+)$/;\n\nexport interface SsmlValidationError {\n message: string;\n position: number;\n}\n\nexport function validateSsml(xmlString: string): SsmlValidationError | null {\n try {\n parseSsml(xmlString);\n return null;\n } catch (error) {\n const rawMessage = error instanceof Error ? error.message : String(error);\n const positionMatch = PARSER_POSITION_SUFFIX.exec(rawMessage);\n\n return {\n message: positionMatch ? rawMessage.slice(0, positionMatch.index) : rawMessage,\n position: positionMatch ? Number.parseInt(positionMatch[1], 10) : 0,\n };\n }\n}\n","import { parseSsml } from \"./parser.ts\";\n\nexport interface SsmlTextNodeContext {\n parentTag: string;\n parentAttributes: Record<string, string>;\n ancestorTags: string[];\n path: string[];\n}\n\nexport interface MapSsmlTextNodesOptions {\n /** Element names whose text should not be passed to the transform. */\n skipTags?: readonly string[];\n /** Decides whether an individual text node should be passed to the transform. */\n filter?: (context: SsmlTextNodeContext) => boolean;\n}\n\ninterface TextNodeRecord {\n context: SsmlTextNodeContext;\n decodedText: string;\n end: number;\n sourceEnd: number;\n sourceStart: number;\n start: number;\n}\n\ninterface OpenElement {\n attributes: Record<string, string>;\n name: string;\n}\n\nfunction decodeXmlText(value: string): string {\n return value.replace(/&(?:amp|apos|gt|lt|quot);|&#(?:x[\\da-f]+|\\d+);/gi, (entity) => {\n if (entity === \"&amp;\") return \"&\";\n if (entity === \"&apos;\") return \"'\";\n if (entity === \"&gt;\") return \">\";\n if (entity === \"&lt;\") return \"<\";\n if (entity === \"&quot;\") return '\"';\n const hexadecimal = entity.toLowerCase().startsWith(\"&#x\");\n const digits = entity.slice(hexadecimal ? 3 : 2, -1);\n return String.fromCodePoint(Number.parseInt(digits, hexadecimal ? 16 : 10));\n });\n}\n\nfunction encodeXmlText(value: string): string {\n return value.replace(/&/g, \"&amp;\").replace(/</g, \"&lt;\").replace(/>/g, \"&gt;\");\n}\n\nfunction decodeXmlAttribute(value: string): string {\n return decodeXmlText(value);\n}\n\nfunction findTagEnd(source: string, start: number): number {\n let quote = \"\";\n for (let index = start; index < source.length; index += 1) {\n const character = source[index];\n if (quote) {\n if (character === quote) quote = \"\";\n } else if (character === '\"' || character === \"'\") {\n quote = character;\n } else if (character === \">\") {\n return index;\n }\n }\n return source.length - 1;\n}\n\nfunction readTagName(tag: string): string | undefined {\n const match = /^<\\s*([A-Za-z_][A-Za-z0-9_.:-]*)/.exec(tag);\n return match?.[1];\n}\n\nfunction readTagAttributes(tag: string, name: string): Record<string, string> {\n const attributes: Record<string, string> = {};\n const nameStart = tag.indexOf(name);\n const attributeSource = tag.slice(nameStart + name.length, tag.length - 1).replace(/\\/\\s*$/, \"\");\n const attributePattern = /([A-Za-z_][A-Za-z0-9_.:-]*)\\s*=\\s*([\"'])([\\s\\S]*?)\\2/g;\n for (const match of attributeSource.matchAll(attributePattern)) {\n attributes[match[1].toLowerCase()] = decodeXmlAttribute(match[3]);\n }\n return attributes;\n}\n\nfunction collectTextNodes(source: string): TextNodeRecord[] {\n const nodes: TextNodeRecord[] = [];\n const elements: OpenElement[] = [];\n let index = 0;\n\n const addText = (start: number, end: number, rawText: string, sourceStart = start, sourceEnd = end): void => {\n if (!rawText) return;\n const path = elements.map((element) => element.name);\n const parent = elements[elements.length - 1];\n nodes.push({\n context: {\n ancestorTags: path.slice(0, -1),\n parentAttributes: { ...(parent?.attributes ?? {}) },\n parentTag: parent?.name ?? \"\",\n path,\n },\n decodedText: decodeXmlText(rawText),\n end,\n sourceEnd,\n sourceStart,\n start,\n });\n };\n\n while (index < source.length) {\n if (source[index] !== \"<\") {\n const nextTag = source.indexOf(\"<\", index);\n const end = nextTag === -1 ? source.length : nextTag;\n addText(index, end, source.slice(index, end));\n index = end;\n continue;\n }\n\n if (source.startsWith(\"<!--\", index)) {\n const end = source.indexOf(\"-->\", index + 4);\n index = end === -1 ? source.length : end + 3;\n continue;\n }\n if (source.startsWith(\"<![CDATA[\", index)) {\n const contentStart = index + 9;\n const end = source.indexOf(\"]]>\", contentStart);\n const contentEnd = end === -1 ? source.length : end;\n addText(\n contentStart,\n contentEnd,\n source.slice(contentStart, contentEnd),\n index,\n end === -1 ? source.length : end + 3,\n );\n index = end === -1 ? source.length : end + 3;\n continue;\n }\n if (source.startsWith(\"<?\", index)) {\n const end = source.indexOf(\"?>\", index + 2);\n index = end === -1 ? source.length : end + 2;\n continue;\n }\n if (source.startsWith(\"</\", index)) {\n const end = findTagEnd(source, index + 2);\n elements.pop();\n index = end + 1;\n continue;\n }\n\n const end = findTagEnd(source, index + 1);\n const tag = source.slice(index, end + 1);\n const name = readTagName(tag);\n if (name && !/\\/\\s*>$/.test(tag)) elements.push({ attributes: readTagAttributes(tag, name), name });\n index = end + 1;\n }\n\n return nodes;\n}\n\nexport function extractSsmlText(ssml: string): string[] {\n parseSsml(ssml);\n return collectTextNodes(ssml).map((node) => node.decodedText);\n}\n\nexport async function mapSsmlTextNodes(\n ssml: string,\n transform: (text: string, context: SsmlTextNodeContext) => string | Promise<string>,\n options: MapSsmlTextNodesOptions = {},\n): Promise<string> {\n parseSsml(ssml);\n const nodes = collectTextNodes(ssml);\n const skipTags = new Set((options.skipTags ?? [\"phoneme\", \"say-as\", \"sub\"]).map((tag) => tag.toLowerCase()));\n const replacements = await Promise.all(\n nodes.map(async (node) => {\n const context = {\n ancestorTags: [...node.context.ancestorTags],\n parentAttributes: { ...node.context.parentAttributes },\n parentTag: node.context.parentTag,\n path: [...node.context.path],\n };\n const shouldTransform = !skipTags.has(context.parentTag.toLowerCase()) && (options.filter?.(context) ?? true);\n if (!shouldTransform) return ssml.slice(node.sourceStart, node.sourceEnd);\n const transformed = await transform(node.decodedText, context);\n if (typeof transformed !== \"string\") {\n throw new TypeError(\"SSML text node transform must return a string\");\n }\n return transformed === node.decodedText\n ? ssml.slice(node.sourceStart, node.sourceEnd)\n : encodeXmlText(transformed);\n }),\n );\n\n let result = \"\";\n let cursor = 0;\n nodes.forEach((node, nodeIndex) => {\n result += ssml.slice(cursor, node.sourceStart) + replacements[nodeIndex];\n cursor = node.sourceEnd;\n });\n return result + ssml.slice(cursor);\n}\n","import { parseSsml } from \"./parser.ts\";\n\nexport type SsmlDiagnosticSeverity = \"error\" | \"warning\";\n\nexport interface SsmlDiagnostic {\n line: number;\n column: number;\n message: string;\n severity: SsmlDiagnosticSeverity;\n}\n\nexport interface AzureValidationOptions {\n allowedAudioOrigins?: readonly string[];\n allowExternalAudio?: boolean;\n allowHttpAudio?: boolean;\n customVoiceStyleMap?: Record<string, readonly string[]>;\n maxLength?: number;\n unknownVoicePolicy?: \"error\" | \"warn\" | \"ignore\";\n validateNestedVoices?: boolean;\n}\n\n/** @deprecated Use AzureValidationOptions instead. */\nexport type AzureSsmlValidationOptions = AzureValidationOptions;\n\ninterface ElementToken {\n attributes: Map<string, string>;\n end: number;\n name: string;\n parentVoiceName?: string;\n start: number;\n selfClosing: boolean;\n}\n\nconst EXPRESS_AS_STYLES: Readonly<Record<string, readonly string[]>> = {\n \"en-us-jennyneural\": [\n \"assistant\",\n \"chat\",\n \"customerservice\",\n \"newscast\",\n \"cheerful\",\n \"empathetic\",\n \"excited\",\n \"friendly\",\n \"hopeful\",\n \"sad\",\n \"shouting\",\n \"terrified\",\n \"unfriendly\",\n \"whispering\",\n ],\n \"en-us-guyneural\": [\n \"angry\",\n \"cheerful\",\n \"excited\",\n \"friendly\",\n \"hopeful\",\n \"newscast\",\n \"sad\",\n \"shouting\",\n \"terrified\",\n \"unfriendly\",\n \"whispering\",\n ],\n \"en-us-jennymultilingualneural\": [\n \"cheerful\",\n \"empathetic\",\n \"excited\",\n \"friendly\",\n \"hopeful\",\n \"sad\",\n \"shouting\",\n \"terrified\",\n \"unfriendly\",\n \"whispering\",\n ],\n \"en-us-andrewneural\": [\"empathetic\", \"relieved\"],\n \"ja-jp-mayuneural\": [\"calm\", \"cheerful\", \"sad\"],\n \"ja-jp-nanamineural\": [\"chat\", \"customerservice\", \"cheerful\", \"whispering\", \"sad\"],\n \"ja-jp-keitaneural\": [\"chat\"],\n \"ko-kr-sunhineural\": [\"cheerful\", \"sad\"],\n \"zh-cn-yunxineural\": [\n \"narration-relaxed\",\n \"embarrassed\",\n \"fearful\",\n \"sad\",\n \"disgruntled\",\n \"serious\",\n \"angry\",\n \"depressed\",\n \"chat\",\n \"cheerful\",\n \"assistant\",\n ],\n \"zh-cn-xiaoxiaoneural\": [\n \"assistant\",\n \"chat\",\n \"customerservice\",\n \"newscast\",\n \"cheerful\",\n \"empathetic\",\n \"excited\",\n \"friendly\",\n \"hopeful\",\n \"sad\",\n \"terrified\",\n \"whispering\",\n \"poetry-reading\",\n \"sports_commentary\",\n \"sports_commentary_excited\",\n \"story\",\n ],\n \"fr-fr-deniseneural\": [\"cheerful\", \"sad\"],\n \"fr-fr-henrineural\": [\"cheerful\", \"sad\"],\n \"pt-br-franciscaneural\": [\"calm\"],\n \"it-it-elsaneural\": [\"cheerful\", \"sad\"],\n \"de-de-katjaneural\": [\"cheerful\", \"sad\"],\n \"de-de-conradneural\": [\"cheerful\", \"sad\"],\n \"ru-ru-svetlananeural\": [\"cheerful\", \"sad\", \"angry\", \"disgruntled\", \"embarrassed\", \"fearful\"],\n};\n\nconst ALLOWED_BREAK_STRENGTHS = new Set([\"none\", \"x-weak\", \"weak\", \"medium\", \"strong\", \"x-strong\"]);\nconst ALLOWED_SAY_AS = new Set([\n \"characters\",\n \"spell-out\",\n \"cardinal\",\n \"ordinal\",\n \"number\",\n \"date\",\n \"time\",\n \"telephone\",\n \"fraction\",\n \"address\",\n \"name\",\n \"currency\",\n]);\nconst ALLOWED_ROLES = new Set([\n \"Girl\",\n \"Boy\",\n \"YoungAdultFemale\",\n \"YoungAdultMale\",\n \"OlderAdultFemale\",\n \"OlderAdultMale\",\n \"SeniorFemale\",\n \"SeniorMale\",\n]);\nconst ALLOWED_EMPHASIS_LEVELS = new Set([\"strong\", \"moderate\", \"reduced\", \"none\"]);\nconst ALLOWED_SILENCE_TYPES = new Set([\n \"Leading\",\n \"Tailing\",\n \"Sentenceboundary\",\n \"Comma\",\n \"Semicolon\",\n \"Enumerationcomma\",\n]);\nconst ALLOWED_VISEME_TYPES = new Set([\"redlips_front\", \"FacialExpression\"]);\n\nfunction decodeAttribute(value: string): string {\n return value.replace(\n /&(?:amp|apos|gt|lt|quot);/gi,\n (entity) =>\n ({ \"&amp;\": \"&\", \"&apos;\": \"'\", \"&gt;\": \">\", \"&lt;\": \"<\", \"&quot;\": '\"' })[entity.toLowerCase()] ?? entity,\n );\n}\n\nfunction findTagEnd(source: string, start: number): number {\n let quote = \"\";\n for (let index = start; index < source.length; index += 1) {\n const character = source[index];\n if (quote) {\n if (character === quote) quote = \"\";\n } else if (character === '\"' || character === \"'\") quote = character;\n else if (character === \">\") return index;\n }\n return source.length - 1;\n}\n\nfunction tokenizeElements(source: string): ElementToken[] {\n const tokens: ElementToken[] = [];\n const openElements: Array<{ name: string; voiceName?: string }> = [];\n let index = 0;\n while (index < source.length) {\n const start = source.indexOf(\"<\", index);\n if (start === -1) break;\n if (source.startsWith(\"<!--\", start)) {\n const end = source.indexOf(\"-->\", start + 4);\n index = end === -1 ? source.length : end + 3;\n continue;\n }\n if (source.startsWith(\"<![CDATA[\", start)) {\n const end = source.indexOf(\"]]>\", start + 9);\n index = end === -1 ? source.length : end + 3;\n continue;\n }\n if (source.startsWith(\"<?\", start)) {\n const end = source.indexOf(\"?>\", start + 2);\n index = end === -1 ? source.length : end + 2;\n continue;\n }\n const end = findTagEnd(source, start + 1);\n const raw = source.slice(start, end + 1);\n if (raw.startsWith(\"</\")) {\n openElements.pop();\n index = end + 1;\n continue;\n }\n const nameMatch = /^<\\s*([A-Za-z_][A-Za-z0-9_.:-]*)/.exec(raw);\n if (!nameMatch?.[1]) {\n index = end + 1;\n continue;\n }\n const attributes = new Map<string, string>();\n const attributeSource = raw.slice(nameMatch[0].length, raw.length - 1).replace(/\\/\\s*$/, \"\");\n const attributePattern = /([A-Za-z_][A-Za-z0-9_.:-]*)\\s*=\\s*([\"'])([\\s\\S]*?)\\2/g;\n for (const match of attributeSource.matchAll(attributePattern)) {\n attributes.set(match[1].toLowerCase(), decodeAttribute(match[3]));\n }\n const selfClosing = /\\/\\s*>$/.test(raw);\n const parentVoiceName = [...openElements].reverse().find((element) => element.voiceName)?.voiceName;\n tokens.push({ attributes, end, name: nameMatch[1], parentVoiceName, selfClosing, start });\n if (!selfClosing) {\n openElements.push({\n name: nameMatch[1],\n voiceName: nameMatch[1].toLowerCase() === \"voice\" ? attributes.get(\"name\") : parentVoiceName,\n });\n }\n index = end + 1;\n }\n return tokens;\n}\n\nfunction location(source: string, offset: number): { column: number; line: number } {\n const before = source.slice(0, Math.max(0, offset));\n const line = before.split(\"\\n\").length;\n return { line, column: before.length - (before.lastIndexOf(\"\\n\") + 1) + 1 };\n}\n\nfunction addDiagnostic(\n diagnostics: SsmlDiagnostic[],\n source: string,\n offset: number,\n message: string,\n severity: SsmlDiagnosticSeverity = \"error\",\n): void {\n diagnostics.push({ ...location(source, offset), message, severity });\n}\n\nfunction attr(token: ElementToken, name: string): string | undefined {\n return token.attributes.get(name.toLowerCase());\n}\n\nfunction normalizeVoiceStyleMap(\n customVoiceStyleMap: Record<string, readonly string[]> | undefined,\n): ReadonlyMap<string, readonly string[]> {\n const map = new Map<string, readonly string[]>(\n Object.entries(EXPRESS_AS_STYLES).map(([voiceName, styles]) => [voiceName.toLowerCase(), styles]),\n );\n for (const [voiceName, styles] of Object.entries(customVoiceStyleMap ?? {})) {\n map.set(\n voiceName.toLowerCase(),\n styles.map((style) => style.toLowerCase()),\n );\n }\n return map;\n}\n\nfunction diagnosticSeverity(policy: AzureValidationOptions[\"unknownVoicePolicy\"]): SsmlDiagnosticSeverity | undefined {\n if (policy === \"ignore\") return undefined;\n return policy === \"error\" ? \"error\" : \"warning\";\n}\n\nfunction voiceLocalePrefix(voiceName: string): { language: string; region: string } | undefined {\n const match = /^(?<language>[A-Za-z]{2,3})-(?<region>[A-Za-z]{2}|\\d{3})(?:-|$)/.exec(voiceName.trim());\n if (!match?.groups) return undefined;\n return {\n language: match.groups.language.toLowerCase(),\n region: match.groups.region.toLowerCase(),\n };\n}\n\nfunction languageLocalePrefix(language: string): { language: string; region?: string } | undefined {\n const match = /^(?<language>[A-Za-z]{2,3})(?:-(?<region>[A-Za-z]{2}|\\d{3}))?(?:-|$)/.exec(language.trim());\n if (!match?.groups) return undefined;\n return {\n language: match.groups.language.toLowerCase(),\n region: match.groups.region?.toLowerCase(),\n };\n}\n\nfunction voiceMatchesLanguage(voiceName: string, language: string): boolean | undefined {\n const voiceLocale = voiceLocalePrefix(voiceName);\n const languageLocale = languageLocalePrefix(language);\n if (!voiceLocale || !languageLocale) return undefined;\n return (\n voiceLocale.language === languageLocale.language &&\n (languageLocale.region === undefined || voiceLocale.region === languageLocale.region)\n );\n}\n\nfunction validateElement(\n token: ElementToken,\n source: string,\n diagnostics: SsmlDiagnostic[],\n voiceName: string | undefined,\n options: AzureValidationOptions,\n voiceStyleMap: ReadonlyMap<string, readonly string[]>,\n): void {\n const name = token.name.toLowerCase();\n if (name === \"voice\" && !attr(token, \"name\")?.trim())\n addDiagnostic(diagnostics, source, token.start, '<voice> requires a non-empty \"name\" attribute.');\n if (name === \"break\") {\n const time = attr(token, \"time\");\n const strength = attr(token, \"strength\");\n if (!time && !strength)\n addDiagnostic(diagnostics, source, token.start, '<break> requires either \"time\" or \"strength\".');\n if (time && strength)\n addDiagnostic(diagnostics, source, token.start, '<break> must not specify both \"time\" and \"strength\".');\n if (time && !/^\\d+(?:\\.\\d+)?(?:ms|s)$/.test(time.trim()))\n addDiagnostic(diagnostics, source, token.start, '<break time> must use a numeric value followed by \"ms\" or \"s\".');\n if (strength && !ALLOWED_BREAK_STRENGTHS.has(strength))\n addDiagnostic(diagnostics, source, token.start, `Unsupported <break strength> value \"${strength}\".`);\n }\n if (name === \"prosody\") {\n const rate = attr(token, \"rate\");\n const pitch = attr(token, \"pitch\");\n const volume = attr(token, \"volume\");\n if (rate && !/^(x-slow|slow|medium|fast|x-fast|[+-]?\\d+(?:\\.\\d+)?%)$/.test(rate.trim()))\n addDiagnostic(diagnostics, source, token.start, `Unsupported <prosody rate> value \"${rate}\".`);\n if (pitch && !/^(x-low|low|medium|high|x-high|[+-]?\\d+(?:\\.\\d+)?(?:st|Hz|%)?)$/.test(pitch.trim()))\n addDiagnostic(diagnostics, source, token.start, `Unsupported <prosody pitch> value \"${pitch}\".`);\n if (volume && !/^(silent|x-soft|soft|medium|loud|x-loud|[+-]?\\d+(?:\\.\\d+)?(?:dB|%)?)$/.test(volume.trim()))\n addDiagnostic(diagnostics, source, token.start, `Unsupported <prosody volume> value \"${volume}\".`);\n }\n if (name === \"mstts:express-as\" || name === \"express-as\" || name === \"expressas\") {\n const style = attr(token, \"style\");\n if (!style?.trim())\n addDiagnostic(diagnostics, source, token.start, '<mstts:express-as> requires a non-empty \"style\" attribute.');\n const degree = attr(token, \"styledegree\") ?? attr(token, \"style-degree\");\n if (degree && (!/^\\d+(?:\\.\\d+)?$/.test(degree) || Number(degree) < 0.01 || Number(degree) > 2))\n addDiagnostic(\n diagnostics,\n source,\n token.start,\n \"<mstts:express-as styledegree> must be a number between 0.01 and 2.\",\n );\n const role = attr(token, \"role\");\n if (role && !ALLOWED_ROLES.has(role))\n addDiagnostic(diagnostics, source, token.start, `Unsupported <mstts:express-as role> value \"${role}\".`);\n const supportedStyles = voiceName ? voiceStyleMap.get(voiceName.toLowerCase()) : undefined;\n const severity = diagnosticSeverity(options.unknownVoicePolicy ?? \"warn\");\n if (style && supportedStyles && !supportedStyles.includes(style.toLowerCase()) && severity)\n addDiagnostic(\n diagnostics,\n source,\n token.start,\n `Unknown style \"${style}\" is not supported by voice \"${voiceName}\" according to the configured voice style map.`,\n severity,\n );\n if (style && voiceName && !supportedStyles && severity)\n addDiagnostic(\n diagnostics,\n source,\n token.start,\n `Unknown style \"${style}\" cannot be verified because voice \"${voiceName}\" is not registered in the voice style map.`,\n severity,\n );\n }\n if (name === \"say-as\" || name === \"sayas\") {\n const interpretAs = attr(token, \"interpret-as\");\n if (!interpretAs || !ALLOWED_SAY_AS.has(interpretAs))\n addDiagnostic(diagnostics, source, token.start, `<say-as> requires a supported \"interpret-as\" value.`);\n }\n if (name === \"phoneme\" && (!attr(token, \"alphabet\") || !attr(token, \"ph\")))\n addDiagnostic(diagnostics, source, token.start, '<phoneme> requires both \"alphabet\" and \"ph\" attributes.');\n if (name === \"emphasis\" && attr(token, \"level\") && !ALLOWED_EMPHASIS_LEVELS.has(attr(token, \"level\") ?? \"\"))\n addDiagnostic(diagnostics, source, token.start, `Unsupported <emphasis level> value \"${attr(token, \"level\")}\".`);\n if (name === \"sub\" && !attr(token, \"alias\")?.trim())\n addDiagnostic(diagnostics, source, token.start, '<sub> requires a non-empty \"alias\" attribute.');\n if (name === \"lang\" && !attr(token, \"xml:lang\")?.trim() && !attr(token, \"lang\")?.trim())\n addDiagnostic(diagnostics, source, token.start, '<lang> requires an \"xml:lang\" attribute.');\n if (name === \"mark\" && !attr(token, \"name\")?.trim())\n addDiagnostic(diagnostics, source, token.start, '<mark> requires a non-empty \"name\" attribute.');\n if (name === \"bookmark\" && !attr(token, \"mark\")?.trim())\n addDiagnostic(diagnostics, source, token.start, '<bookmark> requires a non-empty \"mark\" attribute.');\n if (name === \"lexicon\") {\n const uri = attr(token, \"uri\");\n if (!uri) addDiagnostic(diagnostics, source, token.start, '<lexicon> requires a \"uri\" attribute.');\n else {\n try {\n const parsed = new URL(uri);\n if (parsed.protocol !== \"https:\")\n addDiagnostic(diagnostics, source, token.start, \"<lexicon uri> must use HTTPS.\");\n } catch {\n addDiagnostic(diagnostics, source, token.start, \"<lexicon uri> must be an absolute HTTPS URL.\");\n }\n }\n }\n if (name === \"mstts:silence\") {\n const type = attr(token, \"type\");\n const value = attr(token, \"value\");\n if (!type || !ALLOWED_SILENCE_TYPES.has(type))\n addDiagnostic(diagnostics, source, token.start, '<mstts:silence> requires a supported \"type\" attribute.');\n if (!value || !/^\\d+(?:\\.\\d+)?(?:ms|s)$/.test(value.trim()))\n addDiagnostic(diagnostics, source, token.start, '<mstts:silence> requires a time-valued \"value\" attribute.');\n }\n if (name === \"mstts:viseme\") {\n const type = attr(token, \"type\");\n if (!type || !ALLOWED_VISEME_TYPES.has(type))\n addDiagnostic(diagnostics, source, token.start, '<mstts:viseme> requires a supported \"type\" attribute.');\n }\n if (name === \"audio\") {\n const src = attr(token, \"src\");\n if (!src) addDiagnostic(diagnostics, source, token.start, '<audio> requires a \"src\" attribute.');\n else {\n let parsed: URL;\n try {\n parsed = new URL(src);\n } catch {\n addDiagnostic(diagnostics, source, token.start, \"<audio src> must be an absolute HTTP(S) URL.\");\n return;\n }\n if (parsed.protocol !== \"https:\" && !(options.allowHttpAudio && parsed.protocol === \"http:\"))\n addDiagnostic(diagnostics, source, token.start, \"<audio src> must use HTTPS.\");\n if (options.allowedAudioOrigins && !options.allowedAudioOrigins.includes(parsed.origin))\n addDiagnostic(diagnostics, source, token.start, `<audio src> origin \"${parsed.origin}\" is not allowed.`);\n else if (!options.allowExternalAudio)\n addDiagnostic(\n diagnostics,\n source,\n token.start,\n `<audio src> external origin \"${parsed.origin}\" is blocked by default; set allowExternalAudio to true or provide allowedAudioOrigins.`,\n \"error\",\n );\n }\n }\n}\n\nexport function validateAzureSsml(ssml: string, options: AzureValidationOptions = {}): SsmlDiagnostic[] {\n const diagnostics: SsmlDiagnostic[] = [];\n if (typeof ssml !== \"string\") {\n return [{ line: 1, column: 1, message: \"SSML input must be a string\", severity: \"error\" }];\n }\n const maxLength = options.maxLength ?? 10_000;\n if (ssml.length > maxLength)\n addDiagnostic(diagnostics, ssml, maxLength, `SSML exceeds the maximum length of ${maxLength} characters.`);\n try {\n parseSsml(ssml);\n } catch (error) {\n const message = error instanceof Error ? error.message.replace(/ at position \\d+$/, \"\") : String(error);\n const match = / at position (\\d+)$/.exec(error instanceof Error ? error.message : \"\");\n addDiagnostic(diagnostics, ssml, match ? Number(match[1]) : 0, message);\n return diagnostics;\n }\n const tokens = tokenizeElements(ssml);\n const speak = tokens.find((token) => token.name.toLowerCase() === \"speak\");\n const voices = tokens.filter((token) => token.name.toLowerCase() === \"voice\");\n if (!speak || voices.length === 0)\n addDiagnostic(\n diagnostics,\n ssml,\n speak?.start ?? 0,\n \"Azure SSML requires at least one <voice> element under <speak>.\",\n );\n const voiceName = voices[0] ? attr(voices[0], \"name\") : undefined;\n const voiceStyleMap = normalizeVoiceStyleMap(options.customVoiceStyleMap);\n const policySeverity = diagnosticSeverity(options.unknownVoicePolicy ?? \"warn\");\n const voicesToValidate = options.validateNestedVoices === false ? voices.slice(0, 1) : voices;\n for (const token of voicesToValidate) {\n const name = attr(token, \"name\")?.trim();\n const language = attr(token, \"xml:lang\")?.trim() || (speak ? attr(speak, \"xml:lang\")?.trim() : undefined);\n if (name && !voiceStyleMap.has(name.toLowerCase()) && policySeverity)\n addDiagnostic(\n diagnostics,\n ssml,\n token.start,\n `Unknown voice \"${name}\" is not registered in the voice style map.`,\n policySeverity,\n );\n if (name && language && voiceMatchesLanguage(name, language) === false)\n addDiagnostic(\n diagnostics,\n ssml,\n token.start,\n `Voice \"${name}\" does not match language \"${language}\"; the voice name prefix indicates a different language or region.`,\n \"warning\",\n );\n }\n for (const token of tokens) {\n const tokenVoiceName = options.validateNestedVoices === false ? voiceName : token.parentVoiceName;\n validateElement(token, ssml, diagnostics, tokenVoiceName, options, voiceStyle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AAQ,KAAK,OAAO,UAAU,GAAG,KAAK,IAAI;AAC/F,QAAI,QAAQ,CAAC,cAAc,IAAI,KAAK,YAAY,CAAC,KAAK;AACpD;AAAA,QACE;AAAA,QACA;AAAA,QACA,MAAM;AAAA,QACN,kBAAkB,IAAI;AAAA,QACtB;AAAA,MACF;AACF,QAAI,QAAQ,YAAY,qBAAqB,MAAM,QAAQ,MAAM;AAC/D;AAAA,QACE;AAAA,QACA;AAAA,QACA,MAAM;AAAA,QACN,UAAU,IAAI,8BAA8B,QAAQ;AAAA,QACpD;AAAA,MACF;AAAA,EACJ;AACA,aAAW,SAAS,QAAQ;AAC1B,UAAM,iBAAiB,QAAQ,yBAAyB,QAAQ,YAAY,MAAM;AAClF,oBAAgB,OAAO,MAAM,aAAa,gBAAgB,SAAS,aAAa;AAAA,EAClF;AACA,SAAO;AACT;","names":["escapeAttribute","end","findTagEnd","end"]}
package/dist/core.d.mts CHANGED
@@ -158,10 +158,18 @@ declare function validateSsml(xmlString: string): SsmlValidationError | null;
158
158
 
159
159
  interface SsmlTextNodeContext {
160
160
  parentTag: string;
161
+ parentAttributes: Record<string, string>;
162
+ ancestorTags: string[];
161
163
  path: string[];
162
164
  }
165
+ interface MapSsmlTextNodesOptions {
166
+ /** Element names whose text should not be passed to the transform. */
167
+ skipTags?: readonly string[];
168
+ /** Decides whether an individual text node should be passed to the transform. */
169
+ filter?: (context: SsmlTextNodeContext) => boolean;
170
+ }
163
171
  declare function extractSsmlText(ssml: string): string[];
164
- declare function mapSsmlTextNodes(ssml: string, transform: (text: string, context: SsmlTextNodeContext) => string | Promise<string>): Promise<string>;
172
+ declare function mapSsmlTextNodes(ssml: string, transform: (text: string, context: SsmlTextNodeContext) => string | Promise<string>, options?: MapSsmlTextNodesOptions): Promise<string>;
165
173
 
166
174
  type SsmlDiagnosticSeverity = "error" | "warning";
167
175
  interface SsmlDiagnostic {
@@ -170,11 +178,17 @@ interface SsmlDiagnostic {
170
178
  message: string;
171
179
  severity: SsmlDiagnosticSeverity;
172
180
  }
173
- interface AzureSsmlValidationOptions {
181
+ interface AzureValidationOptions {
174
182
  allowedAudioOrigins?: readonly string[];
183
+ allowExternalAudio?: boolean;
175
184
  allowHttpAudio?: boolean;
185
+ customVoiceStyleMap?: Record<string, readonly string[]>;
176
186
  maxLength?: number;
187
+ unknownVoicePolicy?: "error" | "warn" | "ignore";
188
+ validateNestedVoices?: boolean;
177
189
  }
178
- declare function validateAzureSsml(ssml: string, options?: AzureSsmlValidationOptions): SsmlDiagnostic[];
190
+ /** @deprecated Use AzureValidationOptions instead. */
191
+ type AzureSsmlValidationOptions = AzureValidationOptions;
192
+ declare function validateAzureSsml(ssml: string, options?: AzureValidationOptions): SsmlDiagnostic[];
179
193
 
180
- export { type AudioElement, type AzureSsmlValidationOptions, type BookmarkElement, type BreakElement, type BuildPartialSsmlOptions, type CustomElement, type EmphasisElement, type ExpressAsElement, type LangElement, type LexiconElement, type MarkElement, type MsttsSilenceElement, type MsttsVisemeElement, type NamedElement, type ParagraphElement, type PhonemeElement, type ProsodyElement, type SayAsElement, type SentenceElement, type SsmlAttributeValue, type SsmlAttributes, type SsmlBreakElement, type SsmlDiagnostic, type SsmlDiagnosticSeverity, type SsmlDocument, type SsmlElement, type SsmlElementBase, type SsmlExpressAsElement, type SsmlNode, type SsmlPartialContext, type SsmlPartialProsody, type SsmlPartialVoice, type SsmlPhonemeElement, type SsmlProsodyElement, type SsmlSayAsElement, type SsmlText, type SsmlTextNodeContext, type SsmlValidationError, type SsmlVoiceElement, type SubElement, type VoiceElement, type WordElement, buildPartialSsml, buildSsml, extractSsmlText, mapSsmlTextNodes, parseSsml, validateAzureSsml, validateSsml };
194
+ export { type AudioElement, type AzureSsmlValidationOptions, type AzureValidationOptions, type BookmarkElement, type BreakElement, type BuildPartialSsmlOptions, type CustomElement, type EmphasisElement, type ExpressAsElement, type LangElement, type LexiconElement, type MapSsmlTextNodesOptions, type MarkElement, type MsttsSilenceElement, type MsttsVisemeElement, type NamedElement, type ParagraphElement, type PhonemeElement, type ProsodyElement, type SayAsElement, type SentenceElement, type SsmlAttributeValue, type SsmlAttributes, type SsmlBreakElement, type SsmlDiagnostic, type SsmlDiagnosticSeverity, type SsmlDocument, type SsmlElement, type SsmlElementBase, type SsmlExpressAsElement, type SsmlNode, type SsmlPartialContext, type SsmlPartialProsody, type SsmlPartialVoice, type SsmlPhonemeElement, type SsmlProsodyElement, type SsmlSayAsElement, type SsmlText, type SsmlTextNodeContext, type SsmlValidationError, type SsmlVoiceElement, type SubElement, type VoiceElement, type WordElement, buildPartialSsml, buildSsml, extractSsmlText, mapSsmlTextNodes, parseSsml, validateAzureSsml, validateSsml };
package/dist/core.d.ts CHANGED
@@ -158,10 +158,18 @@ declare function validateSsml(xmlString: string): SsmlValidationError | null;
158
158
 
159
159
  interface SsmlTextNodeContext {
160
160
  parentTag: string;
161
+ parentAttributes: Record<string, string>;
162
+ ancestorTags: string[];
161
163
  path: string[];
162
164
  }
165
+ interface MapSsmlTextNodesOptions {
166
+ /** Element names whose text should not be passed to the transform. */
167
+ skipTags?: readonly string[];
168
+ /** Decides whether an individual text node should be passed to the transform. */
169
+ filter?: (context: SsmlTextNodeContext) => boolean;
170
+ }
163
171
  declare function extractSsmlText(ssml: string): string[];
164
- declare function mapSsmlTextNodes(ssml: string, transform: (text: string, context: SsmlTextNodeContext) => string | Promise<string>): Promise<string>;
172
+ declare function mapSsmlTextNodes(ssml: string, transform: (text: string, context: SsmlTextNodeContext) => string | Promise<string>, options?: MapSsmlTextNodesOptions): Promise<string>;
165
173
 
166
174
  type SsmlDiagnosticSeverity = "error" | "warning";
167
175
  interface SsmlDiagnostic {
@@ -170,11 +178,17 @@ interface SsmlDiagnostic {
170
178
  message: string;
171
179
  severity: SsmlDiagnosticSeverity;
172
180
  }
173
- interface AzureSsmlValidationOptions {
181
+ interface AzureValidationOptions {
174
182
  allowedAudioOrigins?: readonly string[];
183
+ allowExternalAudio?: boolean;
175
184
  allowHttpAudio?: boolean;
185
+ customVoiceStyleMap?: Record<string, readonly string[]>;
176
186
  maxLength?: number;
187
+ unknownVoicePolicy?: "error" | "warn" | "ignore";
188
+ validateNestedVoices?: boolean;
177
189
  }
178
- declare function validateAzureSsml(ssml: string, options?: AzureSsmlValidationOptions): SsmlDiagnostic[];
190
+ /** @deprecated Use AzureValidationOptions instead. */
191
+ type AzureSsmlValidationOptions = AzureValidationOptions;
192
+ declare function validateAzureSsml(ssml: string, options?: AzureValidationOptions): SsmlDiagnostic[];
179
193
 
180
- export { type AudioElement, type AzureSsmlValidationOptions, type BookmarkElement, type BreakElement, type BuildPartialSsmlOptions, type CustomElement, type EmphasisElement, type ExpressAsElement, type LangElement, type LexiconElement, type MarkElement, type MsttsSilenceElement, type MsttsVisemeElement, type NamedElement, type ParagraphElement, type PhonemeElement, type ProsodyElement, type SayAsElement, type SentenceElement, type SsmlAttributeValue, type SsmlAttributes, type SsmlBreakElement, type SsmlDiagnostic, type SsmlDiagnosticSeverity, type SsmlDocument, type SsmlElement, type SsmlElementBase, type SsmlExpressAsElement, type SsmlNode, type SsmlPartialContext, type SsmlPartialProsody, type SsmlPartialVoice, type SsmlPhonemeElement, type SsmlProsodyElement, type SsmlSayAsElement, type SsmlText, type SsmlTextNodeContext, type SsmlValidationError, type SsmlVoiceElement, type SubElement, type VoiceElement, type WordElement, buildPartialSsml, buildSsml, extractSsmlText, mapSsmlTextNodes, parseSsml, validateAzureSsml, validateSsml };
194
+ export { type AudioElement, type AzureSsmlValidationOptions, type AzureValidationOptions, type BookmarkElement, type BreakElement, type BuildPartialSsmlOptions, type CustomElement, type EmphasisElement, type ExpressAsElement, type LangElement, type LexiconElement, type MapSsmlTextNodesOptions, type MarkElement, type MsttsSilenceElement, type MsttsVisemeElement, type NamedElement, type ParagraphElement, type PhonemeElement, type ProsodyElement, type SayAsElement, type SentenceElement, type SsmlAttributeValue, type SsmlAttributes, type SsmlBreakElement, type SsmlDiagnostic, type SsmlDiagnosticSeverity, type SsmlDocument, type SsmlElement, type SsmlElementBase, type SsmlExpressAsElement, type SsmlNode, type SsmlPartialContext, type SsmlPartialProsody, type SsmlPartialVoice, type SsmlPhonemeElement, type SsmlProsodyElement, type SsmlSayAsElement, type SsmlText, type SsmlTextNodeContext, type SsmlValidationError, type SsmlVoiceElement, type SubElement, type VoiceElement, type WordElement, buildPartialSsml, buildSsml, extractSsmlText, mapSsmlTextNodes, parseSsml, validateAzureSsml, validateSsml };