Date: Sun, 22 Aug 1993 17:21:29 -0500 From: PAUL M SHELDON Subject: simple speech manager translation to pascal code I have little experience in C and was grateful for the posting, in C, of speech manager routine calls. It gave me an opportunity to make a simple exercise to value learning C in the future by the book. In the following, I paste my C to pascal code translation of a submission of a quick hack on this archive by Alan Coopersmith as /info-mac/dev/mac-speech-01.hqx. It was a lot of fun to figure this simple translation with a kid I mentor and then go on late into the night to make the compiling linking and execution work. I tried to comment the code with some of my hard won understanding. Perhaps this brief segment will improve others courage as it has mine. I had a lot of psychological inertia to get moving into enthusiastic momentum. I look forward to translating Alexander W. Kourakos' C demo with Paul Traue, my mentor-kid. Povl H. Pedersen has given me some reassurance. Notice what I am trying to say is this isn't much of a boast for me, just a sense of remarkable joy that I can hook into new system extensions from apple with pinterfaces. A few years ago the only guys I knew about who did real stuff with new rom calls worked in a garage well above my league... A few years later, I thought that was guys who made modula module (managers) who as far as I could see might as well have been also making computers or computer languages. Its in my league now! OK here's the code, part of a larger hidden body of code that I worked through developing in an Apple course called the pascal object oriented animation library (incidentally, their enclosed video movie "How to Create A Monster" ought to have a Galateia sequel): PROCEDURE TTextEntryDialog.GetTextBBAtItemBB(VAR theText:Str255;ItemNo:INTEGER); VAR CharIndex , theType:INTEGER;(* gives the type of the item requested *) theTextHdl:Handle;(* gives a handle to the item *) txtBox:Rect;(* gives the display rectangle of the item *) theChannel: SpeechChannel; theVoiceSpecPtr: VoiceSpecPtr; theVoiceSpec: VoiceSpec; myErr: OSErr; finalTicks,textlen,delayLen: LONGINT; theTextPtr:Ptr; { Comment on string lengths: Pasted from Spinside mac Toolbox utilities: String 'STR ' m bytes The string (1-byte length followed by the characters) THE MEMORY MANAGER Str255 = STRING[255]; My remarks (PMS): 8bits specify 2^8=256 possibilities (less one possibility of string 0 length) or 255 } voiceCount:integer; BEGIN {Standard calls to get text from a dialogue box I made:} GetDItem (fDialog, ItemNo, theType, theTextHdl, txtBox); GetIText (theTextHdl, theText); {Following are speech commands, Put speech.p in Lab 7 folder, so PMake would see it without too much auxiliary scripting:} {Some sort of initialization needed even if not do loop of all:} myErr := CountVoices (voiceCount); {Type transfer from generic pointer:} theVoiceSpecPtr := VoiceSpecPtr(@theVoiceSpec); {Liked the deep voice, most like Schwartznegger's:} myErr := GetIndVoice (6, theVoiceSpecPtr); myErr := NewSpeechChannel (theVoiceSpecPtr, theChannel); {Note: @theText= @theText[0] would tell length of text, since theText:Str255, so we use @theText[1] to start reading where we want to below:} theTextPtr:=Ptr(@theText[1]); {Since we started reading at the right byte, we have the expected text length:} textlen:=Ord4(LENGTH(theText)); {OK now we have set up and it can speak:} myErr := SpeakText (theChannel,theTextPtr,textlen); {The need for the following wait loop shows that statements following speech can happen concurrently, that is, are immediately executed during speech! Don't want to dispose his speech while the speaker is speaking!} while (NOT (SpeechBusy = 0)) do Delay(15, delayLen); myErr := DisposeSpeechChannel (theChannel); END;