home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 5
/
FreshFish_July-August1994.bin
/
bbs
/
dev
/
rkrm.lha
/
RKRM
/
Narrator
/
Full_Narrator.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-03
|
19KB
|
614 lines
/*
* Copyright (c) 1992 Commodore-Amiga, Inc.
*
* This example is provided in electronic form by Commodore-Amiga, Inc. for
* use with the "Amiga ROM Kernel Reference Manual: Devices", 3rd Edition,
* published by Addison-Wesley (ISBN 0-201-56775-X).
*
* The "Amiga ROM Kernel Reference Manual: Devices" contains additional
* information on the correct usage of the techniques and operating system
* functions presented in these examples. The source and executable code
* of these examples may only be distributed in free electronic form, via
* bulletin board or as part of a fully non-commercial and freely
* redistributable diskette. Both the source and executable code (including
* comments) must be included, without modification, in any copy. This
* example may not be published in printed form or distributed with any
* commercial product. However, the programming techniques and support
* routines set forth in these examples may be used in the development
* of original executable software products for Commodore Amiga computers.
*
* All other rights reserved.
*
* This example is provided "as-is" and is subject to change; no
* warranties are made. All use is at your own risk. No liability or
* responsibility is assumed.
*
***************************************************************************
*
* Full_Narrator.c
*
* This example program sends a string of phonetic text to the narrator
* device and, while it is speaking, highlights, word-by-word, a
* corresponding English string. In addition, mouth movements are drawn
* in a separate window.
*
* Compile with SAS C 5.10 lc -b1 -cfistq -v -y -L
*
* Requires Kickstart V37 or greater.
*/
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/libraries.h>
#include <dos/dos.h>
#include <intuition/intuition.h>
#include <ctype.h>
#include <exec/exec.h>
#include <fcntl.h>
#include <devices/narrator.h>
#include <clib/exec_protos.h>
#include <clib/alib_protos.h>
#include <clib/intuition_protos.h>
#include <clib/graphics_protos.h>
#include <clib/dos_protos.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#ifdef LATTICE
int CXBRK(void) { return(0); } /* Disable SAS CTRL/C handling */
int chkabort(void) { return(0); } /* really */
#endif
/*
* Due to an omission, the sync field defines were not included in older
* versions of the narrator device include files. So, if they haven't
* already been defined, do so now.
*/
#ifndef NDF_READMOUTH /* Already defined ? */
#define NDF_READMOUTH 0x01 /* No, define here */
#define NDF_READWORD 0x02
#define NDF_READSYL 0x04
#endif
#define PEN3 3 /* Drawing pens */
#define PEN2 2
#define PEN1 1
#define PEN0 0
BOOL FromCLI = TRUE;
BYTE chans[4] = {3, 5, 10, 12};
LONG EyesLeft; /* Left edge of left eye */
LONG EyesTop; /* Top of eyes box */
LONG EyesBottom; /* Bottom of eyes box */
LONG YMouthCenter; /* Pixels from top edge */
LONG XMouthCenter; /* Pixels from left edge */
LONG LipWidth, LipHeight; /* Width and height of mouth */
struct TextAttr MyFont = {"topaz.font", TOPAZ_SIXTY, FS_NORMAL, FPF_ROMFONT,};
extern struct Library *SysBase; /* Used to check the OS version number */
struct IntuitionBase *IntuitionBase = NULL;
struct GfxBase *GfxBase = NULL;
struct MsgPort *VoicePort = NULL;
struct MsgPort *MouthPort = NULL;
struct narrator_rb *VoiceIO = NULL;
struct mouth_rb *MouthIO = NULL;
struct IntuiText HighLight;
struct NewWindow NewWindow;
struct Window *TextWindow;
struct Window *FaceWindow;
struct RastPort *FaceRast;
void main(int argc, char **argv)
{
LONG i;
LONG sentence;
LONG Offset;
LONG CharsLeft;
LONG ScreenPos;
LONG WordLength;
LONG LineNum;
UBYTE *Tempptr;
UBYTE *English;
UBYTE *OldEnglish;
UBYTE c;
UBYTE *PhonPtr; /* Pointer to phonetic text */
LONG PhonSize; /* Size of phonetic text */
UBYTE *PhonStart[100]; /* Start of phonetic sentences */
LONG NumPhonStarts; /* Number of phonetic sentences */
UBYTE *EngPtr; /* Pointer to English text */
LONG EngSize; /* Size of English text */
UBYTE *EngStart[100]; /* Start of English sentences */
LONG NumEngStarts; /* Number of English sentences */
UBYTE *EngLine[24]; /* Start of line on screen */
LONG EngBytes[24]; /* Bytes per line on screen */
LONG NumEngLines; /* Number of lines on screen */
extern void Cleanup(UBYTE *errmsg);
extern void ClearWindow(struct Window *TextWindow);
extern void DrawFace(void);
extern void UpdateFace(void);
/*
* (0) Note whether the program was started from the CLI or from
* Workbench.
*/
if (argc == 0)
FromCLI = FALSE;
/*
* (1) Setup the phonetic text to be spoken. If there are any non-
* alphabetic characters in the text (such as NEWLINES or TABS)
* replace them with spaces. Then break up the text into sentences,
* storing the start of each sentence in PhonStart array elements.
*/
PhonPtr = "KAA1RDIYOWMAYAA5PAXTHIY. AY /HAED NEH1VER /HER4D AXV IHT "
"BIXFOH5R, BAHT DHEH5R IHT WAHZ - LIH4STIXD AEZ (DHAX FOH5RM "
"AXV /HAA5RT DIHZIY5Z) DHAET FEH4LD (NAAT WAH5N OHR TUW5) - "
"BAHT (AO7L THRIY5 AXV DHAX AA5RTAXFIHSHUL /HAA5RTQ "
"RIXSIH5PIYINTS). (AH LIH5TUL RIXSER5CH) PROHDUW5ST (SAHM "
"IH5NTRIHSTIHNX RIXZAH5LTS). AHKOH5RDIHNX TUW (AEN AA5RTIHKUL "
"IHN DHAX NOWVEH5MBER EY2THQX NAY5NTIYNEYTIYFOH1R NUW IY5NXGLIND "
"JER5NUL AXV MEH5DIXSIN), (SIH5GEREHT SMOW5KIHNX) KAO4ZIHZ "
"(DHIHS LIY5THUL DIHZIY5Z) DHAET WIY4KINZ (DHAX /HAA5RTS "
"PAH4MPIHNX PAW2ER). WAYL (DHIY IHGZAE5KT MEH5KINIXZUM) IHZ "
"NAAT KLIY5R, DAA5KTER AA5RTHER JEY2 /HAARTS SPEH5KYULEYTIHD "
"DHAET NIH4KAXTIY2N- OHR KAA5RBIN MUNAA5KSAYD IHN DHAX SMOW5K- "
"SAH5M/HAW1 POY4ZINZ DHAX /HAA5RT, AEND LIY4DZ TUW (/HAA5RT "
"FEY5LYER).";
PhonSize = strlen(PhonPtr);
NumPhonStarts = 0;
PhonStart[NumPhonStarts++] = PhonPtr;
for (i = 0; i < PhonSize; ++i)
{
if (isspace((int)(c = *PhonPtr++)))
*(PhonPtr-1) = ' ';
if ((c == '.') || (c == '?'))
{
*PhonPtr = '\0';
PhonStart[NumPhonStarts++] = ++PhonPtr;
}
}
/*
* (2) Create the English text corresponding to the phonetic text above.
* As before, insure that there are no TABS or NEWLINES in the text.
* Break the text up into sentences and store the start of each
* sentence in EngStart array elements.
*/
EngPtr = "Cardiomyopathy. I had never heard of it before, but there it was "
"listed as the form of heart disease that felled not one or two but "
"all three of the artificial heart recipients. A little research "
"produced some interesting results. According to an article in the "
"November 8, 1984, New England Journal of Medicine, cigarette smoking "
"causes this lethal disease that weakens the heart's pumping power. "
"While the exact mechanism is not clear, Doctor Arthur J Hartz "
"speculated that nicotine or carbon monoxide in the smoke somehow "
"poisons the heart and leads to heart failure.";
EngSize = strlen(EngPtr);
NumEngStarts = 0;
EngStart[NumEngStarts++] = EngPtr;
for (i = 0; i < EngSize; ++i)
{
if (isspace((int)(c = *EngPtr++)))
*(EngPtr-1) = ' ';
if ((c == '.') || (c == '?'))
{
*EngPtr = '\0';
EngStart[NumEngStarts++] = ++EngPtr;
}
}
/*
* (3) Open Intuition and Graphics libraries.
*/
if (!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0)))
Cleanup("c