Coder Social home page Coder Social logo

fluent-ssml's Introduction

fluent-ssml

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

Features:

  • support for the full Alexa 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

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

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

// prints <speak>I am a template</speak>
console.log(renderXml(template));

Using templated strings for parametric templates

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

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

Use the fluent api for more complicated templates

This code...

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)

<speak>
    <p>
        <say-as interpret-as="characters">ssml</say-as> templates can get quite complicated
    </p>
    <p>
        it's important to keep them composable and parametric
    </p>
    <p>
        if you do <break strength="strong"/> you are gonna keep your sanity
    </p>
    <say-as interpret-as="interjection">abracadabra</say-as>
</speak>

fluent-ssml's People

Contributors

javaday avatar maghis avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

javaday

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.