npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ssml-check

v0.4.6

Published

Check for valid SSML

Downloads

10,822

Readme

SSML-Check

SSML-Check will verify that a given input is valid SSML. It is built on top of ssml-check-core, which provides core syntax validation of SSML. This library extends this functionality by looking into files accessed by the input SSML such as audio files to make sure they conform with platform expectations.

Usage

This library exposes two functions which allow you to check and optionally correct a given SSML string

Check

The first is check which verifies whether the given input is a valid SSML string on either the Amazon Alexa or Google Assistant platform (or both). This function returns a Promise with an array of errors indicating how the input fails validation, or a Promise of undefined if there are no errors.

check(ssml, options)

The arguments to this function are:

  • ssml - The SSML to check
  • options - Options for evaluating the SSML as noted below

The options structure is composed of the following fields with the following default values:

{
  platform:all,              // The voice platform to evaluate this SSML against.
                             // Valid values are "all", "amazon", or "google".
  locale:undefined,          // The locale you want to check against, used for certain
                             // locale-specific attributes like amazon:emotion
  validateAudioFiles:false,  // Whether to validate audio files against
                             // acceptable formats (bit rate, sample rate, etc)
  getPositions:false,        // If set, the index of the tag will be returned as the position
                             // field within the error object
  unsupportedTags:undefined, // An array of tags that will be flagged as invalid
                             // For example, ['prosody']
}

The return value is a Promise resolving to an array of errors that were encountered in processing the SSML, or undefined if no errors were encountered. The format of each error object is as follows:

{
  type,       // The type of error encountered ("tag," "audio" or a specific error)
  tag,        // The tag that had an error (set if type is "tag")
  attribute,  // The attribute that had an error (set if type is "tag")
  value,      // The attribute value that was in error (set if type is "tag" or "audio")
  detail,     // Further details about the error (set if type is "audio")
  position,   // The position of the start of the tag within the input string (set if getPositions is true)
}

The current version of ssml-check will check for the following:

  • Valid XML format
  • All tags are valid tags for their platform with valid attributes and values
  • No more than five audio tags in the response
  • Note invalid & character
  • Valid audio file format (HTTPS, MP3, length, bit rate, sample rate), if validateAudioFiles is set

Examples

const ssmlCheck = require('ssml-check');
ssmlCheck.check('<speak><prosody rate="5%">Hello world</prosody></speak>')
.then((errors) => {
  if (errors) {
    console.log(JSON.stringify(errors));
  } else {
    console.log('SSML is clean');
  }
});

will output [{"type":"tag","tag":"prosody","attribute":"rate","value":"5%"}]

const ssmlCheck = require('ssml-check');
ssmlCheck.check('<speak><audio src="https://foo.mp3"/></speak>', {validateAudioFiles: true})
.then((errors) => {
  if (errors) {
    console.log(JSON.stringify(errors));
  } else {
    console.log('SSML is clean');
  }
});

will output [{"type":"audio","value":"https://foo.mp3","detail":"Can't access file"}]

verifyAndFix

The second function is verifyAndFix which returns a Promise of an object containing an array of caught SSML errors (similar to check) and, if possible, corrected SSML as noted below.

verifyAndFix(ssml, options)

The arguments to this function, including the options structure, are the same as for check.

The return value is a Promise resolving to an object with the following fields:

{
  fixedSSML,  // A fixed SSML string if errors are found that can be corrected for
              // This field will be undefined if the SSML cannot be corrected
  errors,     // An array of errors. The format of each object in this array is as
              // defined above for the check function. This field is undefined
              // if there are no errors.    
}

If there are no errors, then the Promise will contain an empty object.

The current version of ssml-check will correct the following errors:

  • If more than five audio tags are in the response, elements after the first five are removed
  • If an invalid audio file is found when the validateAudioFiles option is set, the element will be removed
  • If an invalid tag is found, the element will be removed
  • If an invalid attribute is found, it will be removed (in the case of the src attribute for audio, if this is missing or invalid the element will be removed)
  • If an invalid value is found for an attribute within a valid tag, the value will be corrected as best possible. For example, adding a leading + to values that require it like prosody's pitch attribute, adjusting the value to be within an acceptable range, or substituting a default value if necessary

Examples

const ssmlCheck = require('ssml-check');
ssmlCheck.verifyAndFix('<speak><audio src="https://foo.mp3"/>This & that</speak>', {validateAudioFiles: true})
.then((result) => {
  if (result.fixedSSML) {
    console.log(result.fixedSSML);
  } else if (result.errors) {
    console.log(JSON.stringify(result.errors));
  } else {
    console.log('SSML is clean');
  }
});

will output <speak>This &amp; that</speak>

const ssmlCheck = require('ssml-check');
ssmlCheck.verifyAndFix('<speak><tag><prosody rate="60">Hello world</prosody></tag></speak>')
.then((result) => {
  if (result.fixedSSML) {
    console.log(result.fixedSSML);
  } else if (result.errors) {
    console.log(JSON.stringify(result.errors));
  } else {
    console.log('SSML is clean');
  }
});

will output <speak><prosody rate="60%">Hello world</prosody></speak>

Contributions

We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:

  • Reporting a bug
  • Discussing the current state of the code
  • Submitting a fix
  • Proposing new features

When contributing to this repository, please first discuss the change you wish to make by raising an issue or sending an e-mail with to the owners of this repository.