How do I develop Silverlight applications that speak and listen?

Last reviewed: 1/14/2012

HOW Article ID: H071133

The information in this article applies to:

  • SpeechKit 7

Summary

You can develop Silverlight applications that speak and listen using your favorite Silverlight development tools such as Microsoft Visual C# .NET and Microsoft Visual Basic .NET.

More Information

To access the SpeechKit Silverlight classes within your application, add them to your project References:

  1. Within your Silverlight project, right click on the References folder in C# or Open MyProject in VB and select the References tab.
  2. For Silverlight V4 applications, add references to the SpeechKit Silverlight assemblies:
    1. Program Files\Chant\SpeechKit 7\Win32\Silverlight\libv4\Chant.SpeechKit.Silverlight.dll and
    2. Program Files\Chant\SpeechKit 7\Win32\Silverlight\libv4\Chant.Shared.Silverlight.dll.
  3. For Silverlight V5 applications, add references to the SpeechKit Silverlight assemblies:
    1. Program Files\Chant\SpeechKit 7\Win32\Silverlight\libv5\Chant.SpeechKit.Silverlight.dll and
    2. Program Files\Chant\SpeechKit 7\Win32\Silverlight\libv5\Chant.Shared.Silverlight.dll.
  1. Within your Silverlight project, right click on the References folder in C# or Open MyProject in VB and select the References tab.
  2. For Silverlight V5 applications, add references to the SpeechKit Silverlight assemblies:
    1. Program Files\Chant\SpeechKit 7\Win64\Silverlight\libv5\Chant.SpeechKit.Silverlight.dll and
    2. Program Files\Chant\SpeechKit 7\Win64\Silverlight\libv5\Chant.Shared.Silverlight.dll.

To access the SpeechKit Silverlight classes within your application, add references to the SpeechKit assemblies in your code:


using System;
...
using Chant.SpeechKit.Silverlight;
using Chant.Shared.Silverlight;
        

Imports Chant.SpeechKit.Silverlight
Imports Chant.Shared.Silverlight
Class MainWindow
...

Out-of-Browser Settings

To run your Silverlight app out-of-browser, set the properties as follows:

  1. Within your Silverlight project, select the Silverlight tab under project properties.
  2. Select the checkbox: Enable application running out of the browser.
  3. Deselect the checkbox: Require elevated trust when running in-browser.
  4. Press the Out-of-Browser Settings... button.
  5. Select the checkbox: Required elevated trust when running outside the browser.

In-Browser Settings

To run your Silverlight app in-browser, set the properties as follows:

  1. Within your Silverlight project, select the Silverlight tab under project properties.
  2. Select the checkbox: Require elevated trust when running in-browser.
  3. Deselect the checkbox: Enable application running out of the browser.
  4. Select the Signing tab under project properties.
  5. Select the checkbox: Sign the Xap File.
  6. Press one of the three buttons to select a signing certificate:
    1. Select from Store... if you have installed a signing certificate on your system;
    2. Select from File... if you have a signing certificate file your system; or
    3. Create test certificate... if you do not have signing certificate on your system.
  7. Press the More Details... button to ensure you have installed Trusted Root and Publisher certificiates:
    1. Press the Install Certificate... button;
    2. Select Automatically ... option if you have Certificate installed in your store or Select Place ... option if you created a temp certificate for testing and press the Browse button;
    3. Select Trusted Root Certification Authorities and press the OK button; and
    4. Press the Next button.
    5. Repeat the process by Pressing the Install Certificate... button;
    6. Select Place ... option and press the Browse button;
    7. Select Trusted Publishers and press the OK button; and
    8. Press the Next button.
  8. Run regedit to add a Silverlight registery property AllowElevatedTrustAppsInBrowser with value of 1:
    1. Select the Start menu and enter regedit to launch the Registry Editor;
    2. For Win32 systems, navigate to HKEY_LOCAL_MACHINE\Software\Microsoft\Silverlight\;
    3. For Win64 systems, navigate to HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Silverlight\;
    4. Right click and select New->DWORD (32-bit) Value;
    5. Set the value name to AllowElevatedTrustAppsInBrowser;
    6. Set th value data to 1;
    7. Press the OK button; and
    8. Close the Registry Editor.

Object Instantiation

Declare a global variable for the ChantSR class, instantiate an instance, add the event handler, and set the license and serial properties.


