Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <servprov.h>
- #include <sapi.h>
- #include <string>
- #include <iostream>
- #include <comstl/error/exceptions.hpp>
- #include <comstl/util/initialisers.hpp>
- #include <comstl/util/creation_functions.hpp>
- #include <stlsoft/smartptr/ref_ptr.hpp>
- #include <winstl/conversion/char_conversions.hpp>
- namespace stlsoft {
- namespace comstl_project {
- COMSTL_IID_TRAITS_DEFINE(ISpVoice)
- }
- }
- class mySpeech {
- public:
- mySpeech() {
- static comstl::com_initializer coinit;
- HRESULT hr;
- if(FAILED(hr = comstl::co_create_instance(CLSID_SpVoice,_pVoice)))
- throw comstl::com_exception("Failed to create SpVoice COMinstance",hr);
- }
- int sayit(const char* s, int n) {
- std::string(s,n);
- _pVoice->Speak(winstl::a2w(s), SPF_ASYNC, 0);
- return n;
- }
- void setRate(long n) { _pVoice->SetRate(n); }
- private:
- //COM object smart pointer
- stlsoft::ref_ptr<ISpVoice> _pVoice;
- };
- // Main
- int main() {
- class mySpeech *msp;
- try {
- msp = new mySpeech();
- } catch (comstl::com_exception &e){
- std::cerr<< "error";
- }
- const char* str="hello, world";
- msp->sayit(str,13);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement