Git Product home page Git Product logo

ssmlbuilder's Introduction

SSMLBuilder

Yet another SSML Builder, that uses the Razor Engine to render the SSML output

Build status master NuGet version

Why did I create this builder?

Personally, I don't like coding down stuff in an imperative manner, when it comes to reports or other similar UI'ish stuff. Microsoft offers the Razor engine to develop powerful web-frontends with a mix of HTML and C#. The best thing about razor is that it is not restricted to the use inside an ASP.NET application.

Since SSML is more or less XML with a fixed subset of tags, I figured, why not try to build my SSML Builder using the powerful Razor Engine

Special thanks to

I would like to thank @toddams and all those who took part in the development of the RazorLight implementation that I am basing this builder on. For more information, go and visit: https://github.com/toddams/RazorLight

How does it work?

Basically, you first have to build a .cshtml-View we know from ASP.NET application. That view will later be compiled into the SSML.

Here is a simple example:

@inherits SSMLBuilder.SSMLPage<SSMLBuilderTests.Game>
<speak>
    <p>
        The clock is ticking down
        5<break time='0.3s' />
        4<break time='0.3s' />
        3<break time='0.3s' />
        2<break time='0.3s' />
        1<break time='0.8s' />

        @if (Model.PlayerAmount == 5 || Model.PlayerAmount == 6)
        {
            <p>
                We started with less than 7 people.
                <break time='5s' />
                3<break time='0.3s' />
                2<break time='0.3s' />
                1<break time='0.3s' />
            </p>
        }
        else
        {
            <p>
                We started with more than 6 people.
                <break time='5s'/>
                3<break time='0.3s'/>
                2<break time='0.3s'/>
                1<break time='0.3s'/>
            </p>
        }
        
        This is the end
    </p>
</speak>

When you finished, you can throw the view into the builder, append a model and finally let the razor engine do it's magic:

var templateKey = "SSMLBuilderTests.SSMLViews.TestView.cshtml";
var assembly = GetType().GetTypeInfo().Assembly;
var resource = assembly.GetManifestResourceStream(templateKey);
var ssmlResult = await SSMLRazorBuilder.BuildFromAsync(resource, templateKey, new Game { PlayerAmount = 5 });

The result in this example will look like this:

<speak>
    <p>
        The clock is ticking down
        5<break time='0.3s' />
        4<break time='0.3s' />
        3<break time='0.3s' />
        2<break time='0.3s' />
        1<break time='0.8s' />

            <p>
                We started with less than 7 people.
                <break time='5s' />
                3<break time='0.3s' />
                2<break time='0.3s' />
                1<break time='0.3s' />
            </p>
        
        This is the end
    </p>
</speak>

I used a dynamic model in this example. Feel free to use whatever type you like.

Verification

Be sure to always verify the SSML after the razor engine, since I cannot guarantee that your razor view is SSML-conform.

You can find my SSMLVerifier here.

ssmlbuilder's People

Contributors

janniksam avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

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.