How do I develop Universal Windows Platform (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;
        

Imports Chant.SpeechKit.WindowsMedia
Imports Chant.Shared.WindowsMedia
Public NotInheritable Class MainPage
...

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();
}
        

Public NotInheritable Class MainPage
    Inherits Page
    Dim WithEvents NChantSR1 As NChantSR
    Public Sub New()
        Me.InitializeComponent()
        ' Instantiate NChantSR object
        NChantSR1 = New NChantSR()
        ' 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
        Dim nChantCommandVocab As 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()
    End Sub
End Class

Private Sub NChantSR1_HasEvent(ByVal sender As System.Object, ByVal e As HasEventArgs) Handles NChantSR1.HasEvent
    Dim nChantSREvent As NChantSREvent
    ' Get the event from the event queue
    nChantSREvent = NChantSR1.GetChantSREvent()
    Select Case nChantSREvent.ChantCallback
        Case ChantCallback.CCSRHasCommand
            ' Handle command
            ...
    End Select
    ' Remove the event from the event queue
    NChantSR1.RemoveEvent()
End Sub

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");
}
        

Public NotInheritable Class MainPage
    Inherits Page
    Dim WithEvents NChantTTS1 As NChantTTS
    Public Sub New()
        Me.InitializeComponent()
        ' Instantiate NChantTTS object
        NChantTTS1 = New NChantTTS()
        ' 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")
    End Sub
End Class