How Tos
Last reviewed: 7/15/2011
Article ID: H071136
HOW: Developing Web applications that speak and listen
The information in this article applies to:
- SpeechKit 7
Summary
You can develop web applications that speak and listen using your favorite JavaScript and VBScript development tools.
More Information
SpeechKit class methods require enumeration constant values for some of the parameters. These constants are pre-defined in files chant.js and chant.vb. Copy the applicable file to the same folder as your web page from the following installation folder:
Program Files\Chant\SpeechKit 7\Win32\Web\include.
Access the constant values on your web page by including a reference to the file on your web page.
<head> <script type="text/javascript" language="JavaScript" src="chant.js" /> ... </head> <body onload="onLoad()"> ... </body>
Object Declaration
Chant SpeechKit includes a Web component library that can be accessed via script code on a web page.
The ChantAudio, ChantSR, and ChantTTS components can be accessed via JavaScript and VBScript code on a web page. The IE browser caches the components automatically for the web page.
Object Instantiation
The ChantAudio, ChantSR, and ChantTTS class objects are automatically instantiated when the web page loads. Access the instance of the object from the document object. Set the CSPSerials property with your SpeechKit license serial number to unlock the component library for this web page. Even though you access the object instance from as many functions as your application needs, you only need to set the CSPLicense once on page load.
<head> <script type="text/javascript" language="JavaScript"><!-- function onLoad() { // Get the object instance (Win32 and Win64) var ChantAudio = document.getElementById('WChantAudio1'); // Get the object instance (WinCE) var ChantAudio = document.all['WChantAudio1']; // Get the object instance (Win32 and Win64) var ChantSR = document.getElementById('WChantSR1'); // Get the object instance (WinCE) var ChantSR = document.all['WChantSR1']; // Get the object instance (Win32 and Win64) var ChantTTS = document.getElementById('WChantTTS1'); // Get the object instance (WinCE) var ChantTTS = document.all['WChantTTS1']; // Set license property ChantAudio.SetStringProperty(CSPSerials,"LicenseSerialNumber"); ChantSR.SetStringProperty(CSPSerials,"LicenseSerialNumber"); ChantTTS.SetStringProperty(CSPSerials,"LicenseSerialNumber"); ... } //--> </script> </head> <body onload="onLoad()"> ... </body>
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.
<script type="text/javascript" language="JavaScript" for="WChantAudio1" event="HasEvent"><!-- var wChantAudioEvent; var ChantAudio = document.getElementById('WChantAudio1'); // Get the number of events numberOfEvents = ChantAudio.GetResourceCount(CSREvent); for (i = 0; i < numberOfEvents; i++) { // Get the event from the event queue wChantAudioEvent = ChantAudio.GetResource(CSREvent, 0); switch (wChantAudioEvent.ChantCallback) { case ChantCallback.CCDDeviceArrival: { ... } default: break; } // Remove the event from the event queue ChantAudio.RemoveResource(CSREvent, 0, 0, ""); } //--> </script> <script type="text/javascript" language="JavaScript" for="WChantSR1" event="HasEvent"><!-- var wChantSREvent; var ChantSR = document.getElementById('WChantSR1'); // Get the number of events numberOfEvents = ChantSR.GetResourceCount(CSREvent); for (i = 0; i < numberOfEvents; i++) { // Get the event from the event queue wChantSREvent = ChantSR.GetResource(CSREvent, 0); switch (wChantSREvent.ChantCallback) { case ChantCallback.CCSRHasCommand: { ... } default: break; } // Remove the event from the event queue ChantSR.RemoveResource(CSREvent, 0, 0, ""); } //--> </script> <script type="text/javascript" language="JavaScript" for="WChantTTS1" event="HasEvent"><!-- var wChantTTSEvent; var ChantTTS = document.getElementById('WChantTTS1'); // Get the number of events numberOfEvents = ChantTTS.GetResourceCount(CSREvent); for (i = 0; i < numberOfEvents; i++) { // Get the event from the event queue wChantTTSEvent = ChantTTS.GetResource(CSREvent, 0); switch (wChantTTSEvent.ChantCallback) { case ChantCallback.CCDAudioStop: { ... } default: break; } // Remove the event from the event queue ChantTTS.RemoveResource(CSREvent, 0, 0, ""); } //--> </script>
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 web page to any domain with a valid license from the Chant.
- Update the codebase tag in the <object> declaration with location of the SpeechKit cab file. This can be the Chant web location or the URL of that location on your website where you copy the licensed cab file.
Sample Projects
Web sample projects are installed at the following location:
- My Documents\Chant SpeechKit 7\Win32\Web\JavaScript.