MacDevCenter    
 Published on MacDevCenter (http://www.macdevcenter.com/)
 See this if you're having trouble printing code examples


Mac Technologies Enabled for Java

by Daniel H. Steinberg
05/24/2001

For more than a year now, Apple has hammered the message of wanting to make Mac OS X the premier desktop for running Java applications.

In general, that seemed to mean that apps would look prettier when running with the Aqua look-and-feel, and that performance would be a priority -- both of those are laudable goals. Now the Apple engineers have opened up a whole new range of possibilities by wrapping some of the Mac OS X APIs into JavaBeans. We've seen Apple Java-enable their technologies before, but this is different. Take a core service and provide Java hooks to it, and developers can now easily add speech synthesis and recognition, or spell-checking to their applications.

The Java Speech Framework

Steve Lewallen, senior engineer at Apple, demonstrated these APIs at a late afternoon session Tuesday at the WWDC 2001. The Java Speech Framework is built on top of the Synthesis and Recognition components that sit on top of Carbon.

To convert Java Strings to speech, use the Synthesizer and Voice classes in the com.apple.speech.synthesis package. The Voice class gives you access to all the built-in Mac OS X voices and allows you to modify their properties. You can listen for errors as well as when the speech has started, stopped, or is done.

Other Synthesizer events allow you to synch on a particular word. This would allow, for example, you to synchronize a slide show with an audio presentation. You can also get callbacks at the end of words and phonemes. The phoneme callbacks could allow you to animate a face that appears to be speaking the words.

There is flexibility for changing the way specific parts are read. This could be used for emphasis or to change the way, for example, that a number is read. In the demo, Lewallen had the reader read a phone number and extension. Although what was on the screen was read correctly, we wouldn't read extension 5678 as "five thousand six hundred seventy eight". Lewallen added a tag before and after the extension and the extension was read as a human would.

Comment on this articleApple seems very serious about empowering the Java Framework for Mac OS X. Do you think its commitment will translate into more Java developers working on Mac OS X?
Post your comments

More Apple Worldwide Developers Conference Coverage:

Jobs to Developers: 'A Problem or an Opportunity?'

Cocoa Vs. Carbon?

Java Plays Prominent Role at WWDC 2001

Java Speech recognition recognizes spoken language contained in a language model. The tool for defining a language model isn't quite ready yet and, unfortunately, uses some conventions that are artifacts of an older OS. The Recognizer and LanguageModel classes are in the com.apple.speech.recognition package. The recognizer can fire events that indicate if the spoken input is unrecognized, detected, or done.

Check your spelling

The Java Spelling Framework allows you to include the ability to have spelling checked on the fly or by command. You can use the APIs to check spelling, suggest corrections, and even modify the System directory so that all applications will get an addition to the dictionary.

Because all Swing text widgets derive from JTextComponent, you get easy integration of the spell-checker with all of your text components. The SpellingChecker, MisspelledWord, and Word classes are in the com.apple.spell package. It took a couple of lines of code to add spell-checking to an application.

Lewallen instantiated a JTextComponentDriver and then used the method checkSpelling() with the name of the text component as the argument. The JTextComponentDriver, SpellingPanel, and Driver are in the com.apple.spell.ui package.

Having these components accessible as beans means that you can use an IDE such as JBuilder to easily add this functionality to your application and edit the properties. You could add Speech Synthesis with a couple of mouse clicks and choose a particular voice. As for Java access to future technologies, Apple says that this may or may not be done via JavaBeans. That decision will depend on the technology being delivered.

Daniel H. Steinberg is the editor for the new series of Mac Developer titles for the Pragmatic Programmers. He writes feature articles for Apple's ADC web site and is a regular contributor to Mac Devcenter. He has presented at Apple's Worldwide Developer Conference, MacWorld, MacHack and other Mac developer conferences.


Return to the Mac DevCenter.

Copyright © 2009 O'Reilly Media, Inc.