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

    Function isValidVolume

    • Validates if a string represents a valid volume value.

      Checks if the provided string matches any of the accepted volume formats for SSML prosody and background audio elements.

      Valid formats:

      • Decibels: +10dB, -5dB, 0dB (can be positive or negative)
      • Percentage: 50, 50%, 100, 100% (0-100)
      • Named values: silent, x-soft, soft, medium, loud, x-loud

      The regex patterns match:

      • Decibel format: Optional +/-, digits with optional decimal, 'dB' suffix
      • Percentage format: Digits with optional decimal, optional '%' suffix

      Parameters

      • value: string

        The string value to validate

      Returns boolean

      true if the value is a valid volume format, false otherwise

      // Valid volume values
      console.log(isValidVolume('50')); // true - percentage
      console.log(isValidVolume('75%')); // true - percentage with %
      console.log(isValidVolume('+10dB')); // true - positive decibels
      console.log(isValidVolume('-5.5dB')); // true - negative decibels
      console.log(isValidVolume('loud')); // true - named value
      console.log(isValidVolume('x-soft')); // true - named value

      // Invalid volume values
      console.log(isValidVolume('150%')); // false - over 100%
      console.log(isValidVolume('very-loud')); // false - invalid named value
      console.log(isValidVolume('10db')); // false - lowercase 'db'

      // Use in validation
      function setVolume(volume: string) {
      if (!isValidVolume(volume)) {
      throw new Error(`Invalid volume format: ${volume}`);
      }
      // Valid volume format
      }