September 96 - Adding Speech Recognition to an Application Framework
Adding Speech Recognition to an Application
Tim Monroe
It's easy to add speech recognition capabilities to an application
built with an object-oriented framework, with minimal disruption
to your existing code. To illustrate the process, this article shows
one way to add basic speech recognition capabilities to an
application built with PowerPlant, Metrowerks' popular C++-based
application framework. You can use the same strategy with other
application frameworks as well.
Speech recognition capabilities, such as those provided by Apple's Speech Recognition
Manager, promise to revolutionize the way people use computers. The reason for this
is simple: it's often a lot easier to say what you want done than to actually do it, even in
the "user-friendly" environment provided by the Macintosh graphical user interface.
So the time you spend making your application speakable is time very well spent.
Happily, if you've built your application with a framework such as PowerPlant or
MacApp, you can add basic speech recognition capabilities quickly and easily.
To show how to add speech recognition to an application built with a framework, we'll
modify the PowerPlant DocDemo sample provided with the CodeWarrior 8 release to
add speech support for the File menu commands. Of course, there's nothing special
about DocDemo: you should be able to drop the code we provide into any PowerPlant
application. Moreover, although this code is specific to PowerPlant, you should be able
to use similar techniques with other application frameworks as well.
Before reading this article, you should be familiar with the basic operations of the
Speech Recognition Manager and with the PowerPlant application framework. For an
overview of the Speech Recognition Manager, see the article "The Speech Recognition
Manager Revealed" in this issue of develop. As mentioned in that article, you'll find
everything you need to use the Speech Recognition Manager -- including detailed
documentation (written by yours truly) -- on this issue's CD and on
Apple's speech technology Web site. For basic information about PowerPlant, see The
PowerPlant Book or other Metrowerks documentation.
THE BASIC STRATEGY
We want to add speech support for the File menu commands in the DocDemo
application. This isn't the highest or best use of speech recognition capabilities (see
"Speakable Menus?"), but it makes a simple example for us to focus on. In a nutshell,
we'll define a custom C++ class and create a single instance of that class to handle all
the required speech recognition processing (such as installing a language model and
responding to recognition results sent to it via Apple events). Here are the steps we'll
follow:
• Add a few lines of code to the main application source code file,
CDocDemoApp.cp. In part, this code creates a single instance of our
• custom class CDocSpeech.
• Design a set of language models that describe the words and phrases we
• want to listen for.
• Add resources containing string representations of those words and
• phrases to the application's resource file.
• Write Apple event handlers for the two speech recognition events.
The following sections explain these steps in detail, though not strictly in this order.
All the code provided here is also included on this issue's CD.
______________________________
SPEAKABLE MENUS?
While it's fairly easy to make your application's menus speakable, this isn't
necessarily the best use of speech recognition technology and it's definitely not
what Apple's speech engineers would like to see you focus your attention on.
Most File and Edit menu commands are just too short to be easily distinguished
by the recognizer ("quit" sounds a lot like "cut," for example).