Skip to content

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

License

Notifications You must be signed in to change notification settings

janniksam/SSMLBuilder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published