home *** CD-ROM | disk | FTP | other *** search
- 18-Jun-88 14:25:58-MDT,7401;000000000000
- Return-Path: <u-lchoqu%sunset@cs.utah.edu>
- Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:25:48 MDT
- Received: by cs.utah.edu (5.54/utah-2.0-cs)
- id AA22101; Sat, 18 Jun 88 14:25:44 MDT
- Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
- id AA24518; Sat, 18 Jun 88 14:25:41 MDT
- Date: Sat, 18 Jun 88 14:25:41 MDT
- From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
- Message-Id: <8806182025.AA24518@sunset.utah.edu>
- To: rthum@simtel20.arpa
- Subject: Cheaptalk.c
-
- /******************************************************************
-
- Cheaptalk.c
-
- TOM PHILLIPS 6-27-86
- 1633 Commonwealth Ave.
- West Newton, MA 02165
- (617) 332-1373
-
- This is a translation of Dan Weston's
- Cheaptalk demo application from
- assembly to LightspeedC. His original
- program was published in Mactutor, November 1985.
- (This was done on a Mac Plus and HD20)
-
- Instructions for getting this code to compile
- and run with LightspeedC:
-
- 1) you must have the MacinTalk driver
- and SpeechAsm.Rel files. Both are available in
- the May 1985 Software Supplement from Apple.
- They are also available on MacTutor's source
- code disk #4. They are also be available on Delphi.
- The MacinTalk driver must be in the same HFS
- folder as your project.
-
- 2) Convert SpeechAsm.Rel to SpeechAsm.Lib with
- LightspeedC's RelConv utility.
-
- 3) Edit SpeechAsm.Voc (which was created by RelConv)
- so that the capitalization corresponds to
- the following: SpeechOn, MacinTalk, Reader, SpeechOff.
-
- 4) Re-convert SpeechAsm.Rel to SpeechAsm.Lib with
- RelConv so that new capitalization will occur
- in the Lib file.
-
- 5) Create a resouce file called Cheaptalk.Rsrc
- from Cheaptalk's resources (DLOG DITL and PHNM)
- using ResEdit.
-
- 6) Load Cheaptalk.c into project with MacTraps
- and SpeechAsm.Lib.
-
- 7) Run it.
-
- **************************************************************/
- #include "QuickDraw.h"
- #include "WindowMgr.h"
- #include "DialogMgr.h"
- /*************************************************************/
-
- extern pascal SpeechOn(); /* these MacinTalk calls must */
- extern pascal MacinTalk(); /* be declared as pascal type */
- extern pascal Reader(); /* so that the parameters are pushed */
- extern pascal SpeechOff(); /* on the stack in the right order */
-
- #define theDialog 1 /* resource ID # of dialog */
- #define sayitbutton 1 /* item # for 'say it ' */
- #define quitbutton 2 /* item # for 'quit' */
- #define usertext 3 /* item # for edit text box */
-
- /********************* Global Variables **********************/
-
- long theSpeech; /* handle to speech driver globals */
- short speechOK; /* our flag to show if driver open */
- char theString[256]; /* array for GetIText and Reader */
- Handle phHandle; /* handle to phonetic string */
- WindowPtr dp; /* dialog pointer */
- short Result; /* error code */
- long length; /* used for length of string for Reader */
-
- short ItemHit; /* itemnumber from modal dialog */
- short theType; /* for GetDItem */
- int ***theItem; /* for GetDItem */
- Rect theRect; /* for GetDItem */
-
- main()
- {
- InitGraf(&thePort); /* Init Quickdraw */
- InitFonts(); /* Init Font Manager */
- InitWindows(); /* Init Window Manager */
- InitDialogs(0); /* Init Dialog Manager */
- TEInit();
- InitCursor(); /* set arrow cursor */
-
- OpenResFile("\pCheapTalk.Rsrc"); /* open for DLOG and PHNM resources */
-
- /* assume that driver will open alright, set our flag to TRUE */
- speechOK=1;
- /*************************************************************/
- /* Open speech driver to use default rules */
- /* If driver open not successful then clear speechOK flag */
- /* to prevent further use of invalid driver */
- /* You could also put an error dialog here */
-
- if (SpeechOn(0,&theSpeech) != 0)
- { speechOK = 0;
- dp = GetNewDialog(2,0,-1);
- SetPort(dp);
- ModalDialog(0,&ItemHit);
- ExitToShell();
- }
- /*************************************************************/
- /* Get Dialog from the Resource file */
- /* Store on heap and make it front window */
- dp = GetNewDialog(theDialog,0,-1);
- SetPort(dp); /* Make It The Current Port */
- /*************************************************************/
- /* usually you would not use DrawDialog, but we need to draw the */
- /* dialog contents once before saying them, then go to Modal dialog */
- /* which will draw the contents again */
- DrawDialog(dp);
- /****************** Speak pre-translated speech ***************/
- /* now Say the static text item which has been pre-translated into */
- /* a phoneme string with the same ID as the dialog */
- /* first, check our flag to make sure that driver is open */
- if (speechOK == 0) goto L2; /* driver not valid, branch around */
- /* driver valid, go ahead and speak */
- phHandle = GetResource('PHNM',theDialog); /* handle to phoneme string */
- /* say it using, speech global handle and phoneme handle,*/
- Result = MacinTalk(theSpeech,phHandle);
- L2: /* branch to here to avoid speaking with invalid driver */
- /*************** Dialog loop *******************/
- /* now process the dialog */
- dialogloop:
- ModalDialog(0,&ItemHit); /* default filter proc & Item Hit Data */
- /*see which button was pushed */
- if (quitbutton == ItemHit) goto closeit; /* if quit button, then close */
- if (sayitbutton == ItemHit) goto sayit; /* if say it button, then say it */
- goto dialogloop; /* none of the above so go around again */
- /*********** Translate English to Phonetics and speak **********/
- sayit:
- /* first, check our flag to make sure that driver is open */
- if (speechOK==0) goto L3;
- /* driver not valid, branch around speech stuff */
- /* driver valid, go ahead and speak */
- /* get the current text in the edit text box */
- GetDItem(dp,usertext,&theType,&theItem,&theRect);
- GetIText(theItem,theString);
- /* now feed the text into reader to translate it into phonemes */
- /* set up an empty handle first for Reader to fill with phonemes */
- phHandle = NewHandle(0); /* set up empty handle. */
- length = (long)theString[0];/* length fo the string */
- Result = Reader(theSpeech,&theString[1],length,phHandle);
- /* now feed the phonemes to Macintalk */
- Result = MacinTalk(theSpeech,phHandle);
- /* deallocate handle and loop back for more */
- DisposHandle(phHandle);
- L3: /* branch to here to avoid speaking with invalid driver */
- goto dialogloop;
- /******************* Close up shop *******************************/
- closeit:
- CloseDialog(dp); /* Close the Dialog window */
- /* first, check our flag to make sure that driver is open */
- if (speechOK==0) goto L4; /* if driver not valid, branch around */
- /* driver valid,so close it up with the handle to the speech globals */
- SpeechOff(theSpeech);
- L4: /* branch to here to avoid closing invalid driver */
- ExitToShell(); /* Return To Finder */
- }
-