Developing UWP applications that speak and listen

Last reviewed: 11/1/2016

HOW Article ID: H111601

The information in this article applies to:

  • SpeechKit 8

Summary

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

More Information

The following sections describe the steps for integrating SpeechKit with .NET UWP applications.

SpeechKit Assemblies

SpeechKit includes UWP compatible .NET assemblies compiled with .NET Framework V4 and native compiler V5 to support your application's target framework.

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

  1. Within your .NET project, right click on the References node in the Solution Explorer.
  2. Add references to the Chant shared and SpeechKit .NET assemblies:
    1. Program Files\Chant\SpeechKit 8\UWP\lib\Chant.SpeechKit.WindowsMedia.dll and
    2. Program Files\Chant\SpeechKit 8\UWP\lib\libv4\Chant.Shared.WindowsMedia.dll.

To access the SpeechKit .NET classes within your application, add references to the Chant shared and SpeechKit assemblies in your code.


using System;
...
using Chant.SpeechKit.WindowsMedia;
using Chant.Shared.WindowsMedia;

Speech Recognition

The following example illustrates using a command vocabulary.


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

    // Register for command recognition event
    NChantSR1.RegisterCallback(ChantCallback.CCSRHasCommand);

    // Define the vocabulary
    NChantCommandVocab nChantCommandVocab = nChantSR.CreateChantCommandVocab("commands");

    // Add commands to the vocabulary
    nChantCommandVocab.AddCommand("Open File");
    nChantCommandVocab.AddCommand("Print File");
    nChantCommandVocab.AddCommand("Close File");
    
    // Enable the vocabulary
    nChantCommandVocab.Enable();
}

private void NChantSR1_HasEvent(object sender, HasEventArgs e)
{
    // Get the event from the event queue
    NChantSREvent nChantSREvent = NChantSR1.GetChantSREvent();
    switch (nChantSREvent.ChantCallback)
    {
        case ChantCallback.CCSRHasCommand:
            {
                // Handle command
                ...
                break;
            }
        default:
            break;
    }
    // Remove the event from the event queue
    NChantSR1.RemoveEvent();
}

Speech Synthesis

The following examples illustrate using the StartPlayback method to synthesize speech and playback audio.


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

    // Synthesize text to speech
    NChantTTS1.StartPlayback("Hello world.");

    // Playback a wave file
    NChantTTS1.StartPlayback("myinaudiofile.wav");

    // Synthesize a file of text to speech
    NChantTTS1.StartPlayback("mytextfile.txt");
}