Talking Web Clients with JavaScript and the Speech API Wisconsin

See how to make your web clients read or play content to its users. You will experiment with JavaScript from the command line, learn a JavaScript debugging technique that might be useful, and see how to load the Speech API and ask it to read the ALT (text) attribute of HTML controls.

Local Companies

R S InfoCon, Inc.
262-898-7456
2320 Renaissance Blvd
Sturtevant, WI
Acumium
608 310 9700 x 522
5133 West Terrace Drive Suite 300
Madison, , WI
Visionary Computer Solutions
262-365-9430
PO Box 406
Grafton, WI
Wireless Direct
1.866.707.8498
BOX 71101
shorewood, WI
R.E. Coker and Associates, Inc.
262-723-8104
108 W Court St.
Elkhorn, WI
IFS
414-577-5191
12000 W. Park Place
Milwaukee, WI
Electroniclaim
262-240-9700
11357 N. Port Washington Rd
Mequon, WI
HarrisData
800-225-0585
13555 Bishops Court
Brookfield, WI
Xorbix Technologies Inc.
414-277-5044
759 N. Milwaukee St.
Milwaukee, WI
HarrisData
262-784-9099
13555 Bishop's Court, Suite 300
Brookfield, WI

Talking Web Clients with JavaScript and the Speech API

provided by: 
Originally published at Internet.com


Introduction

I was surfing the web and saw the announcement of Microsoft Surface. Surface right now is a tabletop Windows Vista machine with cameras pointing out, no keyboard, and no mouse. Interactions are done with the surface of the device. Combined with the cameras and Bluetooth capabilities, Surface interacts with objects in the real world. For example, lay an enabled cell phone on the device and Surface downloads your pictures or possibly synchronizes your phone contacts with your Outlook contacts. I can't do the device justice here; it's one of those things you will have to see to believe (www.microsoft.com/surface). It's worth seeing.

I was so intrigued with a device that interacts naturally with the physical world that I became interested in the day-to-day possibilities of a more natural interaction with computing devices (as well as interested in writing a book about Surface. Hint: Microsoft, send me a Surface machine, for research purposes of course). Consequently, this article is an off-shoot of that interest.

This article demonstrates how to make your web clients read some or play some of the text content to the users. I am aware of accessibility tags and HTML, but as a programmer how could capabilities like audio-text be used for routine development purposes: first, making debug and trace information audible, and permitting everyday end-users to hear content. And, I will admit it's fun too. In this article, you will get to experiment with JavaScript from the command line, learn a JavaScript debugging technique that might be useful, and how to load the Speech API and ask it to read the ALT (text) attribute of HTML controls.

Even if you aren't that interested in new computing techniques or speech, you will find the JavaScript techniques helpful.

Running JavaScript from the Command Line

JavaScript can be used for more than snappy web clients and as part of the plumbing that makes Ajax work. (And, Ajax is a very cool capability of web programming.) JavaScript can be run from the command line to perform routine tasks.

If you create a .js file and click in Explorer or type the file name from the command line (cmd.exe), the Windows Scripting Host (WScript.exe) will run the JavaScript like a program. Try this example: 1. Open Explorer. 2. Create a new text file and name it Hello.js. 3. Type: WScript.Echo("Microsoft Surface is cool!"). 4. Save the file and double-click it in Explorer.

The WScript host will execute the script and display a standard message box containing the text. Listing 1 demonstrates JavaScript that will create a desktop URL shortcut (to Microsoft's Popfly—Code mashup tool). (Figure 1 shows a Mashup sample I created on Popfly, which is based on Microsoft's Silverlight technology.)

Listing 1: JavaScript that creates a desktop shortcut to Microsoft's Popfly. var shell = WScript.CreateObject("WScript.Shell"); var desktop = shell.SpecialFolders("Desktop"); var url = shell.CreateShortcut(desktop + "\\Popfly.url"); url.TargetPath = "http://www.popfly.ms"; url.Save(); WScript.Echo("Shortcut added to Popfly");



Click here for a larger image.

