Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
main.c
/* |
File: main.c |
Contains: |
Written by: |
Copyright: Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved. |
You may incorporate this Apple sample source code into your program(s) without |
restriction. This Apple sample source code has been provided "AS IS" and the |
responsibility for its operation is yours. You are not permitted to redistribute |
this Apple sample source code as "Apple sample source code" after having made |
changes. If you're going to re-distribute the source, we require that you make |
it clear in the source that the code was descended from Apple sample source |
code, but that you've made changes. |
Change History (most recent first): |
8/2/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 |
*/ |
#ifndef __MAIN__ |
#include "main.h" |
#endif |
//Globals |
Boolean gDone = false; |
SpeechChannel theSpeechChan = nil; |
void main (void) |
{ |
SpeechInfoStruct theSpeechInfo; |
EventRecord event; |
OSErr theErr = noErr; |
Boolean gotEvent = false; |
ToolBoxInit (); |
theErr = SpeakWelcome (); |
if (theErr == noErr) { |
theErr = ListenToUser (&theSpeechInfo); |
} |
while (theErr == noErr && (gDone == false || SpeechBusy() != 0)) { //Don't quit if we're talking to you |
gotEvent = WaitNextEvent (everyEvent, &event, 6, nil); |
if (gotEvent) { |
switch (event.what) |
{ |
case keyDown: |
gDone = true; //want to be able to quit if speech recognition isn't working |
break; |
case kHighLevelEvent : |
AEProcessAppleEvent (&event); //Handle speech recognition events |
break; |
case mouseUp: |
case mouseDown: |
case keyUp: |
case autoKey: |
case updateEvt: |
case diskEvt: |
case activateEvt: |
case osEvt: |
break; |
} |
} |
} |
theErr = SRCloseRecognitionSystem (theSpeechInfo.recogSystem); |
} |
OSErr SpeakWelcome (void) |
{ |
OSErr theErr = noErr; |
theErr = GetNewSpeechChan (&theSpeechChan); //Set up a global speech channel |
return theErr; |
} |
OSErr ListenToUser (SpeechInfoPtr theSpeechInfo) |
{ |
OSErr theErr = noErr; |
theSpeechInfo->ID = 'myID'; |
theSpeechInfo->recogSystem = 0; |
theSpeechInfo->theRecognizer = 0; |
theSpeechInfo->languages = nil; |
theSpeechInfo->SpeechDoneUPP = nil; |
theSpeechInfo->attributes = 0; |
theErr = InitSpeechRecognition (theSpeechInfo); |
if (theErr == noErr) { |
theErr = OpenSpeechRecognition (theSpeechInfo); |
} |
if (theErr == noErr) { |
theErr = ConfigureRecognition (theSpeechInfo); |
} |
if (theErr == noErr) { |
theErr = GetNewRecognizer (theSpeechInfo); |
} |
if (theErr == noErr) { |
theErr = SetSpeechDoneAEHander (theSpeechInfo); |
} |
if (theErr == noErr) { |
theErr = InstallRecogAEHandler (theSpeechInfo); |
} |
if (theErr == noErr) { |
theErr = MakeNewLanguage (theSpeechInfo); |
} |
if (theErr == noErr) { |
theErr = SRStartListening (theSpeechInfo->theRecognizer); |
} |
return theErr; |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-03-14