private Chant.SpeechKit.Silverlight.NChantAudio NChantAudio1;
private Chant.SpeechKit.Silverlight.NChantSR NChantSR1;
private Chant.SpeechKit.Silverlight.NChantTTS NChantTTS1;
public MainPage()
{
    InitializeComponent();
    // Instantiate NChantSR object
    NChantSR1 = new NChantSR(this);
    // Setup event callback handler
    NChantSR1.HasEvent += new Chant.SpeechKit.Silverlight.NChantSR.HasEventHandler(this.NChantSR1_HasEvent);
    // Set license properties
    NChantSR1.SetStringProperty(ChantStringProperty.CSPLicense, "LicenseRegistrationNumber");
    NChantSR1.SetStringProperty(ChantStringProperty.CSPSerials, "LicenseSerialNumber");

    // Instantiate NChantSR object
    NChantSR1 = new NChantSR(this);
    // Setup event callback handler
    NChantSR1.HasEvent += new Chant.SpeechKit.Silverlight.NChantSR.HasEventHandler(this.NChantSR1_HasEvent);
    // Set license properties
    NChantSR1.SetStringProperty(ChantStringProperty.CSPLicense, "LicenseRegistrationNumber");
    NChantSR1.SetStringProperty(ChantStringProperty.CSPSerials, "LicenseSerialNumber");

    // Instantiate NChantTTS object
    NChantTTS1 = new NChantTTS(this);
    // Setup event callback handler
    NChantTTS1.HasEvent += new Chant.SpeechKit.Silverlight.NChantTTS.HasEventHandler(this.NChantTTS1_HasEvent);
    // Set license properties
    NChantTTS1.SetStringProperty(ChantStringProperty.CSPLicense, "LicenseRegistrationNumber");
    NChantTTS1.SetStringProperty(ChantStringProperty.CSPSerials, "LicenseSerialNumber");
}

Dim WithEvents NChantAudio1 As NChantAudio
Dim WithEvents NChantSR1 As NChantSR
Dim WithEvents NChantTTS1 As NChantTTS

Private Sub UserControl_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
    NChantAudio1 = New NChantAudio(Me)
    NChantSR1 = New NChantSR(Me)
    NChantTTS1 = New NChantTTS(Me)

    ' Set license properties
    NChantAudio1.SetStringProperty(ChantStringProperty.CSPLicense, "LicenseRegistrationNumber")
    NChantAudio1.SetStringProperty(ChantStringProperty.CSPSerials, "LicenseSerialNumber")

    ' Set license properties
    NChantSR1.SetStringProperty(ChantStringProperty.CSPLicense, "LicenseRegistrationNumber")
    NChantSR1.SetStringProperty(ChantStringProperty.CSPSerials, "LicenseSerialNumber")

    ' Set license properties
    NChantTTS1.SetStringProperty(ChantStringProperty.CSPLicense, "LicenseRegistrationNumber")
    NChantTTS1.SetStringProperty(ChantStringProperty.CSPSerials, "LicenseSerialNumber")

    ...

End Sub

Event Callbacks

Event callbacks are the mechanism in which the component library sends information back to the application such as a headset was plugged in, speech recognition occurred, audio playback finished, or there was an error.


private void NChantAudio1_HasEvent(object sender, HasEventArgs e)
{
    // Get the number of events
    int numberOfEvents = NChantAudio1.GetResourceCount(ChantSpeechResource.CSREvent, 0, 0);
    for (int i = 0; i < numberOfEvents; i++)
    {
        // Get the event from the event queue
        NChantAudioEvent nChantAudioEvent = NChantAudio1.GetChantAudioEvent(0);
        switch (nChantAudioEvent.ChantCallback)
        {
            case ChantCallback.CCDDeviceArrival:
                {
                    ...
                    break;
                }
            default:
                break;
        }
        // Remove the event from the event queue
        NChantAudio1.RemoveResource(ChantSpeechResource.CSREvent, 0, 0, "");
    }
}

private void NChantSR1_HasEvent(object sender, HasEventArgs e)
{
    // Get the number of events
    int numberOfEvents = NChantSR1.GetResourceCount(ChantSpeechResource.CSREvent, 0, 0);
    for (int i = 0; i < numberOfEvents; i++)
    {
        // Get the event from the event queue
        NChantSREvent nChantSREvent = NChantSR1.GetChantSREvent(0);
        switch (nChantSREvent.ChantCallback)
        {
            case ChantCallback.CCSRHasCommand:
                {
                    ...
                    break;
                }
            default:
                break;
        }
        // Remove the event from the event queue
        NChantSR1.RemoveResource(ChantSpeechResource.CSREvent, 0, 0, "");
    }
}

