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

    Function isValidEmphasisLevel

    • 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 changes
      • moderate: Medium emphasis (default)
      • reduced: De-emphasis with lower pitch and faster speech

      Parameters

      • value: string

        The string value to validate

      Returns value is EmphasisLevel

      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
      }