SSML Builder Documentation - v1.0.1
    Preparing search index...

    Function isValidRate

    • 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:

      • Percentage change: +25%, -10%, 50% (relative or absolute)
      • Multiplier: 0.5, 1.0, 2.0 (treated as percentage when no % sign)
      • Named values: x-slow, slow, medium, fast, x-fast

      The regex pattern matches:

      • Optional +/- sign
      • Digits with optional decimal
      • Optional '%' suffix

      Parameters

      • value: string

        The string value to validate

      Returns boolean

      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
      }