private void NChantTTS1_HasEvent(object sender, HasEventArgs e)
{
    // Get the number of events
    int numberOfEvents = NChantTTS1.GetResourceCount(ChantSpeechResource.CSREvent, 0, 0);
    for (int i = 0; i < numberOfEvents; i++)
    {
        // Get the event from the event queue
        NChantTTSEvent nChantTTSEvent = NChantTTS1.GetChantTTSEvent(0);
        switch (nChantTTSEvent.ChantCallback)
        {
            case ChantCallback.CCDAudioStop:
                {
                    ...
                    break;
                }
            default:
                break;
        }
        // Remove the event from the event queue
        NChantTTS1.RemoveResource(ChantSpeechResource.CSREvent, 0, 0, "");
    }
}

Private Sub NChantAudio1_HasEvent(ByVal sender As System.Object, ByVal e As HasEventArgs) Handles NChantAudio1.HasEvent
    Dim I As Integer
    Dim numberOfEvents As Integer
    Dim nChantAudioEvent As NChantAudioEvent
    ' Get the number of events
    numberOfEvents = NChantAudio1.GetResourceCount(ChantSpeechResource.CSREvent, 0, 0)
    For I = 0 To numberOfEvents - 1
        ' Get the event from the event queue
        nChantAudioEvent = NChantAudio1.GetChantAudioEvent(0)
        Select Case nChantAudioEvent.ChantCallback
            Case ChantCallback.CCDDeviceArrival
                ...
        End Select
        ' Remove the event from the event queue
        NChantAudio1.RemoveResource(ChantSpeechResource.CSREvent, 0, 0, "")
    Next
End Sub

Private Sub NChantSR1_HasEvent(ByVal sender As System.Object, ByVal e As HasEventArgs) Handles NChantSR1.HasEvent
    Dim I As Integer
    Dim numberOfEvents As Integer
    Dim nChantSREvent As NChantSREvent
    ' Get the number of events
    numberOfEvents = NChantSR1.GetResourceCount(ChantSpeechResource.CSREvent, 0, 0)
    For I = 0 To numberOfEvents - 1
        ' Get the event from the event queue
        nChantSREvent = NChantSR1.GetChantSREvent(0)
        Select Case nChantSREvent.ChantCallback
            Case ChantCallback.CCSRHasCommand
                ...
        End Select
        ' Remove the event from the event queue
        NChantSR1.RemoveResource(ChantSpeechResource.CSREvent, 0, 0, "")
    Next
End Sub

Private Sub NChantTTS1_HasEvent(ByVal sender As System.Object, ByVal e As HasEventArgs) Handles NChantTTS1.HasEvent
    Dim I As Integer
    Dim numberOfEvents As Integer
    Dim nChantTTSEvent As NChantTTSEvent
    ' Get the number of events
    numberOfEvents = NChantTTS1.GetResourceCount(ChantSpeechResource.CSREvent, 0, 0)
    For I = 0 To numberOfEvents - 1
        ' Get the event from the event queue
        nChantTTSEvent = NChantTTS1.GetChantTTSEvent(0)
        Select Case nChantTTSEvent.ChantCallback
            Case ChantCallback.CCDAudioStop
                ...
        End Select
        ' Remove the event from the event queue
        NChantTTS1.RemoveResource(ChantSpeechResource.CSREvent, 0, 0, "")
    Next
End Sub

Deployment Checklist

When you are ready to deploy your application, you need to ensure you have a valid license, bundle the correct Chant component libraries, and configure your installation properly on the target system. Review the following checklist before deploying your applications:

  • You may deploy your Silverlight application to any system with a valid license from the Chant.
  • Copy Chant.SpeechKit.Silverlight.dll and Chant.Shared.Silverlight.dll libraries to the target system or merge them with your application using an obfuscator like .NET Reactor by Eziriz.
  • Copy NSpeechKit.dll to the target system.
  • Register NSpeechKit.dll as a COM library on the target system.
  • You may deploy your Silverlight application to any system with a valid license from the Chant.
  • Copy Chant.SpeechKit.Silverlight.dll and Chant.Shared.Silverlight.dll libraries to the target system or merge them with your application using an obfuscator like .NET Reactor by Eziriz.
  • Copy NSpeechKitX64.dll to the target system.
  • Register NSpeechKitX64.dll as a COM library on the target system.

Sample Projects

Silverlight sample projects are installed at the following location:

  • My Documents\Chant SpeechKit 7\Win32\Silveright\VS 2010\CSharp and
  • My Documents\Chant SpeechKit 7\Win32\Silveright\VS 2010\Visual Basic.
  • My Documents\Chant SpeechKit 7\Win64\Silveright\VS 2010\CSharp and
  • My Documents\Chant SpeechKit 7\Win64\Silveright\VS 2010\Visual Basic.