Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/maghis/fluent-ssml

Alexa SSML templates
https://github.com/maghis/fluent-ssml

alexa aws nodejs skills speech ssml typescript

Last synced: about 2 months ago
JSON representation

Alexa SSML templates

Awesome Lists containing this project

README

        

# fluent-ssml

Compose Alexa SSML (*Speech Synthesis Markup Language*) with a fluent interface.

Features:
- support for the full [Alexa SSML Reference](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/speech-synthesis-markup-language-ssml-reference)
- everything is immutable, which makes it reusable and composable (like strings)
- simple templating
- extensible and testable
- typescript types!

**NOTE:** this package is tested on node v8.4.0

## install it

```
npm install --save fluent-ssml
```

## use it

Most basic template

```ts
import { ssml, renderXml } from "fluent-ssml";

const template = ssml("I am a template");

// prints I am a template
console.log(renderXml(template));
```

Using templated strings for parametric templates

```ts
const template = ssml(p => `${p.name} is a cool dude`);

// prints Jon is a cool dude
console.log(renderXml(template, { name: "Jon" }));
```

Use the fluent api for more complicated templates

This code...
```ts
const template = ssml()
.p(
ssml()
.sayAs("characters", "ssml")
.say("templates can get quite complicated")
)
.p("it's important to keep them composable and parametric")
.p(
ssml()
.say("if you do")
.break({ strength: "strong" })
.say(p => `you are gonna keep your ${p.quality}`)
)
.sayAs("interjection", "abracadabra");

// produces a simple object model with the rendered template
// easy to use for testing or debugging
const rendered = template.render({ quality: "sanity" });

// produces the final xml
const xml = renderXml(rendered);

console.log(xml);
```

...renders this (reformatted for clarity)
```xml


ssml templates can get quite complicated



it's important to keep them composable and parametric



if you do you are gonna keep your sanity


abracadabra

```