The string value to validate
true
if the value is a valid emphasis level, false
otherwise
// Valid level
if (isValidEmphasisLevel('strong')) {
// TypeScript knows this is an EmphasisLevel
const level: EmphasisLevel = 'strong';
}
// Invalid level
console.log(isValidEmphasisLevel('very-strong')); // false
// Use in validation
function setEmphasisLevel(value: string) {
if (!isValidEmphasisLevel(value)) {
throw new Error(`Invalid emphasis level: ${value}`);
}
// Safe to use as EmphasisLevel
}
https://docs.microsoft.com/azure/cognitive-services/speech-service/speech-synthesis-markup#adjust-emphasis Emphasis Element Documentation
Type guard to check if a string is a valid emphasis level value.
Validates that the provided string is one of the allowed emphasis level values according to the SSML specification. This function acts as a TypeScript type guard, narrowing the type to
EmphasisLevel
when it returns true.Valid levels:
strong
: High emphasis with significant pitch and timing changesmoderate
: Medium emphasis (default)reduced
: De-emphasis with lower pitch and faster speech