Fixed makefile.
[bcl.git] / speech_sapi.cpp
blob15b33869c9ca19a9bc1c1015497617d6c3c7006c
1 #include <vole/vole.hpp>
3 #include <comstl/util/initialisers.hpp>
5 #include <iostream>
6 #include "bcl.h"
7 using namespace stlsoft;
8 using namespace std;
10 string voicestr;
12 vole::object getSpeaker() {
13 static vole::object ret =vole::object::create("SAPI.SpVoice");
14 cout<<sizeof(vole::object);
15 return ret;
17 vole::collection getVoices() {
18 static vole::collection ret =getSpeaker().invoke_method<vole::collection>(L"GetVoices");
19 return ret;
21 DECLSPEC void initSpeech() {
22 try
24 comstl::com_initialiser coinit;
25 vole::object voice =getSpeaker().get_property<vole::object>(L"voice");
26 voicestr =voice.invoke_method<string>(L"GetDescription");
27 cout<<"hello";
29 catch(std::bad_alloc&)
31 std::cerr << "out of memory" << std::endl;
33 catch(vole::vole_exception& x)
35 std::cerr << "operation failed: " << x.what() << ": " << winstl::error_desc_a(x.hr()) << std::endl;
37 catch(std::exception& x)
39 std::cerr << "operation failed: " << x.what() << std::endl;
41 catch(...)
43 std::cerr << "unexpected condition" << std::endl;
47 DECLSPEC void terminateSpeech() {
48 return;
50 DECLSPEC void speak(char * text, int flags)
52 int sapiFlags =1;
53 if (flags &SPEAK_BLOCKING) sapiFlags =0;
54 if (flags &SPEAK_INTERRUPTING) sapiFlags =2;
55 cout <<"I was he2re";
56 getSpeaker().invoke_method<void>(L"Speak", "<voice required=\"name="+voicestr+"\">"+text+"</voice>");
59 DECLSPEC void setSpeechRate(int rate)
61 getSpeaker().put_property<int>(L"Rate",rate);
64 DECLSPEC int getSpeechRate() {
65 int ret = getSpeaker().get_property<int>(L"rate");
66 return ret;
69 DECLSPEC void setSpeechVoice(int v)
71 int count = getVoices().get_property<int>(L"count");
72 if (v >=count) return;
73 vole::object voice = getVoices().invoke_method<vole::object>(L"Item",v);
74 voicestr =voice.invoke_method<string>(L"GetDescription");
77 DECLSPEC int getSpeechVoice()
79 int count = getVoices().get_property<int>(L"count");
80 for (int i =0;i<count;i++)
82 vole::object voice =getVoices().invoke_method<vole::object>(L"item", i);
83 if (voicestr ==voice.invoke_method<string>(L"GetDescription")) return i;
85 return 0;
88 DECLSPEC void stopSpeech()
90 getSpeaker().invoke_method<void>(L"Speak", "", 2);