Advertisement
Guest User

SAPI C++ example

a guest
Mar 22nd, 2010
996
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include <windows.h>
  2.  #include <servprov.h>
  3.  #include <sapi.h>
  4.  #include <string>
  5.  #include <iostream>
  6.  #include <comstl/error/exceptions.hpp>
  7.  #include <comstl/util/initialisers.hpp>
  8.  #include <comstl/util/creation_functions.hpp>
  9.  #include <stlsoft/smartptr/ref_ptr.hpp>
  10.  #include <winstl/conversion/char_conversions.hpp>
  11.  
  12.  namespace stlsoft {
  13.  namespace comstl_project {
  14.      COMSTL_IID_TRAITS_DEFINE(ISpVoice)
  15.  }
  16.  }
  17.  
  18.  class mySpeech {
  19.      public:
  20.          mySpeech() {
  21.              static comstl::com_initializer coinit;
  22.              HRESULT hr;
  23.              if(FAILED(hr = comstl::co_create_instance(CLSID_SpVoice,_pVoice)))
  24.                  throw comstl::com_exception("Failed to create SpVoice COMinstance",hr);
  25.          }
  26.          int sayit(const char* s, int n) {
  27.              std::string(s,n);
  28.              _pVoice->Speak(winstl::a2w(s), SPF_ASYNC, 0);
  29.              return n;
  30.          }
  31.          void setRate(long n) { _pVoice->SetRate(n); }
  32.      private:
  33.          //COM object smart pointer
  34.          stlsoft::ref_ptr<ISpVoice> _pVoice;
  35.  };
  36.  // Main
  37.  int main() {
  38.      class mySpeech *msp;
  39.      try {
  40.          msp = new mySpeech();
  41.      } catch (comstl::com_exception &e){
  42.          std::cerr<< "error";
  43.      }
  44.      const char* str="hello, world";
  45.      msp->sayit(str,13);
  46.      return 0;
  47.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement