
'-----------------------------------------
'SAPI VOICE
'=========================================

  use com\ComUtil

  'from sapi.h


  'MIDL_INTERFACE("5EFF4AEF-8487-11D2-961C-00C04F8EE628")
  'ISpNotifySource : public IUnknown
  '
  extern virtual
  '
  '--------------------
  class ISpNotifySource
  '====================

    public

    extends IUnknown
        '4
        HRESULT SetNotifySink( 
            /* [in] */ __RPC__in_opt ISpNotifySink *pNotifySink)
        '5
        HRESULT SetNotifyWindowMessage( 
            /* [in] */ HWND hWnd,
            /* [in] */ UINT Msg,
            /* [in] */ WPARAM wParam,
            /* [in] */ LPARAM lParam)
        '6
        HRESULT SetNotifyCallbackFunction( 
            /* [in] */ SPNOTIFYCALLBACK *pfnCallback,
            /* [in] */ WPARAM wParam,
            /* [in] */ LPARAM lParam)
        '7
        HRESULT SetNotifyCallbackInterface( 
            /* [in] */ ISpNotifyCallback *pSpCallback,
            /* [in] */ WPARAM wParam,
            /* [in] */ LPARAM lParam)
        '8
        HRESULT SetNotifyWin32Event( void)
        '9
        HRESULT WaitForNotifyEvent( 
            /* [in] */ DWORD dwMilliseconds)
        '10
        HANDLE GetNotifyEventHandle( void)

  end class



  'MIDL_INTERFACE("BE7A9CCE-5F9E-11D2-960F-00C04F8EE628")
  'ISpEventSource : public ISpNotifySource
  '

  '-------------------
  class ISpEventSource
  '===================

    public

    extends ISpNotifySource
        '11
        HRESULT SetInterest( 
            /* [in] */ ULONGLONG ullEventInterest,
            /* [in] */ ULONGLONG ullQueuedInterest)
        '12
        HRESULT GetEvents( 
            /* [in] */ ULONG ulCount,
            /* [size_is][out] */ SPEVENT *pEventArray,
            /* [out] */ ULONG *pulFetched)
        '13
        HRESULT GetInfo( 
            /* [out] */ SPEVENTSOURCEINFO *pInfo)
        
  end class



    'MIDL_INTERFACE("6C44DF74-72B9-4992-A1EC-EF996E0422D4")
    'ISpVoice : public ISpEventSource
    '

    '-------------
    class ISpVoice
    '=============
    '
    public

    extends ISpEventSource
        '14
        HRESULT SetOutput( 
            /* [in] */ IUnknown *pUnkOutput,
            /* [in] */ BOOL fAllowFormatChanges)
        '15
        HRESULT GetOutputObjectToken( 
            /* [out] */ ISpObjectToken **ppObjectToken)
        '16
        HRESULT GetOutputStream( 
            /* [out] */ ISpStreamFormat **ppStream)
        '17
        HRESULT Pause( void)
        '18
        HRESULT Resume( void)
        '19
        HRESULT SetVoice( 
            /* [in] */ ISpObjectToken *pToken)
        '20
        HRESULT GetVoice( 
            /* [out] */ ISpObjectToken **ppToken)
        '21
        HRESULT Speak( 
            /* [string][in] */ 
            __in_opt  LPCWSTR pwcs,
            /* [in] */ DWORD dwFlags,
            /* [out] */ 
            __out_opt  ULONG *pulStreamNumber)
        '22
        HRESULT SpeakStream( 
            /* [in] */ IStream *pStream,
            /* [in] */ DWORD dwFlags,
            /* [out] */ 
            __out_opt  ULONG *pulStreamNumber)
        '23
        HRESULT GetStatus( 
            /* [out] */ SPVOICESTATUS *pStatus,
            /* [out] */ LPWSTR *ppszLastBookmark)
        '24
        HRESULT Skip( 
            /* [string][in] */ LPCWSTR pItemType,
            /* [in] */ long lNumItems,
            /* [out] */ ULONG *pulNumSkipped)
        '25
        HRESULT SetPriority( 
            /* [in] */ SPVPRIORITY ePriority)
        '26
        HRESULT GetPriority( 
            /* [out] */ SPVPRIORITY *pePriority)
        '27
        HRESULT SetAlertBoundary( 
            /* [in] */ SPEVENTENUM eBoundary)
        '28
        HRESULT GetAlertBoundary( 
            /* [out] */ SPEVENTENUM *peBoundary)
        '29
        HRESULT SetRate( 
            /* [in] */ long RateAdjust)
        '30
        HRESULT GetRate( 
            /* [out] */ long *pRateAdjust)
        '31
        HRESULT SetVolume( 
            /* [in] */ USHORT usVolume)
        '32
        HRESULT GetVolume( 
            /* [out] */ USHORT *pusVolume)
        '33
        HRESULT WaitUntilDone( 
            /* [in] */ ULONG msTimeout)
        '34
        HRESULT SetSyncSpeakTimeout( 
            /* [in] */ ULONG msTimeout)
        '35
        HRESULT GetSyncSpeakTimeout( 
            /* [out] */ ULONG *pmsTimeout)
        '36
        /* [local] */ HANDLE SpeakCompleteEvent( void)
        '37
        /* [local] */ HRESULT IsUISupported( 
            /* [in] */ LPCWSTR pszTypeOfUI,
            /* [in] */ void *pvExtraData,
            /* [in] */ ULONG cbExtraData,
            /* [out] */ BOOL *pfSupported)
        '38
        /* [local] */ HRESULT DisplayUI( 
            /* [in] */ HWND hwndParent,
            /* [in] */ LPCWSTR pszTitle,
            /* [in] */ LPCWSTR pszTypeOfUI,
            /* [in] */ void *pvExtraData,
            /* [in] */ ULONG cbExtraData)
        
    end class

    end extern


  '=================
  'UTILITY FUNCTIONS
  '=================


  '---------------------------------------------
  function ConnectVoice(ISpVoice** voice) as sys
  '=============================================
  'dim as GUID          VoiceObjGuid, ISpVoiceGuid
  'dim as LPUNKNOWN     pUnkOuter
  '@pUnkouter=0
  CreateGuid VoiceObjGuid "96749377-3391-11D2-9EE3-00C04F797396"
  CreateGuid ISpVoiceGuid "6C44DF74-72B9-4992-A1EC-EF996E0422D4"
  'err=CoCreateInstance VoiceObjGuid, pUnkouter, context, ISpVoiceGuid, byval @@voice
  err=CoCreateInstance VoiceObjGuid, null, context, ISpVoiceGuid, byval @@voice
  if err then print "CoCreateInstance error code: " err
  return err
  end function

  '------------------------------------------------
  function DisconnectVoice(ISpVoice** voice) as sys
  '================================================
  if @voice then voice.Release
  @voice=0
  end function

  '
  'UTILITY MACROS FOR LOCAL USE
  '
  '
  '===========
  'VoiceMacros
  '===========
  def Connect
  {
     ISpVoice * %1
     dim ispvoice ptr %1
     Err=ConnectVoice %1
  }

  def Disconnect
  {
    Disconnectvoice %1
  }

  def Attach
  {
    @ %1.%2 = @ %2
  }

  def Detach
  {
    @ %1.%2 = 0
  }

  def ErrorHandler
  {
    if Err then
      print "SAPI Error " hex(Err)
      CoUninitialize
      return 0
    end if
  }

  def forever 0xffffffff

