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");
16 vole::collection
getVoices() {
17 static vole::collection ret
=getSpeaker().invoke_method
<vole::collection
>(L
"GetVoices");
20 DECLSPEC
void initSpeech() {
23 comstl::com_initialiser coinit
;
24 vole::object voice
=getSpeaker().get_property
<vole::object
>(L
"voice");
25 voicestr
=voice
.invoke_method
<string
>(L
"GetDescription");
27 catch(std::bad_alloc
&)
29 std::cerr
<< "out of memory" << std::endl
;
31 catch(vole::vole_exception
& x
)
33 std::cerr
<< "operation failed: " << x
.what() << ": " << winstl::error_desc_a(x
.hr()) << std::endl
;
35 catch(std::exception
& x
)
37 std::cerr
<< "operation failed: " << x
.what() << std::endl
;
41 std::cerr
<< "unexpected condition" << std::endl
;
45 DECLSPEC
void terminateSpeech() {
48 DECLSPEC
void speak(char * text
, int flags
)
51 if (flags
&SPEAK_BLOCKING
) sapiFlags
=0;
52 if (flags
&SPEAK_INTERRUPTING
) sapiFlags
=2;
53 getSpeaker().invoke_method
<void>(L
"Speak", "<voice required=\"name="+voicestr
+"\">"+text
+"</voice>", sapiFlags
);
55 DECLSPEC
void setSpeechRate(int rate
)
57 getSpeaker().put_property
<int>(L
"Rate",rate
);
60 DECLSPEC
int getSpeechRate() {
61 int ret
= getSpeaker().get_property
<int>(L
"rate");
64 DECLSPEC
void setSpeechVoice(int v
)
66 int count
= getVoices().get_property
<int>(L
"count");
67 if (v
>=count
) return;
68 vole::object voice
= getVoices().invoke_method
<vole::object
>(L
"Item",v
);
69 voicestr
=voice
.invoke_method
<string
>(L
"GetDescription");
71 DECLSPEC
int getSpeechVoice()
73 int count
= getVoices().get_property
<int>(L
"count");
74 for (int i
=0;i
<count
;i
++)
76 vole::object voice
=getVoices().invoke_method
<vole::object
>(L
"item", i
);
77 if (voicestr
==voice
.invoke_method
<string
>(L
"GetDescription")) return i
;
82 DECLSPEC
void stopSpeech()
84 getSpeaker().invoke_method
<void>(L
"Speak", "", 2);