home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Snippets / PNL Libraries / MySpeak.p < prev    next >
Encoding:
Text File  |  1997-06-03  |  1.6 KB  |  94 lines  |  [TEXT/CWIE]

  1. unit MySpeak;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Types;
  7.  
  8.     procedure StartupSpeak;
  9.     function SpeakBusy: boolean;
  10.     procedure SpeakStr (s: Str255);
  11.     procedure Speak(id, index: integer);
  12.     function SpeechAvailable: boolean;
  13.  
  14. implementation
  15.  
  16.     uses
  17.         Speech, GestaltEqu, TextUtils, CodeFragments, OSUtils, 
  18.         MyStartup;
  19.  
  20. {$ifc do_debug}
  21.     var
  22.         startup_check: integer;
  23. {$endc}
  24.  
  25. {$SETC debug=0}
  26.  
  27.     function HasSpeechLib:boolean;
  28.     begin
  29. {$IFC GENERATINGPOWERPC}
  30.         HasSpeechLib := longint(@SpeakString) <> kUnresolvedCFragSymbolAddress;
  31. {$ELSEC}
  32.         HasSpeechLib := true;
  33. {$ENDC}
  34.     end;
  35.  
  36.     function SpeechAvailable: boolean;
  37.         var
  38.             v: longint;
  39.     begin
  40.         AssertDidStartup( startup_check );
  41. {$IFC debug}
  42.         SpeechAvailable := true;
  43. {$ELSEC}
  44.         SpeechAvailable := (Gestalt(gestaltSpeechAttr, v) = noErr) & BTST(v, gestaltSpeechMgrPresent) & HasSpeechLib;
  45. {$ENDC}
  46.     end;
  47.  
  48.     function SpeakBusy: boolean;
  49.     begin
  50.         AssertDidStartup( startup_check );
  51. {$IFC debug}
  52.         SpeakBusy := false;
  53. {$ELSEC}
  54.         SpeakBusy := SpeechAvailable & (SpeechBusy > 0);
  55. {$ENDC}
  56.     end;
  57.  
  58.     procedure SpeakStr (s: Str255);
  59.     begin
  60.         AssertDidStartup( startup_check );
  61. {$IFC debug}
  62.         DebugStr(concat('Speak ', s));
  63. {$ELSEC}
  64.         if not SpeechAvailable | (SpeakString(@s) <> noErr) then begin
  65.             SysBeep(1);
  66.         end;
  67. {$ENDC}
  68.     end;
  69.  
  70.     procedure Speak (id, index: integer);
  71.         var
  72.             s: Str255;
  73.     begin
  74.         AssertDidStartup( startup_check );
  75.         GetIndString(s, id, index);
  76.         SpeakStr(s);
  77.     end;
  78.  
  79.     procedure FinishSpeak;
  80.     begin
  81. {$IFC not debug}
  82.         if SpeechAvailable then begin
  83.             SpeakStr('');
  84.         end;
  85. {$ENDC}
  86.     end;
  87.  
  88.     procedure StartupSpeak;
  89.     begin
  90.         DidStartup( startup_check );
  91.         SetStartup(nil, nil, 0, FinishSpeak);
  92.     end;
  93.     
  94. end.