1 #include <vole/vole.hpp>
3 #include <comstl/util/initialisers.hpp>
7 using namespace stlsoft
;
12 vole::object
getSpeaker() {
13 static vole::object ret
=vole::object::create("SAPI.SpVoice");
14 cout
<<sizeof(vole::object
);
17 vole::collection
getVoices() {
18 static vole::collection ret
=getSpeaker().invoke_method
<vole::collection
>(L
"GetVoices");
21 DECLSPEC
void initSpeech() {
24 comstl::com_initialiser coinit
;
25 vole::object voice
=getSpeaker().get_property
<vole::object
>(L
"voice");
26 voicestr
=voice
.invoke_method
<string
>(L
"GetDescription");
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
;
43 std::cerr
<< "unexpected condition" << std::endl
;
47 DECLSPEC
void terminateSpeech() {
50 DECLSPEC
void speak(char * text
, int flags
)
53 if (flags
&SPEAK_BLOCKING
) sapiFlags
=0;
54 if (flags
&SPEAK_INTERRUPTING
) sapiFlags
=2;
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");
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
;
88 DECLSPEC
void stopSpeech()
90 getSpeaker().invoke_method
<void>(L
"Speak", "", 2);