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

speech-builder

v2.2.0

Published

Utility to generate SSML markup for different voice platforms

Downloads

4

Readme

speech-builder

Build Status

Utility to build SSML documents for different voice platforms.

Motivation / Approach

Since the major voice platforms all support slightly different subsets of SSML, documents built for one platform often cause errors when used somewhere else.

To address this issue, speech-builder accepts a list of feature flags as configuration option.

Basic Usage

const { ssml } = require('speech-builder');

const s = ssml().add('Hello').emphasis('world');

console.log(s.toString());
<speak>Hello<emphasis>world</emphasis></speak>

Advanced Options

Base URI

SSML allows authors to specify URLs as relative paths which get resolved according to the xml:base attribute. This is especially useful for audio files which need to be encoded differently for each platform. On platforms that don't support xml:base speech-builder omits the attribute and performs the URL resolving itself.

ssml({
  features: 'alexa',
  base: 'https://example.com/audio/16k'
});

Lexicon

Speech sythesizers sometimes fail to pronounce words correctly, especially when mixing multiple languages. Using .phoneme() helps but can get quite cumbersome to write. As an alternative you can provide a lexicon:

ssml({
  features: 'alexa',
  lexicon: {
    "Passquote": "paskvoːtə",
    "Lloris Hugo": { 
      ipa: "lɔʹris yˌgo", 
      sub: "Lohrieß Ügo"
    }
  }
});

Plain Text Output

The speech-builder can not only output SSML markup but also a plain text representation with <p> tags converted into line breaks. This is useful for adding some basic formatting for visual surfaces.

ssml().p('Hello').p('world!').toPlainText();

API

Table of Contents

lang

Adds an xml:lang attribute to the current node. If not supported, this is a no-op.

Parameters

addText

Adds text. Characters with special meaning in XML are properly escaped.

Parameters

addToken

Like addText but prepends a space (unless it's the first token or the previous one alreads ends with whitespace).

Parameters

add

Like addToken but also accepts a function or an array.

Parameters

  • content any

sub

Adds a <sub> tag. If substitions are not supported, the alias is added as text instead.

Parameters

phoneme

Adds a <phoneme> tag. When an object with notations in different alphabets is passed as ph, the first one that is supported will be used. For platforms without phoneme support, the special sub alphabet can be used to generate a <sub> tag as fallback.

Parameters

break

Adds a <break> tag. If not supported, this is a no-op.

Parameters

audio

Adds an <audio> tag. If not supported, the alt text is added as plain text.

Parameters

emphasis

Adds an <emphasis> tag. If not supported, the text is added as-is.

Parameters

p

Adds a <p> tag. If not supported, the text is added as-is.

Parameters

  • content any

s

Adds an <s> tag. If not supported, the text is added as-is.

Parameters

  • content any

w

Adds a <w> tag. If not supported, the text is added as-is.

Parameters

effect

Adds an <*:effect> tag. If not supported, the text is added as-is. NOTE: The namespace can be configured via the effect feature setting.

Parameters

sayAs

Adds an <say-as> tag. If not supported, the text is added as-is.

Parameters

prosody

Adds a <prosody> tag. If not supported, the text is added as-is.

Parameters

toString

Returns the serialized SSML document.

Returns string

toPlainText

Returns the document without any markup. Paragraphs are turned into line breaks.

Returns string

replace

Duck-type as string to support the Jovo framework.

Parameters

Adding variations

const { ssml } = require('speech-builder');
const { random, chance } = require('variation');

ssml()
  .add(random('hello', 'ciao', 'hola', 'salut'))
  .add(chance(0.5, 'beautiful'))
  .add('world');

License

MIT