ssml-builder-js 2.2.0 → 2.4.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.
- package/README.md +16 -2
- package/dist/{chunk-2XJER2BG.mjs → chunk-I3BR2WCQ.mjs} +161 -134
- package/dist/chunk-I3BR2WCQ.mjs.map +1 -0
- package/dist/{chunk-I3GP7OJU.mjs → chunk-RUIEMCWP.mjs} +462 -3
- package/dist/chunk-RUIEMCWP.mjs.map +1 -0
- package/dist/core.d.mts +22 -1
- package/dist/core.d.ts +22 -1
- package/dist/core.js +463 -1
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +7 -1
- package/dist/elements.js +7 -1
- package/dist/elements.js.map +1 -1
- package/dist/elements.mjs +1 -1
- package/dist/index.d.mts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +467 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -4
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +25 -1
- package/dist/react.d.ts +25 -1
- package/dist/react.js +365 -15
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +333 -10
- package/dist/react.mjs.map +1 -1
- package/package.json +10 -1
- package/dist/chunk-2XJER2BG.mjs.map +0 -1
- package/dist/chunk-I3GP7OJU.mjs.map +0 -1
package/dist/core.js
CHANGED
|
@@ -29,7 +29,10 @@ var core_exports = {};
|
|
|
29
29
|
__export(core_exports, {
|
|
30
30
|
buildPartialSsml: () => buildPartialSsml,
|
|
31
31
|
buildSsml: () => buildSsml,
|
|
32
|
+
extractSsmlText: () => extractSsmlText,
|
|
33
|
+
mapSsmlTextNodes: () => mapSsmlTextNodes,
|
|
32
34
|
parseSsml: () => parseSsml,
|
|
35
|
+
validateAzureSsml: () => validateAzureSsml,
|
|
33
36
|
validateSsml: () => validateSsml
|
|
34
37
|
});
|
|
35
38
|
module.exports = __toCommonJS(core_exports);
|
|
@@ -86,6 +89,7 @@ var SSML_ATTRS = {
|
|
|
86
89
|
STYLE: "style",
|
|
87
90
|
STYLE_DEGREE: "styledegree",
|
|
88
91
|
STYLE_DEGREE_CAMEL: "styleDegree",
|
|
92
|
+
STYLE_DEGREE_HYPHEN: "style-degree",
|
|
89
93
|
ROLE: "role",
|
|
90
94
|
INTERPRET_AS: "interpret-as",
|
|
91
95
|
FORMAT: "format",
|
|
@@ -633,7 +637,12 @@ function convertElement(node) {
|
|
|
633
637
|
case SSML_TAGS.MSTTS_EXPRESS_AS: {
|
|
634
638
|
const element = { type: node.name };
|
|
635
639
|
const style = readAttribute(attributes, SSML_ATTRS.STYLE);
|
|
636
|
-
const styleDegree = readAttribute(
|
|
640
|
+
const styleDegree = readAttribute(
|
|
641
|
+
attributes,
|
|
642
|
+
SSML_ATTRS.STYLE_DEGREE,
|
|
643
|
+
SSML_ATTRS.STYLE_DEGREE_CAMEL,
|
|
644
|
+
SSML_ATTRS.STYLE_DEGREE_HYPHEN
|
|
645
|
+
);
|
|
637
646
|
const role = readAttribute(attributes, SSML_ATTRS.ROLE);
|
|
638
647
|
if (style !== void 0) element.style = style;
|
|
639
648
|
if (styleDegree !== void 0) element.styleDegree = styleDegree;
|
|
@@ -871,11 +880,464 @@ function validateSsml(xmlString) {
|
|
|
871
880
|
};
|
|
872
881
|
}
|
|
873
882
|
}
|
|
883
|
+
|
|
884
|
+
// packages/ssml-core/src/textNodes.ts
|
|
885
|
+
function decodeXmlText(value) {
|
|
886
|
+
return value.replace(/&(?:amp|apos|gt|lt|quot);|&#(?:x[\da-f]+|\d+);/gi, (entity) => {
|
|
887
|
+
if (entity === "&") return "&";
|
|
888
|
+
if (entity === "'") return "'";
|
|
889
|
+
if (entity === ">") return ">";
|
|
890
|
+
if (entity === "<") return "<";
|
|
891
|
+
if (entity === """) return '"';
|
|
892
|
+
const hexadecimal = entity.toLowerCase().startsWith("&#x");
|
|
893
|
+
const digits = entity.slice(hexadecimal ? 3 : 2, -1);
|
|
894
|
+
return String.fromCodePoint(Number.parseInt(digits, hexadecimal ? 16 : 10));
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
function encodeXmlText(value) {
|
|
898
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
899
|
+
}
|
|
900
|
+
function findTagEnd(source, start) {
|
|
901
|
+
let quote = "";
|
|
902
|
+
for (let index = start; index < source.length; index += 1) {
|
|
903
|
+
const character = source[index];
|
|
904
|
+
if (quote) {
|
|
905
|
+
if (character === quote) quote = "";
|
|
906
|
+
} else if (character === '"' || character === "'") {
|
|
907
|
+
quote = character;
|
|
908
|
+
} else if (character === ">") {
|
|
909
|
+
return index;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
return source.length - 1;
|
|
913
|
+
}
|
|
914
|
+
function readTagName(tag) {
|
|
915
|
+
const match = /^<\s*([A-Za-z_][A-Za-z0-9_.:-]*)/.exec(tag);
|
|
916
|
+
return match?.[1];
|
|
917
|
+
}
|
|
918
|
+
function collectTextNodes(source) {
|
|
919
|
+
const nodes = [];
|
|
920
|
+
const path = [];
|
|
921
|
+
let index = 0;
|
|
922
|
+
const addText = (start, end, rawText, sourceStart = start, sourceEnd = end) => {
|
|
923
|
+
if (!rawText) return;
|
|
924
|
+
nodes.push({
|
|
925
|
+
context: { parentTag: path[path.length - 1] ?? "", path: [...path] },
|
|
926
|
+
decodedText: decodeXmlText(rawText),
|
|
927
|
+
end,
|
|
928
|
+
sourceEnd,
|
|
929
|
+
sourceStart,
|
|
930
|
+
start
|
|
931
|
+
});
|
|
932
|
+
};
|
|
933
|
+
while (index < source.length) {
|
|
934
|
+
if (source[index] !== "<") {
|
|
935
|
+
const nextTag = source.indexOf("<", index);
|
|
936
|
+
const end2 = nextTag === -1 ? source.length : nextTag;
|
|
937
|
+
addText(index, end2, source.slice(index, end2));
|
|
938
|
+
index = end2;
|
|
939
|
+
continue;
|
|
940
|
+
}
|
|
941
|
+
if (source.startsWith("<!--", index)) {
|
|
942
|
+
const end2 = source.indexOf("-->", index + 4);
|
|
943
|
+
index = end2 === -1 ? source.length : end2 + 3;
|
|
944
|
+
continue;
|
|
945
|
+
}
|
|
946
|
+
if (source.startsWith("<![CDATA[", index)) {
|
|
947
|
+
const contentStart = index + 9;
|
|
948
|
+
const end2 = source.indexOf("]]>", contentStart);
|
|
949
|
+
const contentEnd = end2 === -1 ? source.length : end2;
|
|
950
|
+
addText(
|
|
951
|
+
contentStart,
|
|
952
|
+
contentEnd,
|
|
953
|
+
source.slice(contentStart, contentEnd),
|
|
954
|
+
index,
|
|
955
|
+
end2 === -1 ? source.length : end2 + 3
|
|
956
|
+
);
|
|
957
|
+
index = end2 === -1 ? source.length : end2 + 3;
|
|
958
|
+
continue;
|
|
959
|
+
}
|
|
960
|
+
if (source.startsWith("<?", index)) {
|
|
961
|
+
const end2 = source.indexOf("?>", index + 2);
|
|
962
|
+
index = end2 === -1 ? source.length : end2 + 2;
|
|
963
|
+
continue;
|
|
964
|
+
}
|
|
965
|
+
if (source.startsWith("</", index)) {
|
|
966
|
+
const end2 = findTagEnd(source, index + 2);
|
|
967
|
+
path.pop();
|
|
968
|
+
index = end2 + 1;
|
|
969
|
+
continue;
|
|
970
|
+
}
|
|
971
|
+
const end = findTagEnd(source, index + 1);
|
|
972
|
+
const tag = source.slice(index, end + 1);
|
|
973
|
+
const name = readTagName(tag);
|
|
974
|
+
if (name && !/\/\s*>$/.test(tag)) path.push(name);
|
|
975
|
+
index = end + 1;
|
|
976
|
+
}
|
|
977
|
+
return nodes;
|
|
978
|
+
}
|
|
979
|
+
function extractSsmlText(ssml) {
|
|
980
|
+
parseSsml(ssml);
|
|
981
|
+
return collectTextNodes(ssml).map((node) => node.decodedText);
|
|
982
|
+
}
|
|
983
|
+
async function mapSsmlTextNodes(ssml, transform) {
|
|
984
|
+
parseSsml(ssml);
|
|
985
|
+
const nodes = collectTextNodes(ssml);
|
|
986
|
+
const replacements = await Promise.all(
|
|
987
|
+
nodes.map(async (node) => {
|
|
988
|
+
const transformed = await transform(node.decodedText, {
|
|
989
|
+
parentTag: node.context.parentTag,
|
|
990
|
+
path: [...node.context.path]
|
|
991
|
+
});
|
|
992
|
+
if (typeof transformed !== "string") {
|
|
993
|
+
throw new TypeError("SSML text node transform must return a string");
|
|
994
|
+
}
|
|
995
|
+
return transformed === node.decodedText ? ssml.slice(node.sourceStart, node.sourceEnd) : encodeXmlText(transformed);
|
|
996
|
+
})
|
|
997
|
+
);
|
|
998
|
+
let result = "";
|
|
999
|
+
let cursor = 0;
|
|
1000
|
+
nodes.forEach((node, nodeIndex) => {
|
|
1001
|
+
result += ssml.slice(cursor, node.sourceStart) + replacements[nodeIndex];
|
|
1002
|
+
cursor = node.sourceEnd;
|
|
1003
|
+
});
|
|
1004
|
+
return result + ssml.slice(cursor);
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
// packages/ssml-core/src/azureValidation.ts
|
|
1008
|
+
var EXPRESS_AS_STYLES = {
|
|
1009
|
+
"en-us-jennyneural": [
|
|
1010
|
+
"assistant",
|
|
1011
|
+
"chat",
|
|
1012
|
+
"customerservice",
|
|
1013
|
+
"newscast",
|
|
1014
|
+
"cheerful",
|
|
1015
|
+
"empathetic",
|
|
1016
|
+
"excited",
|
|
1017
|
+
"friendly",
|
|
1018
|
+
"hopeful",
|
|
1019
|
+
"sad",
|
|
1020
|
+
"shouting",
|
|
1021
|
+
"terrified",
|
|
1022
|
+
"unfriendly",
|
|
1023
|
+
"whispering"
|
|
1024
|
+
],
|
|
1025
|
+
"en-us-guyneural": [
|
|
1026
|
+
"angry",
|
|
1027
|
+
"cheerful",
|
|
1028
|
+
"excited",
|
|
1029
|
+
"friendly",
|
|
1030
|
+
"hopeful",
|
|
1031
|
+
"newscast",
|
|
1032
|
+
"sad",
|
|
1033
|
+
"shouting",
|
|
1034
|
+
"terrified",
|
|
1035
|
+
"unfriendly",
|
|
1036
|
+
"whispering"
|
|
1037
|
+
],
|
|
1038
|
+
"en-us-jennymultilingualneural": [
|
|
1039
|
+
"cheerful",
|
|
1040
|
+
"empathetic",
|
|
1041
|
+
"excited",
|
|
1042
|
+
"friendly",
|
|
1043
|
+
"hopeful",
|
|
1044
|
+
"sad",
|
|
1045
|
+
"shouting",
|
|
1046
|
+
"terrified",
|
|
1047
|
+
"unfriendly",
|
|
1048
|
+
"whispering"
|
|
1049
|
+
],
|
|
1050
|
+
"en-us-andrewneural": ["empathetic", "relieved"],
|
|
1051
|
+
"ja-jp-mayuneural": ["calm", "cheerful", "sad"],
|
|
1052
|
+
"ja-jp-nanamineural": ["chat", "customerservice", "cheerful", "whispering", "sad"],
|
|
1053
|
+
"ja-jp-keitaneural": ["chat"],
|
|
1054
|
+
"ko-kr-sunhineural": ["cheerful", "sad"],
|
|
1055
|
+
"zh-cn-yunxineural": [
|
|
1056
|
+
"narration-relaxed",
|
|
1057
|
+
"embarrassed",
|
|
1058
|
+
"fearful",
|
|
1059
|
+
"sad",
|
|
1060
|
+
"disgruntled",
|
|
1061
|
+
"serious",
|
|
1062
|
+
"angry",
|
|
1063
|
+
"depressed",
|
|
1064
|
+
"chat",
|
|
1065
|
+
"cheerful",
|
|
1066
|
+
"assistant"
|
|
1067
|
+
],
|
|
1068
|
+
"zh-cn-xiaoxiaoneural": [
|
|
1069
|
+
"assistant",
|
|
1070
|
+
"chat",
|
|
1071
|
+
"customerservice",
|
|
1072
|
+
"newscast",
|
|
1073
|
+
"cheerful",
|
|
1074
|
+
"empathetic",
|
|
1075
|
+
"excited",
|
|
1076
|
+
"friendly",
|
|
1077
|
+
"hopeful",
|
|
1078
|
+
"sad",
|
|
1079
|
+
"terrified",
|
|
1080
|
+
"whispering",
|
|
1081
|
+
"poetry-reading",
|
|
1082
|
+
"sports_commentary",
|
|
1083
|
+
"sports_commentary_excited",
|
|
1084
|
+
"story"
|
|
1085
|
+
],
|
|
1086
|
+
"fr-fr-deniseneural": ["cheerful", "sad"],
|
|
1087
|
+
"fr-fr-henrineural": ["cheerful", "sad"],
|
|
1088
|
+
"pt-br-franciscaneural": ["calm"],
|
|
1089
|
+
"it-it-elsaneural": ["cheerful", "sad"],
|
|
1090
|
+
"de-de-katjaneural": ["cheerful", "sad"],
|
|
1091
|
+
"de-de-conradneural": ["cheerful", "sad"],
|
|
1092
|
+
"ru-ru-svetlananeural": ["cheerful", "sad", "angry", "disgruntled", "embarrassed", "fearful"]
|
|
1093
|
+
};
|
|
1094
|
+
var ALLOWED_BREAK_STRENGTHS = /* @__PURE__ */ new Set(["none", "x-weak", "weak", "medium", "strong", "x-strong"]);
|
|
1095
|
+
var ALLOWED_SAY_AS = /* @__PURE__ */ new Set([
|
|
1096
|
+
"characters",
|
|
1097
|
+
"spell-out",
|
|
1098
|
+
"cardinal",
|
|
1099
|
+
"ordinal",
|
|
1100
|
+
"number",
|
|
1101
|
+
"date",
|
|
1102
|
+
"time",
|
|
1103
|
+
"telephone",
|
|
1104
|
+
"fraction",
|
|
1105
|
+
"address",
|
|
1106
|
+
"name",
|
|
1107
|
+
"currency"
|
|
1108
|
+
]);
|
|
1109
|
+
var ALLOWED_ROLES = /* @__PURE__ */ new Set([
|
|
1110
|
+
"Girl",
|
|
1111
|
+
"Boy",
|
|
1112
|
+
"YoungAdultFemale",
|
|
1113
|
+
"YoungAdultMale",
|
|
1114
|
+
"OlderAdultFemale",
|
|
1115
|
+
"OlderAdultMale",
|
|
1116
|
+
"SeniorFemale",
|
|
1117
|
+
"SeniorMale"
|
|
1118
|
+
]);
|
|
1119
|
+
var ALLOWED_EMPHASIS_LEVELS = /* @__PURE__ */ new Set(["strong", "moderate", "reduced", "none"]);
|
|
1120
|
+
var ALLOWED_SILENCE_TYPES = /* @__PURE__ */ new Set([
|
|
1121
|
+
"Leading",
|
|
1122
|
+
"Tailing",
|
|
1123
|
+
"Sentenceboundary",
|
|
1124
|
+
"Comma",
|
|
1125
|
+
"Semicolon",
|
|
1126
|
+
"Enumerationcomma"
|
|
1127
|
+
]);
|
|
1128
|
+
var ALLOWED_VISEME_TYPES = /* @__PURE__ */ new Set(["redlips_front", "FacialExpression"]);
|
|
1129
|
+
function decodeAttribute(value) {
|
|
1130
|
+
return value.replace(
|
|
1131
|
+
/&(?:amp|apos|gt|lt|quot);/gi,
|
|
1132
|
+
(entity) => ({ "&": "&", "'": "'", ">": ">", "<": "<", """: '"' })[entity.toLowerCase()] ?? entity
|
|
1133
|
+
);
|
|
1134
|
+
}
|
|
1135
|
+
function findTagEnd2(source, start) {
|
|
1136
|
+
let quote = "";
|
|
1137
|
+
for (let index = start; index < source.length; index += 1) {
|
|
1138
|
+
const character = source[index];
|
|
1139
|
+
if (quote) {
|
|
1140
|
+
if (character === quote) quote = "";
|
|
1141
|
+
} else if (character === '"' || character === "'") quote = character;
|
|
1142
|
+
else if (character === ">") return index;
|
|
1143
|
+
}
|
|
1144
|
+
return source.length - 1;
|
|
1145
|
+
}
|
|
1146
|
+
function tokenizeElements(source) {
|
|
1147
|
+
const tokens = [];
|
|
1148
|
+
let index = 0;
|
|
1149
|
+
while (index < source.length) {
|
|
1150
|
+
const start = source.indexOf("<", index);
|
|
1151
|
+
if (start === -1) break;
|
|
1152
|
+
if (source.startsWith("<!--", start)) {
|
|
1153
|
+
const end2 = source.indexOf("-->", start + 4);
|
|
1154
|
+
index = end2 === -1 ? source.length : end2 + 3;
|
|
1155
|
+
continue;
|
|
1156
|
+
}
|
|
1157
|
+
if (source.startsWith("<![CDATA[", start)) {
|
|
1158
|
+
const end2 = source.indexOf("]]>", start + 9);
|
|
1159
|
+
index = end2 === -1 ? source.length : end2 + 3;
|
|
1160
|
+
continue;
|
|
1161
|
+
}
|
|
1162
|
+
if (source.startsWith("<?", start)) {
|
|
1163
|
+
const end2 = source.indexOf("?>", start + 2);
|
|
1164
|
+
index = end2 === -1 ? source.length : end2 + 2;
|
|
1165
|
+
continue;
|
|
1166
|
+
}
|
|
1167
|
+
const end = findTagEnd2(source, start + 1);
|
|
1168
|
+
const raw = source.slice(start, end + 1);
|
|
1169
|
+
const nameMatch = /^<\s*([A-Za-z_][A-Za-z0-9_.:-]*)/.exec(raw);
|
|
1170
|
+
if (!nameMatch?.[1] || raw.startsWith("</")) {
|
|
1171
|
+
index = end + 1;
|
|
1172
|
+
continue;
|
|
1173
|
+
}
|
|
1174
|
+
const attributes = /* @__PURE__ */ new Map();
|
|
1175
|
+
const attributeSource = raw.slice(nameMatch[0].length, raw.length - 1).replace(/\/\s*$/, "");
|
|
1176
|
+
const attributePattern = /([A-Za-z_][A-Za-z0-9_.:-]*)\s*=\s*(["'])([\s\S]*?)\2/g;
|
|
1177
|
+
for (const match of attributeSource.matchAll(attributePattern)) {
|
|
1178
|
+
attributes.set(match[1].toLowerCase(), decodeAttribute(match[3]));
|
|
1179
|
+
}
|
|
1180
|
+
tokens.push({ attributes, end, name: nameMatch[1], selfClosing: /\/\s*>$/.test(raw), start });
|
|
1181
|
+
index = end + 1;
|
|
1182
|
+
}
|
|
1183
|
+
return tokens;
|
|
1184
|
+
}
|
|
1185
|
+
function location(source, offset) {
|
|
1186
|
+
const before = source.slice(0, Math.max(0, offset));
|
|
1187
|
+
const line = before.split("\n").length;
|
|
1188
|
+
return { line, column: before.length - (before.lastIndexOf("\n") + 1) + 1 };
|
|
1189
|
+
}
|
|
1190
|
+
function addDiagnostic(diagnostics, source, offset, message, severity = "error") {
|
|
1191
|
+
diagnostics.push({ ...location(source, offset), message, severity });
|
|
1192
|
+
}
|
|
1193
|
+
function attr(token, name) {
|
|
1194
|
+
return token.attributes.get(name.toLowerCase());
|
|
1195
|
+
}
|
|
1196
|
+
function validateElement(token, source, diagnostics, voiceName, options) {
|
|
1197
|
+
const name = token.name.toLowerCase();
|
|
1198
|
+
if (name === "voice" && !attr(token, "name")?.trim())
|
|
1199
|
+
addDiagnostic(diagnostics, source, token.start, '<voice> requires a non-empty "name" attribute.');
|
|
1200
|
+
if (name === "break") {
|
|
1201
|
+
const time = attr(token, "time");
|
|
1202
|
+
const strength = attr(token, "strength");
|
|
1203
|
+
if (!time && !strength)
|
|
1204
|
+
addDiagnostic(diagnostics, source, token.start, '<break> requires either "time" or "strength".');
|
|
1205
|
+
if (time && strength)
|
|
1206
|
+
addDiagnostic(diagnostics, source, token.start, '<break> must not specify both "time" and "strength".');
|
|
1207
|
+
if (time && !/^\d+(?:\.\d+)?(?:ms|s)$/.test(time.trim()))
|
|
1208
|
+
addDiagnostic(diagnostics, source, token.start, '<break time> must use a numeric value followed by "ms" or "s".');
|
|
1209
|
+
if (strength && !ALLOWED_BREAK_STRENGTHS.has(strength))
|
|
1210
|
+
addDiagnostic(diagnostics, source, token.start, `Unsupported <break strength> value "${strength}".`);
|
|
1211
|
+
}
|
|
1212
|
+
if (name === "prosody") {
|
|
1213
|
+
const rate = attr(token, "rate");
|
|
1214
|
+
const pitch = attr(token, "pitch");
|
|
1215
|
+
const volume = attr(token, "volume");
|
|
1216
|
+
if (rate && !/^(x-slow|slow|medium|fast|x-fast|[+-]?\d+(?:\.\d+)?%)$/.test(rate.trim()))
|
|
1217
|
+
addDiagnostic(diagnostics, source, token.start, `Unsupported <prosody rate> value "${rate}".`);
|
|
1218
|
+
if (pitch && !/^(x-low|low|medium|high|x-high|[+-]?\d+(?:\.\d+)?(?:st|Hz|%)?)$/.test(pitch.trim()))
|
|
1219
|
+
addDiagnostic(diagnostics, source, token.start, `Unsupported <prosody pitch> value "${pitch}".`);
|
|
1220
|
+
if (volume && !/^(silent|x-soft|soft|medium|loud|x-loud|[+-]?\d+(?:\.\d+)?(?:dB|%)?)$/.test(volume.trim()))
|
|
1221
|
+
addDiagnostic(diagnostics, source, token.start, `Unsupported <prosody volume> value "${volume}".`);
|
|
1222
|
+
}
|
|
1223
|
+
if (name === "mstts:express-as" || name === "express-as" || name === "expressas") {
|
|
1224
|
+
const style = attr(token, "style");
|
|
1225
|
+
if (!style?.trim())
|
|
1226
|
+
addDiagnostic(diagnostics, source, token.start, '<mstts:express-as> requires a non-empty "style" attribute.');
|
|
1227
|
+
const degree = attr(token, "styledegree") ?? attr(token, "style-degree");
|
|
1228
|
+
if (degree && (!/^\d+(?:\.\d+)?$/.test(degree) || Number(degree) < 0.01 || Number(degree) > 2))
|
|
1229
|
+
addDiagnostic(
|
|
1230
|
+
diagnostics,
|
|
1231
|
+
source,
|
|
1232
|
+
token.start,
|
|
1233
|
+
"<mstts:express-as styledegree> must be a number between 0.01 and 2."
|
|
1234
|
+
);
|
|
1235
|
+
const role = attr(token, "role");
|
|
1236
|
+
if (role && !ALLOWED_ROLES.has(role))
|
|
1237
|
+
addDiagnostic(diagnostics, source, token.start, `Unsupported <mstts:express-as role> value "${role}".`);
|
|
1238
|
+
const supportedStyles = voiceName ? EXPRESS_AS_STYLES[voiceName.toLowerCase()] : void 0;
|
|
1239
|
+
if (style && supportedStyles && !supportedStyles.includes(style.toLowerCase()))
|
|
1240
|
+
addDiagnostic(diagnostics, source, token.start, `Style "${style}" is not supported by voice "${voiceName}".`);
|
|
1241
|
+
}
|
|
1242
|
+
if (name === "say-as" || name === "sayas") {
|
|
1243
|
+
const interpretAs = attr(token, "interpret-as");
|
|
1244
|
+
if (!interpretAs || !ALLOWED_SAY_AS.has(interpretAs))
|
|
1245
|
+
addDiagnostic(diagnostics, source, token.start, `<say-as> requires a supported "interpret-as" value.`);
|
|
1246
|
+
}
|
|
1247
|
+
if (name === "phoneme" && (!attr(token, "alphabet") || !attr(token, "ph")))
|
|
1248
|
+
addDiagnostic(diagnostics, source, token.start, '<phoneme> requires both "alphabet" and "ph" attributes.');
|
|
1249
|
+
if (name === "emphasis" && attr(token, "level") && !ALLOWED_EMPHASIS_LEVELS.has(attr(token, "level") ?? ""))
|
|
1250
|
+
addDiagnostic(diagnostics, source, token.start, `Unsupported <emphasis level> value "${attr(token, "level")}".`);
|
|
1251
|
+
if (name === "sub" && !attr(token, "alias")?.trim())
|
|
1252
|
+
addDiagnostic(diagnostics, source, token.start, '<sub> requires a non-empty "alias" attribute.');
|
|
1253
|
+
if (name === "lang" && !attr(token, "xml:lang")?.trim() && !attr(token, "lang")?.trim())
|
|
1254
|
+
addDiagnostic(diagnostics, source, token.start, '<lang> requires an "xml:lang" attribute.');
|
|
1255
|
+
if (name === "mark" && !attr(token, "name")?.trim())
|
|
1256
|
+
addDiagnostic(diagnostics, source, token.start, '<mark> requires a non-empty "name" attribute.');
|
|
1257
|
+
if (name === "bookmark" && !attr(token, "mark")?.trim())
|
|
1258
|
+
addDiagnostic(diagnostics, source, token.start, '<bookmark> requires a non-empty "mark" attribute.');
|
|
1259
|
+
if (name === "lexicon") {
|
|
1260
|
+
const uri = attr(token, "uri");
|
|
1261
|
+
if (!uri) addDiagnostic(diagnostics, source, token.start, '<lexicon> requires a "uri" attribute.');
|
|
1262
|
+
else {
|
|
1263
|
+
try {
|
|
1264
|
+
const parsed = new URL(uri);
|
|
1265
|
+
if (parsed.protocol !== "https:")
|
|
1266
|
+
addDiagnostic(diagnostics, source, token.start, "<lexicon uri> must use HTTPS.");
|
|
1267
|
+
} catch {
|
|
1268
|
+
addDiagnostic(diagnostics, source, token.start, "<lexicon uri> must be an absolute HTTPS URL.");
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
if (name === "mstts:silence") {
|
|
1273
|
+
const type = attr(token, "type");
|
|
1274
|
+
const value = attr(token, "value");
|
|
1275
|
+
if (!type || !ALLOWED_SILENCE_TYPES.has(type))
|
|
1276
|
+
addDiagnostic(diagnostics, source, token.start, '<mstts:silence> requires a supported "type" attribute.');
|
|
1277
|
+
if (!value || !/^\d+(?:\.\d+)?(?:ms|s)$/.test(value.trim()))
|
|
1278
|
+
addDiagnostic(diagnostics, source, token.start, '<mstts:silence> requires a time-valued "value" attribute.');
|
|
1279
|
+
}
|
|
1280
|
+
if (name === "mstts:viseme") {
|
|
1281
|
+
const type = attr(token, "type");
|
|
1282
|
+
if (!type || !ALLOWED_VISEME_TYPES.has(type))
|
|
1283
|
+
addDiagnostic(diagnostics, source, token.start, '<mstts:viseme> requires a supported "type" attribute.');
|
|
1284
|
+
}
|
|
1285
|
+
if (name === "audio") {
|
|
1286
|
+
const src = attr(token, "src");
|
|
1287
|
+
if (!src) addDiagnostic(diagnostics, source, token.start, '<audio> requires a "src" attribute.');
|
|
1288
|
+
else {
|
|
1289
|
+
let parsed;
|
|
1290
|
+
try {
|
|
1291
|
+
parsed = new URL(src);
|
|
1292
|
+
} catch {
|
|
1293
|
+
addDiagnostic(diagnostics, source, token.start, "<audio src> must be an absolute HTTP(S) URL.");
|
|
1294
|
+
return;
|
|
1295
|
+
}
|
|
1296
|
+
if (parsed.protocol !== "https:" && !(options.allowHttpAudio && parsed.protocol === "http:"))
|
|
1297
|
+
addDiagnostic(diagnostics, source, token.start, "<audio src> must use HTTPS.");
|
|
1298
|
+
if (options.allowedAudioOrigins && !options.allowedAudioOrigins.includes(parsed.origin))
|
|
1299
|
+
addDiagnostic(diagnostics, source, token.start, `<audio src> origin "${parsed.origin}" is not allowed.`);
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
function validateAzureSsml(ssml, options = {}) {
|
|
1304
|
+
const diagnostics = [];
|
|
1305
|
+
if (typeof ssml !== "string") {
|
|
1306
|
+
return [{ line: 1, column: 1, message: "SSML input must be a string", severity: "error" }];
|
|
1307
|
+
}
|
|
1308
|
+
const maxLength = options.maxLength ?? 1e4;
|
|
1309
|
+
if (ssml.length > maxLength)
|
|
1310
|
+
addDiagnostic(diagnostics, ssml, maxLength, `SSML exceeds the maximum length of ${maxLength} characters.`);
|
|
1311
|
+
try {
|
|
1312
|
+
parseSsml(ssml);
|
|
1313
|
+
} catch (error) {
|
|
1314
|
+
const message = error instanceof Error ? error.message.replace(/ at position \d+$/, "") : String(error);
|
|
1315
|
+
const match = / at position (\d+)$/.exec(error instanceof Error ? error.message : "");
|
|
1316
|
+
addDiagnostic(diagnostics, ssml, match ? Number(match[1]) : 0, message);
|
|
1317
|
+
return diagnostics;
|
|
1318
|
+
}
|
|
1319
|
+
const tokens = tokenizeElements(ssml);
|
|
1320
|
+
const speak = tokens.find((token) => token.name.toLowerCase() === "speak");
|
|
1321
|
+
const voices = tokens.filter((token) => token.name.toLowerCase() === "voice");
|
|
1322
|
+
if (!speak || voices.length === 0)
|
|
1323
|
+
addDiagnostic(
|
|
1324
|
+
diagnostics,
|
|
1325
|
+
ssml,
|
|
1326
|
+
speak?.start ?? 0,
|
|
1327
|
+
"Azure SSML requires at least one <voice> element under <speak>."
|
|
1328
|
+
);
|
|
1329
|
+
const voiceName = voices[0] ? attr(voices[0], "name") : void 0;
|
|
1330
|
+
for (const token of tokens) validateElement(token, ssml, diagnostics, voiceName, options);
|
|
1331
|
+
return diagnostics;
|
|
1332
|
+
}
|
|
874
1333
|
// Annotate the CommonJS export names for ESM import in node:
|
|
875
1334
|
0 && (module.exports = {
|
|
876
1335
|
buildPartialSsml,
|
|
877
1336
|
buildSsml,
|
|
1337
|
+
extractSsmlText,
|
|
1338
|
+
mapSsmlTextNodes,
|
|
878
1339
|
parseSsml,
|
|
1340
|
+
validateAzureSsml,
|
|
879
1341
|
validateSsml
|
|
880
1342
|
});
|
|
881
1343
|
//# sourceMappingURL=core.js.map
|