The string value to validate
true
if the value is a valid silence type, false
otherwise
// Valid type
if (isValidSilenceType('Sentenceboundary')) {
// TypeScript knows this is a SilenceType
const type: SilenceType = 'Sentenceboundary';
}
// Invalid type
console.log(isValidSilenceType('Word-boundary')); // false
// Use in validation
function setSilenceType(value: string) {
if (!isValidSilenceType(value)) {
throw new Error(`Invalid silence type: ${value}`);
}
// Safe to use as SilenceType
}
https://docs.microsoft.com/azure/cognitive-services/speech-service/speech-synthesis-markup#add-silence Silence Element Documentation
Type guard to check if a string is a valid silence type value.
Validates that the provided string is one of the allowed silence type values for the
mstts:silence
element. This function acts as a TypeScript type guard, narrowing the type toSilenceType
when it returns true.Valid types:
Leading
: Extra silence at the beginningLeading-exact
: Exact silence at the beginningTailing
: Extra silence at the endTailing-exact
: Exact silence at the endSentenceboundary
: Extra silence between sentencesSentenceboundary-exact
: Exact silence between sentencesComma-exact
: Exact silence at commasSemicolon-exact
: Exact silence at semicolonsEnumerationcomma-exact
: Exact silence at enumeration commas