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-builder

v0.4.3

Published

This package creates Speech Synthesis Markup Language (SSML) using the builder pattern.

Downloads

518

Readme

ssml-builder

This package creates Speech Synthesis Markup Language (SSML) using the builder pattern.

Tired of creating SSML using string concatenation or worring about special characters like '&' ? This project aims to eliminate all these headaches by providing a clean and easy to use API. In addition to making SSML easier to create, this library is fully unit-tested to ensure things work as expected.

Whether you're building an Amazon Alexa Skill using the older version of the JavaScript SDK or the new one, this library is compatible. See the examples in the lower portion of this documentation.

Installation

npm install ssml-builder --save

Features

  • Works with both the new and old Alexa SDKs.
  • Handles special characters to ensure the SSML is well-formated.
  • This library supports the following SSML tags
    • amazon:effect
    • audio
    • break
    • emphasis
    • prosody
    • p
    • s
    • phoneme
    • speak
    • say-as which supports all of the known interpret-as values and formats. For more information, see Amazon Documentation here
      • characters
      • spell-out
      • cardinal
      • number
      • ordinal
      • digits
      • fraction
      • unit
      • date
      • time
      • telephone
      • address
      • interjection
      • expletive
    • sub
    • w
      • ivona:VB: Interpret the word as a verb (present simple).
      • ivona:VBD: Interpret the word as a past participle.
      • ivona:NN: Interpret the word as a noun.
      • ivona:SENSE_1: for more information, see Amazon Documentation here

Code Example for the new Alexa SDK

see link to the new Alexa SDK https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs

var Speech = require('ssml-builder');

var speech = new Speech();
speech.say('Hello')
      .pause('1s')
      .say('fellow Alexa developers')
      .pause('500ms')
      .say('Testing phone numbers')
      .sayAs({
              word: "+1-377-777-1888",
              interpret: "telephone"
            });
var speechOutput = speech.ssml(true);
this.emit(':tell', speechOutput);

The above code will produce the following SSML

Note: In this example, the SSML is not surrounded by <speak/> because we passed 'true' into the ssml(boolean) method. This is intentional to work with the new SDK due to their current design.

  'Hello <break time='1s'/> fellow Alexa developers <break time='500ms'/> Testing phone numbers <say-as interpret-as='telephone'>+1-377-777-1888</say-as>'

Code Example for the old Alexa SDK

var Speech = require('ssml-builder');

var speech = new Speech();
speech.say('Hello')
      .pause('1s')
      .say('fellow Alexa developers');
var speechOutput = speech.toObject();
response.tell(speechOutput);

The above code will produce the following object

  { 
    "type": "SSML",
    "speech": "<speak>Hello <break time='1s'/> fellow Alexa developers</speak>"
  }

Amazon SSML specific tags

When using Amazon specific tags, like whisper, you will need to import and use the AmazonSpeech object directly.

var AmazonSpeech = require('ssml-builder/amazon_speech');

var speech = new AmazonSpeech();
speech.say('Hello')
      .pause('1s')
      .whisper('I can see you when you are sleeping')
      .pause('500ms')
      .say('Is your phone number still')
      .sayAs({
              word: "+1-377-777-1888",
              interpret: "telephone"
            });
var ssml = speech.ssml();

Tag Examples

amazon:effect

speech.whisper('I can see you when you are sleeping');

audio

speech.audio('https://carfu.com/audio/carfu-welcome.mp3');

break

speech.pause('500ms')
      .say('you hear this after a 500 millisecond pause')
      .pause('2s')
      .say('you heard this after a 2 second pause');

emphasis

speech.emphasis('strong', 'phrase will be strong');
speech.emphasis('moderate', 'phrase will be moderate');
speech.emphasis('reduced', 'phrase will be reduced');

prosody

speech.prosody({rate: 'slow'}, 'say slow');
speech.prosody({rate: 'fast'}, 'say fast');
speech.prosody({rate: '120%'}, 'increase the rate of speech by 20%');
speech.prosody({rate: '35%'}, 'decrease the rate of speech by 35%');
speech.prosody({pitch: 'medium'}, 'set pitch to medium');
speech.prosody({pitch: 'x-high'}, 'set pitch to extra high');
speech.prosody({pitch: '+20%'}, 'increase the pitch by 20%');
speech.prosody({pitch: '-10%'}, 'decrease the pitch by 10%');
speech.prosody({volume: 'soft'}, 'set volume to soft');
speech.prosody({volume: 'loud'}, 'set volume to loud');
speech.prosody({volume: '+2db'}, 'increase volume by 2db');
speech.prosody({volume: '-3db'}, 'decrease volume by 3db');

p

speech.paragraph('phrase will be said with extra strong breaks before and after itself');

s

speech.sentence('phrase will be said with strong breaks before and after itself');

phoneme

speech.phoneme('ipa', "pɪˈkɑːn", 'pecan');
speech.phoneme('x-sampa', "fr\oU.z@n", 'frozen');

speak

speech.say('this will be said');

say-as

speech.sayAs({word: '12345', interpret: 'digits'});
speech.sayAs({word: 'usa', interpret: 'characters'});
speech.sayAs({word: '5553329939', interpret: 'telephone'});

sub

speech.sub('magnesium', 'Mg');

w

speech.partOfSpeech({word: 'record', role: 'amazon:VB'});
speech.partOfSpeech({word: 'record', role: 'amazon:NN'});