Git Product home page Git Product logo

kevsoft.ssml's Introduction

Fluent-ish SSML Generator

SSML allows you to build XML easily by using a fluent-ish SSML.

install from nuget downloads Build status

Getting Started

SSML can be installed via the package manager console by executing the following commandlet:

PM> Install-Package SSML

or by using the dotnet CLI:

$ dotnet add package SSML

Usage

Plain text

var xml = await new Ssml().Say("Hello")
    .Say("World")
    .ToStringAsync();
<?xml version="1.0" encoding="UTF-8"?>
<speak>Hello World</speak>

Text with Alias

 var xml = await new Ssml().Say("Hello")
    .Say("World")
    .AsAlias("Bob")
    .ToStringAsync();
<?xml version="1.0" encoding="UTF-8"?>
<speak>
   Hello
   <sub alias="Bob">World</sub>
</speak>

Emphasise word or phrase

var xml = await new Ssml().Say("Hello")
    .Say("World")
    .Emphasised()
    .ToStringAsync();
<?xml version="1.0" encoding="UTF-8"?>
<speak>
   Hello
   <emphasis>World</emphasis>
</speak>

Break

var xml = await new Ssml().Say("Take a deep breath")
    .Break()
    .Say("then continue.")
    .ToStringAsync();
<?xml version="1.0" encoding="UTF-8"?>
<speak>
   Take a deep breath
   <break />
   then continue.
</speak>

Say-as Date

var date = new DateTime(2017, 09, 15);

var xml = await new Ssml()
    .Say("This code was written on")
    .Say(date).As(DateFormat.YearMonth)
    .ToStringAsync();
<?xml version="1.0" encoding="UTF-8"?>
<speak>
   This code was written on
   <say-as interpret-as="date" format="ym">201709</say-as>
</speak>

Say-as Time

var time = new TimeSpan(20, 05, 33);

var xml = await new Ssml().Say("Bedtime is")
    .Say(time).In(TimeFormat.TwentyFourHour)
    .ToStringAsync();
<?xml version="1.0" encoding="UTF-8"?>
<speak>
   Bedtime is
   <say-as interpret-as="time" format="hms24">20:05:33</say-as>
</speak>

Say-as Telephone

var xml = await new Ssml()
    .Say("If you require a new job, please phone")
    .Say("+44 (0)114 273 0281").AsTelephone()
    .ToStringAsync();
<?xml version="1.0" encoding="UTF-8"?>
<speak>
   If you require a new job, please phone
   <say-as interpret-as="telephone">+44 (0)114 273 0281</say-as>
</speak>

Say-as characters

var xml = await new Ssml()
    .Say("It's as easy as")
    .Say("abc").AsCharacters()
    .ToStringAsync();
<?xml version="1.0" encoding="UTF-8"?>
<speak>
   It's as easy as
   <say-as interpret-as="characters" format="characters">abc</say-as>
</speak>

Say-as characters with glyph information

var xml = await new Ssml()
    .Say("It's as easy as")
    .Say("abc").AsCharacters().WithGlyphInformation()
    .ToStringAsync();
<?xml version="1.0" encoding="UTF-8"?>
<speak>
   It's as easy as
   <say-as interpret-as="characters" format="characters" format="glyph">abc</say-as>
</speak>

Say-as cardinal number

var xml = await new Ssml()
    .Say("We only have")
    .Say(512).AsCardinalNumber()
    .ToStringAsync();
<?xml version="1.0" encoding="UTF-8"?>
<speak>
   We only have
   <say-as interpret-as="cardinal">512</say-as>
</speak>

Say-as ordinal number

var xml = await new Ssml()
    .Say("We only have")
    .Say(512).AsOrdinalNumber()
    .ToStringAsync();
<?xml version="1.0" encoding="UTF-8"?>
<speak>
   We only have
   <say-as interpret-as="ordinal">512</say-as>
</speak>

Say-as voice

var xml = await new Ssml().Say("Hello")
    .Say("World")
    .AsVoice("en-US-Jessa24kRUS")
    .ToStringAsync();
<?xml version="1.0" encoding="UTF-8"?>
<speak>
    Hello <voice name=""en-US-Jessa24kRUS"">World</voice>
</speak>

https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/speech-synthesis-markup

Language support

var xml = await new Ssml(lang: "zh-CN")
    .Say("这样做吗")
    .Break().WithStrength(BreakStrength.ExtraStrong).For(TimeSpan.FromMilliseconds(100.1))
    .Say("是的,它确实!")
    .ToStringAsync();;
<?xml version="1.0" encoding="UTF-8"?>
<speak version="1.0" xml:lang="zh-CN">
   这样做吗
   <break strength="x-strong" time="100ms" />
   是的,它确实!
</speak>

More usages

For full set of usages checkout the unit tests within the Kevsoft.Ssml.Tests project.

Contributing

  1. Fork
  2. Hack!
  3. Pull Request

kevsoft.ssml's People

Contributors

aalmada avatar kevbite avatar rodric75 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

kevsoft.ssml's Issues

Make version and namespace configurable.

A quick fix was implemented in Pull Request #8 to fix the issue with the following response from the Alexa API:

{"ssml": "<speak version="1.0" xml:lang="en-US" xmlns="http://www.w3.org/2001/10/synthesis\">Welcome to my test system",
"error": {
"type": "INVALID_RESPONSE",
"message": "Invalid SSML Output Speech for requestId amzn1.echo-api.request.96189453-aa3b-4104-9c4a-769ab34ede09. Error: Invalid attribute version for SSML element speak"
}

It would be nice to implement this in a more configurable way in case other people have similar issues with none Alexa APIs. We also need to add in some tests to cover these scenarios.

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.