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

alexa-ssml-builder

v1.0.0

Published

A Node.js utility for building valid SSML for Amazon Web Services Alexa Service

Downloads

4

Readme

Alexa SSML Builder

A utility for building valid SSML for use with Amazon Web Services Alexa service.

Amazon Alexa supports a subset of the SSML markup tags as defined by Speech Synthesis Markup Language (SSML) Version 1.1, W3C Recommendation.

Using a Builder Pattern, the AlexaSsmlBuilder class allows you to programmatically build up a valid SSML string.

This is an extension of PollySsmlBuilder.

Install

npm install alexa-ssml-builder

Usage

Start by requiring the library.

const AlexaSsmlBuilder = require("alexa-ssml-builder");

Then, for each SSML String you want to create, do the following:

  • create a new AlexaSsmlBuilder
  • call methods to speak text
  • build the String result
let alexaSsmlBuilder = new AlexaSsmlBuilder();
let ssml = alexaSsmlBuilder.speak("Don't tell anyone, but ")
    .whisper("I see dead people.")
    .build();

This produces the following String:

<speak>Don't tell anyone, but <amazon:effect name="whispered">I see dead people.</amazon:effect></speak>

All options are available as constants on the AlexaSsmlBuilder class. For example:

let alexaSsmlBuilder = new AlexaSsmlBuilder();
let ssml = alexaSsmlBuilder.speakPhonetically("pecan", alexaSsmlBuilder.ALPHABET_IPA, "pɪˈkɑːn")
    .build();

AlexaSsmlBuilder.ALPHABET_IPA specifies the "ipa" language.

Break

To add a break (pause) into the speech, call addBreak().

let alexaSsmlBuilder = new AlexaSsmlBuilder();
let ssml = alexaSsmlBuilder.speak("Legen - wait for it.")
    .addBreak(alexaSsmlBuilder.BREAK_STRONG)
    .speak("dary")
    .build();

The duration parameter can be one of the following:

  • The number of seconds specified as "10s" for 10 seconds
  • The number of milliseconds specified as "500ms" for 500 milliseconds
  • One of the BREAK_* constants

Speak with Emphasis

To change the emphasis of speech, call speakWithEmphasis().

let alexaSsmlBuilder = new AlexaSsmlBuilder();
let ssml = alexaSsmlBuilder.speakWithEmphasis("I'm speaking with emphasis!", alexaSsmlBuilder.EMPHASIS_STRONG)
    .build();

The level parameter can be one of the EMPHASIS_* constants.

Speak with Volume

To change the volume of speech, call speakWithVolume().

let alexaSsmlBuilder = new AlexaSsmlBuilder();
let ssml = alexaSsmlBuilder.speakWithVolume("I'm shouting!", alexaSsmlBuilder.VOLUME_XTRA_LOUD)
    .build();

The volume parameter can be one of the following:

  • An increase in volume as "+5dB" will increase the volume by 5 decibels
  • A decrease in volume as "-3dB" will decrease the volume by 3 decibels
  • One of the VOLUME_* constants

Speak with Rate

To change the rate of speech, call speakWithRate().

let alexaSsmlBuilder = new AlexaSsmlBuilder();
let ssml = alexaSsmlBuilder.speakWithRate("I'm speeking fast!", alexaSsmlBuilder.RATE_FAST)
    .build();

The rate parameter can be one of the following:

  • A percent rate over 100% as "150%" will increase the rate by 50 percent
  • A percent rate under 100% as "50%" will decrease the rate by 50 percent
  • One of the RATE_* constants

Speak with Pitch

To change the pitch of speech, call speakWithPitch().

let alexaSsmlBuilder = new AlexaSsmlBuilder();
let ssml = alexaSsmlBuilder.speakWithPitch("I'm speaking with a high voice!", alexaSsmlBuilder.PITCH_HIGH)
    .build();

The pitch parameter can be one of the following:

  • A percent increase in pitch as "+7%" will increase the pitch by 7 percent
  • A percent decrease in pitch as "-5%" will decrease the pitch by 5 percent
  • One of the PITCH_* constants

Speechcons

Alexa supports speechcons!

let alexaSsmlBuilder = new AlexaSsmlBuilder();
let ssml = alexaSsmlBuilder.speakWithSpeechcon("bingo")
    .build();

The text to speak is not validated as a valid speechcon. This is because the list of speechcons depends upon the language of the request. And the list of valid speechcon may change over time.

Here are the lists of valid speechons:

Paragraphs

Paragraphs can be spoken with one method call:

let alexaSsmlBuilder = new AlexaSsmlBuilder();
let ssml = alexaSsmlBuilder.speakWithParagraph("The quick brown fox jumped over the lazy dog.  It is a sentence that contains all the letters of the alphabet.")
    .build();

Or with multiple methods calls:

let replyBuilder = new AlexaSsmlBuilder();
let ssml = alexaSsmlBuilder.startParagraph()
    .speak("The quick brown fox jumped over the lazy dog.  ")
    .speak("It is a sentence that contains all the letters of the alphabet.")
    .endParagraph()
    .build();

Both of these options produce the same result.

If you forget to call endParagraph() before you build(), an Error will be thrown.

Sentences

Sentences work similar to paragraphs - they can be spoken with one method call, or multiple method calls.

Languages

Alexa does not (yet) support speaking in languages. Calling any of these methods will throw an error:

  • startLanguage()
  • endLanguage()
  • speakWithLanguage()

Mark

Alexa does not (yet) support adding a mark to the SSML. Calling this method will throw an error:

  • mark()

Supported Tags

For a full list of supported SSML tags, see Supported SSML Tags

All tags listed as of July 2017 are supported by this builder.

Authors

License

This project is licensed under the Apache 2.0 License - see the LICENSE.txt file for details