home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-23 | 4.0 KB | 157 lines | [TEXT/PJMM] |
- { unit to interface with Speech Daemon GH }
- unit Daemon;
- interface
- uses
- FixMath, Utility, Globals, Speech, PPCToolBox, Script, Processes;
- procedure Talk2Daemon (prefs: PrefRecord;
- string2Speak: Str255);
- function IsDaemonAwake: Boolean;
- implementation
-
- type
- MyVoiceInfo = record
- vers: integer;
- vol: Fixed;
- rate: Fixed;
- modu: Fixed;
- pit: Fixed;
- aVoice: VoiceSpec;
- theString: Str255;
- keepChannel: Boolean;
- waitTicks: LONGINT;
- currTicks: LONGINT;
- end;
- SessionRecord = record
- pb: PPCParamBlockRec;
- portName: PPCPortRec;
- locationName: LocationNameRec;
- userName: Str255;
- buf1: Str255;
- buf2: Str255;
- end;
- const
- kDaemonVersion = 1;
- kSpeakString = 1000;
-
-
- function IsDaemonAwake: Boolean;
- var
- procNum: ProcessSerialNumber;
- procInfo: ProcessInfoRec;
- iErr: OSErr;
- done: Boolean;
- begin
- procInfo.processInfoLength := sizeof(ProcessInfoRec);
- procInfo.processName := nil;
- procInfo.processAppSpec := nil;
- procNum.highLongOfPSN := 0;
- procNum.lowLongOfPSN := kNoProcess;
- IsDaemonAwake := FALSE;
- done := FALSE;
- iErr := GetNextProcess(procNum);
- while (iErr = noErr) and (done = FALSE) do
- begin
- iErr := GetProcessInformation(procNum, procInfo);
- if iErr = noErr then
- begin
- if ('IF 8' = procInfo.processSignature) and ('APPL' = procInfo.processType) then
- begin
- IsDaemonAwake := TRUE;
- done := TRUE;
- end;
- end;
- iErr := GetNextProcess(procNum);
- end;
- end;
- { open a PPC port }
- function OpenAPort (var refNum: integer): OSErr;
- var
- thePort: PPCPortRec;
- pb: PPCOpenPBRec;
- err: OSErr;
- aString: Str255;
- begin
- thePort.nameScript := smRoman;
- GetIndString(aString, 128, 2);
- BlockMove(@aString, @thePort.name, 32);
- thePort.portKindSelector := ppcByCreatorAndType;
- thePort.portCreator := 'Slik';
- thePort.PortType := 'APPL';
- pb.ioCompletion := nil;
- pb.serviceType := ppcServiceRealTime;
- pb.resFlag := 0;
- pb.networkVisible := false;
- pb.portName := @thePort;
- pb.locationName := nil;
- err := PPCOpen(@pb, false);
- OpenAPort := err;
- refNum := pb.portRefNum;
- end;
-
- procedure Talk2Daemon (prefs: PrefRecord;
- string2Speak: Str255);
- var
- iErr: OSErr;
- err: OSErr;
- refNum: integer;
- sesRec: SessionRecord;
- myVInfo: MyVoiceInfo;
- aString: Str255;
- begin
- iErr := OpenAPort(refNum);
- if iErr = noErr then
- begin
- sesRec.portName.nameScript := smRoman;
- GetIndString(aString, 128, 1);
- BlockMove(@aString, @sesRec.portName.name, 32);
- sesRec.portName.portKindSelector := ppcByCreatorAndType;
-
- sesRec.portName.portCreator := 'IF 8';
- sesRec.portName.PortType := 'APPL';
-
- sesRec.pb.startParam.ioCompletion := nil;
- sesRec.pb.startParam.portRefNum := refNum;
- sesRec.pb.startParam.serviceType := ppcServiceRealTime;
- sesRec.pb.startParam.resFlag := 0;
- sesRec.pb.startParam.portName := @sesRec.portName;
-
- sesRec.pb.startParam.locationName := nil;
- sesRec.pb.startParam.userData := kSpeakString;
- sesRec.pb.startParam.userRefNum := 0;
-
-
- iErr := PPCStart(@sesRec.pb.startParam, FALSE);
- if iErr = noErr then
- begin
- with myVInfo, prefs do
- begin
- vers := kDaemonVersion;
- vol := volume;
- rate := wpm;
- modu := modulation;
- pit := pitch;
- aVoice.creator := voice.creator;
- aVoice.id := voice.id;
- waitTicks := 0;
- currTicks := TickCount;
- keepChannel := keepVoice;
- end;
- BlockMove(@string2Speak, @myVInfo.theString, 255);
- sesRec.pb.writeParam.ioCompletion := nil;
- sesRec.pb.writeParam.bufferLength := sizeof(MyVoiceInfo);
- sesRec.pb.writeParam.bufferPtr := Ptr(@myVInfo);
- sesRec.pb.writeParam.more := false;
- iErr := PPCWrite(@sesRec.pb.writeParam, FALSE);
- end;
-
- err := PPCEnd(@sesRec.pb.endParam, false);
- err := PPCClose(@sesRec.pb.closeParam, false); { close the port }
- end;
- { if something failed, speak the string using the default method }
-
- if iErr <> noErr then
- begin
- iErr := SpeakString(string2Speak);
- end;
- end;
- end.