The string value to validate
true
if the value is a valid rate format, false
otherwise
// Valid rate values
console.log(isValidRate('slow')); // true - named value
console.log(isValidRate('x-fast')); // true - named value
console.log(isValidRate('+25%')); // true - percentage increase
console.log(isValidRate('-10%')); // true - percentage decrease
console.log(isValidRate('0.8')); // true - multiplier (80% speed)
console.log(isValidRate('1.5')); // true - multiplier (150% speed)
// Invalid rate values
console.log(isValidRate('very-slow')); // false - invalid named value
console.log(isValidRate('200%%')); // false - double percentage
// Use in validation
function setSpeechRate(rate: string) {
if (!isValidRate(rate)) {
throw new Error(`Invalid rate format: ${rate}`);
}
// Valid rate format
}
https://docs.microsoft.com/azure/cognitive-services/speech-service/speech-synthesis-markup#adjust-prosody Prosody Rate Documentation
Validates if a string represents a valid speech rate value.
Checks if the provided string matches any of the accepted rate formats for SSML prosody elements that control speaking speed.
Valid formats:
+25%
,-10%
,50%
(relative or absolute)0.5
,1.0
,2.0
(treated as percentage when no % sign)x-slow
,slow
,medium
,fast
,x-fast
The regex pattern matches: