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

    Function isValidSilenceType

    • 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 to SilenceType when it returns true.

      Valid types:

      • Leading: Extra silence at the beginning
      • Leading-exact: Exact silence at the beginning
      • Tailing: Extra silence at the end
      • Tailing-exact: Exact silence at the end
      • Sentenceboundary: Extra silence between sentences
      • Sentenceboundary-exact: Exact silence between sentences
      • Comma-exact: Exact silence at commas
      • Semicolon-exact: Exact silence at semicolons
      • Enumerationcomma-exact: Exact silence at enumeration commas

      Parameters

      • value: string

        The string value to validate

      Returns value is SilenceType

      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
      }