How do I develop web applications that speak and listen?
Last reviewed: 7/15/2011
HOW Article ID: H071136
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.
Program Files\Chant\SpeechKit 7\Win64\Web\include.
Program Files\Chant\SpeechKit 7\WinCE\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>
<head>
<script type="text/vbscript" language="vbscript" src="chant.vb" />
...
</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.
<!-- IE 32 declaration -->
<object id="WChantAudio1" width="0" length="0"
classid="clsid:07DF3576-5FF1-4142-AC20-7500A7463FBF"
codebase="http://www.chant.net/speechkit/cabs/WSpeechKit7.cab">
</object>
<object id="WChantSR1" width="0" length="0"
classid="clsid:94A0354B-028F-4E2C-958E-199ECF8074BB"
codebase="http://www.chant.net/speechkit/cabs/WSpeechKit7.cab">
</object>
<object id="WChantTTS1" width="0" length="0"
classid="clsid:6BDF745D-A632-4580-AD5E-A1284C69097A"
codebase="http://www.chant.net/speechkit/cabs/WSpeechKit7.cab">
</object>
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. The 64-bit library declaration is only required when using 64-bit IE.
<!-- IE 64 declaration -->
<object id="WChantAudio1" width="0" length="0"
classid="clsid:488F8F56-6315-4735-9CF9-EB5F0B4A3DF3"
codebase="http://www.chant.net/speechkit/cabs/WSpeechKit7.cab">
</object>
<object id="WChantSR1" width="0" length="0"
classid="clsid:9710A724-C8A6-444F-83D0-A2FD2F3FA8A1"
codebase="http://www.chant.net/speechkit/cabs/WSpeechKit7.cab">
</object>
<object id="WChantTTS1" width="0" length="0"
classid="clsid:B047B205-E822-4FD5-90B2-9EA25DBF54A0"
codebase="http://www.chant.net/speechkit/cabs/WSpeechKit7.cab">
</object>
The ChantAudio, ChantSR, and ChantTTS components can be accessed via JavaScript code on a web page. Pocket IE browser does not support VBScript and does not cache the components automatically for the web page. The web component library must be installed on the device first.
<!-- Pocket IE declaration -->
<object id="WChantAudio1" width="0" length="0"
classid="clsid:844F13F0-8E3D-4829-ABDD-021F72D660C9">
</object>
<object id="WChantSR1" width="0" length="0"
classid="clsid:68239725-5745-4A18-B9D0-94828EBB3E1A">
</object>
<object id="WChantTTS1" width="0" length="0"
classid="clsid:3527BDED-0DA2-435D-B4AE-BC47AC1A2D86">
</object>
To install the web component library on the device, run the Program Files\Chant\SpeechKit 7\WinCE\spkwebsetup.exe or copy the Program Files\Chant\SpeechKit 7\WinCE\WSpeechKitWCEARM4.cab to the device and execute to install.
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>
<head>
<script type="text/vbscript" language="vbscript"> <!--
Sub onLoad
' Get the object instance (Win32 and Win64. VBScript not supported on WinCE)
Set ChantAudio = document.getElementById("WChantAudio1")
Set ChantSR = document.getElementById("WChantSR1")
Set ChantTTS = document.getElementById("WChantTTS1")
' Set license property
ChantAudio.SetStringProperty CSPSerials, "LicenseSerialNumber"
ChantSR.SetStringProperty CSPSerials, "LicenseSerialNumber"
ChantTTS.SetStringProperty CSPSerials, "LicenseSerialNumber"
End Sub
//-->
</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>
<script type="text/vbscript" language="vbscript" for="WChantAudio1" event="HasEvent"><!--
Set ChantAudio = document.getElementById("WChantAudio1")
' Get the number of events
numberOfEvents = ChantAudio.GetResourceCount(CSREvent)
For I = 0 To numberOfEvents-1
' Get the event from the event queue
Set wChantAudioEvent = ChantAudio.GetResource(CSREvent, 0)
' Process the type of callback event
Select Case wChantAudioEvent.ChantCallback
Case ChantCallback.CCDDeviceArrival
...
Case Else
End Select
' Remove the event from the event queue
ChantAudio.RemoveResource CSREvent, 0
Next
//-->
</script>
<script type="text/vbscript" language="vbscript" for="WChantSR1" event="HasEvent"><!--
Set ChantSR = document.getElementById("WChantSR1")
' Get the number of events
numberOfEvents = ChantSR.GetResourceCount(CSREvent)
For I = 0 To numberOfEvents-1
' Get the event from the event queue
Set wChantSREvent = ChantSR.GetResource(CSREvent, 0)
' Process the type of callback event
Select Case wChantSREvent.ChantCallback
Case ChantCallback.CCSRHasCommand
...
Case Else
End Select
' Remove the event from the event queue
ChantSR.RemoveResource CSREvent, 0
Next
//-->
</script>
<script type="text/vbscript" language="vbscript" for="WChantTTS1" event="HasEvent"><!--
Set ChantTTS = document.getElementById("WChantTTS1")
' Get the number of events
numberOfEvents = ChantTTS.GetResourceCount(CSREvent)
For I = 0 To numberOfEvents-1
' Get the event from the event queue
Set wChantTTSEvent = ChantTTS.GetResource(CSREvent, 0)
' Process the type of callback event
Select Case wChantTTSEvent.ChantCallback
Case ChantCallback.CCDAudioStop
...
Case Else
End Select
' Remove the event from the event queue
ChantTTS.RemoveResource CSREvent, 0
Next
//-->
</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.
- My Documents\Chant SpeechKit 7\Win64\Web\JavaScript.
- My Documents\Chant SpeechKit 7\WinCE\Web\JavaScript.