Figure 1: My FlickringVirtualEarth Mashup that shows the location of pictures from Flickr on VirtualEarth.

Adding Speech to a Web Client

You can use the Speech API with just a few lines of code. You will need to create an ActiveXObject passing the name of the Speech API component, SAPI.SpVoice. (You can download the Speech API for free, if it's not installed on your computer already. Check oout http://msdn2.microsoft.com/en-us/library/ms723627.aspx.) Next, you can pick a voice, and optionally set the speech rate and volume. Finally, send the text you'd like to be spoken (see Listing 2). Note: Other browsers may not support ActiveX objects, but this technique works great on the most popular browser, IE.

Listing 2 The bare bones code it takes to read some hard coded text. var voice = new ActiveXObject("SAPI.SpVoice"); voice.Speak("Microsoft Surface is cool!");

You can select from available voices and modulate the rate and volume with code like that shown in Listing 3. The rate can be from 1—slow—to 10—very fast; the volume can be from 0 to 100, which is the loudest; and the voice selected has to be an installed voice.

Listing 3: Speech script that sets the rate of speech, volume, and picks from an available voice. var voices = voice.GetVoices(); v ar len = voices.count; WScript.Echo("Length: " + len ); WScript.Echo("Voice: " + voices(1).GetDescription() ); if(len >= 2) voice.Voice = voices(1); voice.Rate = 1; voice.Volume = 75; voice.Speak("Microsoft PopFly is cool too!");

The code above gets the array of available voices. The number is retrieved and displayed and a description of voice at index 1 is displayed. On my machine, I have three voices and the voice at index 1 is LH Michelle. The speech rate is set to 1 (slow) and the volume is set to about ¾'s of the maximum volume.

Listing 4 combines the elements you have seen so far with some new features. I have introduced the debugger keyword that causes the debugger to break precisely at that line, making it easier to target specific code for debugging. I have also introduced a try..catch block and some cleanup code (see Listing 4).



Click here for a larger image.

Figure 2: By adding a debugger statement to your code, you will be prompted to select a debugger (usually Visual Studio or Microsoft Script Editor (shown)) and execution will be suspended at the debugger statement.

Listing 4: Speech capability bound to the onclick event of an control. (The numbering is for reference only.) 1: 2: 3: Talking Page 4: 34: 37: 38: 39: 40:

41: Paul's Number is (555) 555-1212 extension 3333

Author: Paul Kimmel

Read article at Internet.com site

Featured Local Company

HarrisData

262-784-9099
13555 Bishop's Court, Suite 300
Brookfield, WI
http://www.HarrisData.com

Regional Articles
- Talking Web Clients with JavaScript and the Speech API Appleton WI
- Talking Web Clients with JavaScript and the Speech API Baraboo WI
- Talking Web Clients with JavaScript and the Speech API Beaver Dam WI
- Talking Web Clients with JavaScript and the Speech API Beloit WI
- Talking Web Clients with JavaScript and the Speech API Brookfield WI
- Talking Web Clients with JavaScript and the Speech API Burlington WI
- Talking Web Clients with JavaScript and the Speech API Cedarburg WI
- Talking Web Clients with JavaScript and the Speech API Chippewa Falls WI
- Talking Web Clients with JavaScript and the Speech API Cudahy WI
- Talking Web Clients with JavaScript and the Speech API De Pere WI
- Talking Web Clients with JavaScript and the Speech API Delavan WI
- Talking Web Clients with JavaScript and the Speech API Eau Claire WI
- Talking Web Clients with JavaScript and the Speech API Elkhorn WI
- Talking Web Clients with JavaScript and the Speech API Fond Du Lac WI
- Talking Web Clients with JavaScript and the Speech API Fort Atkinson WI
- Talking Web Clients with JavaScript and the Speech API Franklin WI
- Talking Web Clients with JavaScript and the Speech API Green Bay WI
- Talking Web Clients with JavaScript and the Speech API Hartland WI
- Talking Web Clients with JavaScript and the Speech API Janesville WI
- Talking Web Clients with JavaScript and the Speech API Kaukauna WI
- Talking Web Clients with JavaScript and the Speech API Kenosha WI
- Talking Web Clients with JavaScript and the Speech API La Crosse WI
- Talking Web Clients with JavaScript and the Speech API Lake Geneva WI
- Talking Web Clients with JavaScript and the Speech API Manitowoc WI
- Talking Web Clients with JavaScript and the Speech API Marinette WI
- Talking Web Clients with JavaScript and the Speech API Marshfield WI
- Talking Web Clients with JavaScript and the Speech API Menasha WI
- Talking Web Clients with JavaScript and the Speech API Menomonee Falls WI
- Talking Web Clients with JavaScript and the Speech API Menomonie WI
- Talking Web Clients with JavaScript and the Speech API Merrill WI
- Talking Web Clients with JavaScript and the Speech API Middleton WI
- Talking Web Clients with JavaScript and the Speech API Milwaukee WI
- Talking Web Clients with JavaScript and the Speech API Mosinee WI
- Talking Web Clients with JavaScript and the Speech API Mukwonago WI
- Talking Web Clients with JavaScript and the Speech API Muskego WI
- Talking Web Clients with JavaScript and the Speech API Neenah WI
- Talking Web Clients with JavaScript and the Speech API New Berlin WI
- Talking Web Clients with JavaScript and the Speech API Oak Creek WI
- Talking Web Clients with JavaScript and the Speech API Oconomowoc WI
- Talking Web Clients with JavaScript and the Speech API Onalaska WI
- Talking Web Clients with JavaScript and the Speech API Oshkosh WI
- Talking Web Clients with JavaScript and the Speech API Pewaukee WI
- Talking Web Clients with JavaScript and the Speech API Racine WI
- Talking Web Clients with JavaScript and the Speech API Rhinelander WI
- Talking Web Clients with JavaScript and the Speech API Rice Lake WI
- Talking Web Clients with JavaScript and the Speech API River Falls WI
- Talking Web Clients with JavaScript and the Speech API Schofield WI
- Talking Web Clients with JavaScript and the Speech API Shawano WI
- Talking Web Clients with JavaScript and the Speech API Sheboygan WI
- Talking Web Clients with JavaScript and the Speech API South Milwaukee WI
- Talking Web Clients with JavaScript and the Speech API Stevens Point WI
- Talking Web Clients with JavaScript and the Speech API Sturgeon Bay WI
- Talking Web Clients with JavaScript and the Speech API Sun Prairie WI
- Talking Web Clients with JavaScript and the Speech API Superior WI
- Talking Web Clients with JavaScript and the Speech API Thiensville WI
- Talking Web Clients with JavaScript and the Speech API Two Rivers WI
- Talking Web Clients with JavaScript and the Speech API Watertown WI
- Talking Web Clients with JavaScript and the Speech API Waukesha WI
- Talking Web Clients with JavaScript and the Speech API Waupaca WI
- Talking Web Clients with JavaScript and the Speech API Wausau WI
- Talking Web Clients with JavaScript and the Speech API West Bend WI
- Talking Web Clients with JavaScript and the Speech API Whitewater WI
- Talking Web Clients with JavaScript and the Speech API Wisconsin Rapids WI
Related Local Events
2008 Early Stage Symposium
Dates: 11/5/2008 - 11/6/2008
Location: Monona Terrace
Madison WI
View Details

Wisconsin Entrepreneurs' Conference
Dates: 6/9/2008 - 6/10/2008
Location: Hyatt Regency Hotel
Milwaukee WI
View Details
Rate Article
     
Articles Insider

Rss   Delicious   Digg   Add To My Yahoo   Add To My Google   Bookmark   Search Plugin

Topics:
Advertising Engineering Home Services Retail & Consumer Services
Business Services Entertainment Industrial Goods & Services Software
Career Family Insurance Technology
Cars Financial Services Internet Telecommunications
Computer Hardware Food & Beverage Legal Transportation & Logistics
Construction Health Pets Travel
Education Home Electronics Real Estate Wedding