  '=================================
  'ATTACHING SAPI VOICE TO AN OBJECT
  '=================================
  '
  '
  '         ###############
  '       ###################
  '      ###               ###
  '     ###    ###          ###
  '    ###    ## ##         ###
  '    ###   ##   ##        ###
  '    ###  ##     ##       ###
  '    ###  ##      ##      ###
  '    ###  ##      ##      ###
  '    ###   ####  ##      ###
  '     ###    ####       ###
  '      ###             ###
  '       ###           ###
  '         #############
  '           #########

  uses COM/Voice
  CoInitialize null
  Connect voice


  extern

  '---------
  class mind
  '=========
    string memory
  end class    


  '-----------
  class person
  '===========
    has mind
    sys pv
    '
    method constructor()
    memory="<>"
    end method
    '
    method destructor()
    del memory
    end method
    '
    method speech(ISpVoice*v)
    pv=@v
    end method

    method learn(string s)
    memory+=s "<>"
    end method

    method speak(wstring s)
    if pv then
      IspVoice v at pv
      v.speak s
      v.WaitUntilDone forever
    end if
    end method
    '
    method recall(string s)
    sys a,b,c
    string r
    a=instr(memory,s)
    if a then
      a+=len(s)
      b=instr(a,memory,"<>")
    end if
    if a then
      r=mid(memory,a,b-a)
    else
      r="I do not remember " s
    end if
    if pv then
      speak r
    else
      print r
    end if
    end method
    '
  end class

  end extern
  
  function main()
  if err=0 then
    'voice.speak "hello"
    'voice.WaitUntilDone forever

    new Person Hilda
    Hilda.speech voice
    Hilda.speak "ok"
    Hilda.learn ".greeting. Hello Everyone"
    Hilda.learn ".departure. Goodbye Everyone"
    Hilda.recall ".greeting."
    Hilda.recall ".departure."
    del Hilda
  else
    print "Error: " err
  end if
  end function
  main
  Disconnect voice
  CoUninitialize
  


