Skip to content

kevbite/Kevsoft.Ssml

Repository files navigation

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

Releases

No releases published

Packages

No packages published

Languages