How do I develop Microsoft HoloLens apps that speak and listen?

Last reviewed: 2/1/2017

HOW Article ID: H021701

The information in this article applies to:

  • SpeechKit 8

Summary

You can develop Microsoft HoloLens applications that speak and listen with SpeechKit.

More Information

The following sections describe the steps for integrating SpeechKit with Microsoft HoloLens applications.

SpeechKit Assemblies

SpeechKit includes UWP compatible .NET assemblies.

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

Dim WithEvents NChantSR1 As NChantSR
...
    ' 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()
...

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;
...
// 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.");
...
        

Dim WithEvents NChantTTS1 As NChantTTS
...
    ' 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.")
...