home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Sound / Speech Recognition sample / _source / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-15  |  2.0 KB  |  102 lines  |  [TEXT/CWIE]

  1. #ifndef __MAIN__
  2. #include "main.h"
  3. #endif
  4.  
  5. //Globals
  6.     Boolean                gDone            = false;
  7.     SpeechChannel        theSpeechChan    = nil;
  8.  
  9. void main (void)
  10. {
  11.     SpeechInfoStruct    theSpeechInfo;
  12.     EventRecord            event;
  13.     OSErr                theErr            = noErr;
  14.     Boolean                gotEvent        = false;
  15.  
  16.     ToolBoxInit ();
  17.  
  18.     theErr = SpeakWelcome ();
  19.     if (theErr == noErr) {
  20.         theErr = ListenToUser (&theSpeechInfo);
  21.     }
  22.  
  23.     while (theErr == noErr && (gDone == false || SpeechBusy() != 0)) {    //Don't quit if we're talking to you
  24.         gotEvent = WaitNextEvent (everyEvent, &event, 6, nil);
  25.         if (gotEvent) {
  26.             switch (event.what)
  27.             {
  28.                 case keyDown:
  29.                     gDone = true;    //want to be able to quit if speech recognition isn't working
  30.                     break;
  31.                 case kHighLevelEvent :
  32.                     AEProcessAppleEvent (&event);    //Handle speech recognition events
  33.                     break;
  34.                 case mouseUp:
  35.                 case mouseDown:
  36.                 case keyUp:
  37.                 case autoKey:
  38.                 case updateEvt:
  39.                 case diskEvt:
  40.                 case activateEvt:
  41.                 case osEvt:
  42.                     break;
  43.             }
  44.         }
  45.     }
  46.  
  47.     theErr = SRCloseRecognitionSystem (theSpeechInfo.recogSystem);
  48. }
  49.  
  50. OSErr        SpeakWelcome        (void)
  51. {
  52.     OSErr                theErr            = noErr;
  53.  
  54.     theErr = GetNewSpeechChan (&theSpeechChan);        //Set up a global speech channel
  55.  
  56.     return theErr;
  57. }
  58.  
  59. OSErr        ListenToUser        (SpeechInfoPtr theSpeechInfo)
  60. {
  61.     OSErr                theErr            = noErr;
  62.  
  63.     theSpeechInfo->ID                = 'myID';
  64.     theSpeechInfo->recogSystem        = 0;
  65.     theSpeechInfo->theRecognizer    = 0;
  66.     theSpeechInfo->languages        = nil;
  67.     theSpeechInfo->SpeechDoneUPP    = nil;
  68.     theSpeechInfo->attributes        = 0;
  69.  
  70.     theErr = InitSpeechRecognition (theSpeechInfo);
  71.  
  72.     if (theErr == noErr) {
  73.         theErr = OpenSpeechRecognition (theSpeechInfo);
  74.     }
  75.  
  76.     if (theErr == noErr) {
  77.         theErr = ConfigureRecognition (theSpeechInfo);
  78.     }
  79.  
  80.     if (theErr == noErr) {
  81.         theErr = GetNewRecognizer (theSpeechInfo);
  82.     }
  83.  
  84.     if (theErr == noErr) {
  85.         theErr = SetSpeechDoneAEHander (theSpeechInfo);
  86.     }
  87.  
  88.     if (theErr == noErr) {
  89.         theErr = InstallRecogAEHandler (theSpeechInfo);
  90.     }
  91.  
  92.     if (theErr == noErr) {
  93.         theErr = MakeNewLanguage (theSpeechInfo);
  94.     }
  95.  
  96.     if (theErr == noErr) {
  97.         theErr = SRStartListening (theSpeechInfo->theRecognizer);
  98.     }
  99.  
  100.     return theErr;
  101. }
  102.