Getting Started with the Speech Server 2007 API

Speech Server 2007 has a really cool Windows Workflow based programming model that lets you quickly build interactive voice response applications. For many applications it is all you will ever need.

Sometimes however you find the workflow model just isn't the right fit. If you're looking for really fine-grained control over the application, or you simply prefer to work in code, then the Core API is what you need.

Unfortunately figuring out you want to use the API is a lot easier than figuring out how to start using it. There is very little documentation and no Visual Studio project templates or samples included with Speech Server.

I'll do my best to give a brick-simple explanation of how to get your first core API project started. You can also download the zipped project files.

1) First you'll need to create a new Voice Response Workflow Application. We'll use the project that gets generated as our foundation.

image

2) When asked for the application resources you'll want to uncheck everything.

image

3) Open up the Class1.cs file and remove all of the references to the VoiceResponseWorkflow1 class. The resulting class should look like the following (I removed the comments in the code for brevity):

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SpeechServer ;
using Microsoft.SpeechServer.Dialog;

namespace VoiceResponseWorkflowApplication1
{
    public class Class1 : IHostedSpeechApplication
    {     
        private IApplicationHost _host;

        public void Start(IApplicationHost host)
        {
            if (host != null)
            {
                _host = host;
                _host.TelephonySession.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("en-US");
            }
            else
            {
                throw new ArgumentNullException("host");
            }
        }
        public void Stop(bool immediate)
        {
        }

        public void OnUnhandledException(Exception exception)
        {
            if (exception != null)
            {
                _host.TelephonySession.LoggingManager.LogApplicationError(100, "An unexpected exception occurred: {0}", exception.Message);
            }
            else
            {
                _host.TelephonySession.LoggingManager.LogApplicationError(100, "An unknown exception occurred: {0}", System.Environment.StackTrace);
            }

            _host.OnCompleted();
        }
    }
}

That's all folks. Class1.cs is now the starting point of your Core API application. As a further example, lets take the project and add some code to turn it into an outbound dialing "Hello World" application.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SpeechServer ;
using Microsoft.SpeechServer.Dialog;

namespace VoiceResponseWorkflowApplication1
{
    public class Class1 : IHostedSpeechApplication
    {     
        private IApplicationHost _host;

        public void Start(IApplicationHost host)
        {
            if (host != null)
            {
                _host = host;
                _host.TelephonySession.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("en-US");
                // Dial and outbound call (make sure you change these numbers :-)
                _host.TelephonySession.OpenCompleted += new EventHandler<AsyncCompletedEventArgs>(TelephonySession_OpenCompleted);
                _host.TelephonySession.OpenAsync("7813062200", "8887006263");
            }
            else
            {
                throw new ArgumentNullException("host");
            }
        }

        void TelephonySession_OpenCompleted(object sender, AsyncCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                _host.TelephonySession.Close();
            }
            else
            {
                _host.TelephonySession.Synthesizer.SpeakCompleted += new EventHandler<Microsoft.SpeechServer.Synthesis.SpeakCompletedEventArgs>(Synthesizer_SpeakCompleted);
                _host.TelephonySession.Synthesizer.SpeakAsync("Hello World", Microsoft.SpeechServer.Synthesis.SynthesisTextFormat.PlainText);
            }
        }

        void Synthesizer_SpeakCompleted(object sender, Microsoft.SpeechServer.Synthesis.SpeakCompletedEventArgs e)
        {
            _host.TelephonySession.Close();
        }
        public void Stop(bool immediate)
        {
        }

        public void OnUnhandledException(Exception exception)
        {
            if (exception != null)
            {
                _host.TelephonySession.LoggingManager.LogApplicationError(100, "An unexpected exception occurred: {0}", exception.Message);
            }
            else
            {
                _host.TelephonySession.LoggingManager.LogApplicationError(100, "An unknown exception occurred: {0}", System.Environment.StackTrace);
            }

            _host.OnCompleted();
        }
    }
}

(download the zipped project)

11 Comments

  • It's a good idea to unsubscribe Synthesizer_SpeakCompleted once it's fired. It doesn't matter in this example, however if you were to subscribe a new handler and call SpeakAsync again, both handlers will fire, which might cause some confusion. Therefore it's a good practice to always unsubscribe the event handler.

  • That is an excellent point Anthony.

  • hi i have a problem with the built-in date grammar.can i use built-in date for "this week" and "next week".
    suppose if today is tuesday if i say next wednesday it is returning tomorrow's date but i want next week date. If i say next monday then it returns next week date means for the past days it is returning next week date.


    Is it possible for me to use both this week and next week dates in built-in date grammar.if possible give me the solution ...

  • you employ a fantastic weblog here! wish to earn some invite posts on
    my blog

  • You created some good tips at this time there.

    I did searching around that the topic and discovered
    most everyone will know in your web site.

  • Some actually interesting information , well written and broadly speaking user pleasant.

  • This site can be a walk-through it is the information you wanted concerning this and didn’t recognize who to ask.

    Glimpse here, and you’ll undoubtedly discover it.

  • Yay google is my world beater assisted me to lookup for this great
    web site ! .

  • Just something like the old saying goes, within that the pro’s
    head there have been few options, then again , for a person
    with the beginner’s brain, that the world is open up.

  • Hello! I just want to offer a huge thumbs up for that the
    great information you have here on this post. I will be coming back to your blog for more soon.

  • Can I just now say such a relief to discover one who truly knows what theyre dealing
    with on that the web. You really recognize how to bring
    a concern to light and earn it important. Lots
    more people have to look at this and see why side of that the story.
    I cant think youre not more popular as you certainly develop the gift.

Comments have been disabled for this content.