Use the following procedure to implement speech recognition in your application:

1.Identify an Audio Source (OPTIONAL): Use the AudioSource interface to enumerate and select an input audio device, as illustrated in Example 145.

Example 145: Select an Audio Source

 

N/A

// session is a PXCSession instance.

PXCAudioSource *source=session->CreateAudioSource();

 

// Scan and Enumerate audio devices

source->ScanDevices();

PXCAudioSource::DeviceInfo dinfo;

for (int d=source->QueryDeviceNum()-1;d>=0;d--) {

   source->QueryDeviceInfo(i, &dinfo);

 

   // Select one and break out of the loop

   ...

}

 

// Set the active device

source->SetDevice(&dinfo);

 

// session is a PXCMSession instance.

PXCMAudioSource source=session.CreateAudioSource();

 

// Scan and Enumerate audio devices

source.ScanDevices();

PXCMAudioSource.DeviceInfo dinfo;

for (int d=source.QueryDeviceNum()-1;d>=0;d--) {

   source.QueryDeviceInfo(i, out dinfo);

 

   // Select one and break out of the loop

   ...

}

 

// Set the active device

source.SetDevice(dinfo);

 

// session is a PXCMSession instance.

PXCMAudioSource source=session.CreateAudioSource();

 

// Scan and Enumerate audio devices

source.ScanDevices();

PXCMAudioSource.DeviceInfo dinfo=new PXCMAudioSource();

for (int d=source.QueryDeviceNum()-1;d>=0;d--) {

   source.QueryDeviceInfo(i, out dinfo);

 

   // Select one and break out of the loop

   ...

}

 

// Set the active device

source.SetDevice(dinfo);

 

// JavaScript does not support configuring AudioSource

 

tipThe SDK audio source supports reading from an audio file. The audio file can be in any system-supported audio formats, such as WAV, MP3, or WMV. Example 146 shows how to setup the audio source to read from an audio file.

Example 146: Select a File Audio Source

 

N/A

// session is a PXCSession instance.

PXCAudioSource *source=session->CreateAudioSource();

 

// Set the audio fie

PXCAudioSource::DeviceInfo dinfo={};

wcscpy_s<sizeof(dinfo.did)/sizeof(pxcCHAR)>(dinfo.did,L"my_audio_file.wav");

 

// Set the active device

source->SetDevice(&dinfo);

 

// session is a PXCMSession instance.

PXCMAudioSource source=session.CreateAudioSource();

 

// Set the audio fie

PXCMAudioSource.DeviceInfo dinfo=new PXCMAudioSource.DeviceInfo();

dinfo.did="my_audio_file.wav";

 

// Set the active device

source.SetDevice(dinfo);

 

// session is a PXCMSession instance.

PXCMAudioSource source=session.CreateAudioSource();

 

// Set the audio fie

PXCMAudioSource.DeviceInfo dinfo=new PXCMAudioSource.DeviceInfo();

dinfo.did="my_audio_file.wav";

 

// Set the active device

source.SetDevice(dinfo);

 

// JavaScript does not support file-based operations.

 

2.Locate the Module Implementation: Use the CreateImpl function (or the CreateInstance function) to create an instance of the PXCSpeechRecognition instance, as illustrated in Example 147.

Example 147: Create a Speech Recognition Instance

 

N/A

PXCSpeechRecognition *sr=0;

session->CreateImpl<PXCSpeechRecognition>(&sr);

 

PXCMSpeechRecognition sr;

session.CreateImpl<PXCMSpeechRecognition>(out sr);

 

PXCMSpeechRecognition sr=new PXCMSpeechRecognition();

session.CreateImpl(sr);

 

// namespace shortcut

var rss=intel.realsense.speech;

 

// sm is a SenseManager instance

rss.SpeechRecognition.createInstance(sm.session).then(function() {

   ....

});

 

3.Configure the Module: Get available configurations using the QueryProfile function and set the configuration using the SetProfile function. See Example 148.

Example 148: Initialize the Speech Recognition Module

 

N/A

PXCSpeechRecognition::ProfileInfo pinfo;

sr->QueryProfile(0,&pinfo);

pinfo.language=PXCSpeechRecognition::LANGUAGE_US_ENGLISH;

sr->SetProfile(&pinfo);

 

PXCMSpeechRecognition.ProfileInfo pinfo;

sr.QueryProfile(0,out pinfo);

pinfo.language=PXCMSpeechRecognition.LanguageType.LANGUAGE_US_ENGLISH;

sr.SetProfile(pinfo);

 

PXCMSpeechRecognition.ProfileInfo pinfo=new PXCMSpeechRecognition.ProfileInfo;

sr.QueryProfile(0, pinfo);

pinfo.language=PXCMSpeechRecognition.LanguageType.LANGUAGE_US_ENGLISH;

sr.SetProfile(pinfo);

 

// namespace shortcut

var rss=intel.realsense.speech;

 

// sr is a SpeechRecognition instance

 

// Retrieve all available profiles.

sr.queryProfiles().then(function(result) {

   var pinfo=result.profiles[0];

 

   // Set the language type

   pinfo.language=rss.LanguageType.LANGUAGE_US_ENGLISH;

   return sr.setProfile(pinfo);

}).then(function() {

   ....

});

 

tipAlways set the language. If not set, the default language is undetermined depending on what is currently installed on the platform.

4.Set the Recognition mode (OPTIONAL): See Command Control and Dictation on how to configure the speech recognition module to work in the command and control mode or in the dictation mode. By default, the module is set in the dictation mode.

Example 149: Set the Dictation Mode

 

N/A

sr->SetDictation();

 

sr.SetDictation();

 

sr.SetDictation();

 

// JavaScript supports command & control only.

 

5.Execution Flow: Start speech recognition using the StartRec function and stop with the StopRec function. The application receives events on any recognition activities. See Handle Recognition Events for details on setting up event handlers.

Example 150: Start/Stop Speech Recognition

 

N/A

// Start recognition

sr->StartRec(source, handler);

 

...

 

// Stop recognition

sr->StopRec();

 

// Start recognition

sr.StartRec(source, handler);

 

...

 

// Stop recognition

sr.StopRec();

 

// Start recognition

sr.StartRec(source, handler);

 

...

 

// Stop recognition

sr.StopRec();

 

// Start recognition

sr.startRec().then(function() {

  ....

});

 

...

 

// In other thread, stop recognition

sr.stopRec().then(function() {

  ....

});