Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cellular/speech-builder
Utility to generate SSML markup for different voice platforms
https://github.com/cellular/speech-builder
Last synced: about 2 months ago
JSON representation
Utility to generate SSML markup for different voice platforms
- Host: GitHub
- URL: https://github.com/cellular/speech-builder
- Owner: cellular
- Created: 2018-05-22T12:50:38.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-06-08T14:26:08.000Z (over 6 years ago)
- Last Synced: 2024-06-03T01:36:36.363Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 78.1 KB
- Stars: 18
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# speech-builder
[![Build Status](https://travis-ci.org/cellular/speech-builder.svg?branch=master)](https://travis-ci.org/cellular/speech-builder)
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
```js
const { ssml } = require('speech-builder');const s = ssml().add('Hello').emphasis('world');
console.log(s.toString());
``````xml
Helloworld
```## Advanced Options
### Base URI
SSML allows authors to specify URLs as relative paths which get resolved according to the [xml:base](`https://www.w3.org/TR/2009/REC-speech-synthesis-20090303/#S3.1.3) 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.
```js
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:
```js
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 `` tags converted into line breaks. This is useful
for adding some basic formatting for visual surfaces.```js
ssml().p('Hello').p('world!').toPlainText();
```## API
#### Table of Contents
- [lang](#lang)
- [addText](#addtext)
- [addToken](#addtoken)
- [add](#add)
- [sub](#sub)
- [phoneme](#phoneme)
- [break](#break)
- [audio](#audio)
- [emphasis](#emphasis)
- [p](#p)
- [s](#s)
- [w](#w)
- [effect](#effect)
- [sayAs](#sayas)
- [prosody](#prosody)
- [toString](#tostring)
- [toPlainText](#toplaintext)
- [replace](#replace)### lang
Adds an `xml:lang` attribute to the current node.
If not supported, this is a no-op.**Parameters**
- `lang` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?**
### addText
Adds text. Characters with special meaning in XML are properly escaped.
**Parameters**
- `text` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))**
### addToken
Like `addText` but prepends a space (unless it's the first token or the
previous one alreads ends with whitespace).**Parameters**
- `text` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))**
### add
Like `addToken` but also accepts a function or an array.
**Parameters**
- `content` **any**
### sub
Adds a `` tag. If substitions are not supported,
the alias is added as text instead.**Parameters**
- `text` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `alias` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?**### phoneme
Adds a `` 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 `` tag as fallback.**Parameters**
- `text` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `ph` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)? | {})**### break
Adds a `` tag. If not supported, this is a no-op.
**Parameters**
- `time` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)? | [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))**
### audio
Adds an `` tag. If not supported, the alt text
is added as plain text.**Parameters**
- `src` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | {src: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), alt: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?})**
### emphasis
Adds an `` tag. If not supported, the text is added as-is.
**Parameters**
- `content` **any**
- `level` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?**### p
Adds a `
` tag. If not supported, the text is added as-is.
**Parameters**
- `content` **any**
### s
Adds an `` tag. If not supported, the text is added as-is.
**Parameters**
- `content` **any**
### w
Adds a `` tag. If not supported, the text is added as-is.
**Parameters**
- `role` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `content` **any**### 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**
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `content` **any**### sayAs
Adds an `` tag. If not supported, the text is added as-is.
**Parameters**
- `interpretAs` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `text` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))**
- `format` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?**
- `detail` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)? | [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))**### prosody
Adds a `` tag. If not supported, the text is added as-is.
**Parameters**
- `attrs` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `text` **any**### toString
Returns the serialized SSML document.
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
### toPlainText
Returns the document without any markup.
Paragraphs are turned into line breaks.Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
### replace
Duck-type as string to support the Jovo framework.
**Parameters**
- `pattern` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [RegExp](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp))**
- `replacement` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function))**## Adding variations
```js
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