You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

281 lines
9.2 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: comstl/speech/sapi_util.hpp (derived from Pantheios)
  3. *
  4. * Purpose: Definition of SAPI types and constants.
  5. *
  6. * Created: 31st August 2006
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2006-2009, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are
  16. * met:
  17. *
  18. * - Redistributions of source code must retain the above copyright notice,
  19. * this list of conditions and the following disclaimer.
  20. * - Redistributions in binary form must reproduce the above copyright
  21. * notice, this list of conditions and the following disclaimer in the
  22. * documentation and/or other materials provided with the distribution.
  23. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the
  24. * names of any contributors may be used to endorse or promote products
  25. * derived from this software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  31. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  32. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  33. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  36. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  37. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * ////////////////////////////////////////////////////////////////////// */
  40. /** \file comstl/speech/sapi_util.hpp
  41. *
  42. * \brief [C++ only; requires COM] Definition of SAPI types and constants.
  43. * (\ref group__library__utility__com "COM Utility" Library).
  44. */
  45. #ifndef COMSTL_INCL_COMSTL_SPEECH_HPP_SAPI_UTIL
  46. #define COMSTL_INCL_COMSTL_SPEECH_HPP_SAPI_UTIL
  47. /* File version */
  48. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  49. # define COMSTL_VER_COMSTL_SPEECH_HPP_SAPI_UTIL_MAJOR 1
  50. # define COMSTL_VER_COMSTL_SPEECH_HPP_SAPI_UTIL_MINOR 0
  51. # define COMSTL_VER_COMSTL_SPEECH_HPP_SAPI_UTIL_REVISION 4
  52. # define COMSTL_VER_COMSTL_SPEECH_HPP_SAPI_UTIL_EDIT 6
  53. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  54. /* /////////////////////////////////////////////////////////////////////////
  55. * Includes
  56. */
  57. #ifndef COMSTL_INCL_COMSTL_H_COMSTL
  58. # include <comstl/comstl.h>
  59. #endif /* !COMSTL_INCL_COMSTL_H_COMSTL */
  60. #ifndef COMSTL_INCL_UTIL_HPP_CREATION_FUNCTIONS
  61. # include <comstl/util/creation_functions.hpp>
  62. #endif /* !COMSTL_INCL_UTIL_HPP_CREATION_FUNCTIONS */
  63. #ifndef COMSTL_INCL_UTIL_HPP_INTERFACE_TRAITS
  64. # include <comstl/util/interface_traits.hpp>
  65. #endif /* !COMSTL_INCL_UTIL_HPP_INTERFACE_TRAITS */
  66. #ifndef STLSOFT_INCL_STLSOFT_CONVERSION_HPP_CHAR_CONVERSIONS
  67. # include <stlsoft/conversion/char_conversions.hpp>
  68. #endif /* !STLSOFT_INCL_STLSOFT_CONVERSION_HPP_CHAR_CONVERSIONS */
  69. #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING
  70. # include <stlsoft/shims/access/string.hpp>
  71. #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING */
  72. #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ATTRIBUTE_HPP_GET_PTR
  73. # include <stlsoft/shims/attribute/get_ptr.hpp>
  74. #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ATTRIBUTE_HPP_GET_PTR */
  75. #ifndef STLSOFT_INCL_STLSOFT_SMARTPTR_HPP_REF_PTR
  76. # include <stlsoft/smartptr/ref_ptr.hpp>
  77. #endif /* !STLSOFT_INCL_STLSOFT_SMARTPTR_HPP_REF_PTR */
  78. #ifdef COMSTL_SPEECH_SAPI_UTIL_USE_MS_SAPI_HEADERS
  79. # include <sapi.h>
  80. #endif /* COMSTL_SPEECH_SAPI_UTIL_USE_MS_SAPI_HEADERS */
  81. /* /////////////////////////////////////////////////////////////////////////
  82. * Namespace
  83. */
  84. #if !defined(_COMSTL_NO_NAMESPACE) && \
  85. !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  86. # if defined(_STLSOFT_NO_NAMESPACE)
  87. /* There is no stlsoft namespace, so must define ::comstl */
  88. namespace comstl
  89. {
  90. # else
  91. /* Define stlsoft::comstl_project */
  92. namespace stlsoft
  93. {
  94. namespace comstl_project
  95. {
  96. # endif /* _STLSOFT_NO_NAMESPACE */
  97. #endif /* !_COMSTL_NO_NAMESPACE */
  98. /* /////////////////////////////////////////////////////////////////////////
  99. * SAPI
  100. */
  101. #ifndef COMSTL_SPEECH_SAPI_UTIL_USE_MS_SAPI_HEADERS
  102. /** Interface that emulates the vtable of ISpNotifySource
  103. */
  104. struct ISpNotifySource_ : public IUnknown
  105. {
  106. virtual void ISpNotifySource_1() = 0;
  107. virtual void ISpNotifySource_2() = 0;
  108. virtual void ISpNotifySource_3() = 0;
  109. virtual void ISpNotifySource_4() = 0;
  110. virtual void ISpNotifySource_5() = 0;
  111. virtual void ISpNotifySource_6() = 0;
  112. virtual void ISpNotifySource_7() = 0;
  113. };
  114. /** Interface that emulates the vtable of ISpEventSource
  115. */
  116. struct ISpEventSource_ : public ISpNotifySource_
  117. {
  118. virtual void ISpEventSource_1() = 0;
  119. virtual void ISpEventSource_2() = 0;
  120. virtual void ISpEventSource_3() = 0;
  121. };
  122. /** Interface that emulates the vtable of ISpVoice
  123. */
  124. struct ISpVoice_ : public ISpEventSource_
  125. {
  126. virtual void ISpVoice_1() = 0;
  127. virtual void ISpVoice_2() = 0;
  128. virtual void ISpVoice_3() = 0;
  129. virtual void ISpVoice_4() = 0;
  130. virtual void ISpVoice_5() = 0;
  131. virtual void ISpVoice_6() = 0;
  132. virtual void ISpVoice_7() = 0;
  133. virtual HRESULT STDMETHODCALLTYPE Speak(
  134. /* [string][in] */ const WCHAR *pwcs,
  135. /* [in] */ DWORD dwFlags,
  136. /* [out] */ ULONG *pulStreamNumber) = 0;
  137. virtual void ISpVoice_9() = 0;
  138. virtual void ISpVoice_10() = 0;
  139. virtual void ISpVoice_11() = 0;
  140. virtual void ISpVoice_12() = 0;
  141. virtual void ISpVoice_13() = 0;
  142. virtual void ISpVoice_14() = 0;
  143. virtual void ISpVoice_15() = 0;
  144. virtual void ISpVoice_16() = 0;
  145. virtual void ISpVoice_17() = 0;
  146. virtual void ISpVoice_18() = 0;
  147. virtual void ISpVoice_19() = 0;
  148. virtual HRESULT STDMETHODCALLTYPE WaitUntilDone(
  149. /* [in] */ ULONG msTimeout) = 0;
  150. virtual void ISpVoice_21() = 0;
  151. virtual void ISpVoice_22() = 0;
  152. virtual /* [local] */ HANDLE STDMETHODCALLTYPE SpeakCompleteEvent( void) = 0;
  153. virtual void ISpVoice_24() = 0;
  154. virtual void ISpVoice_25() = 0;
  155. };
  156. /** Flags that may be passed to comstl::sapi_speak()
  157. */
  158. enum SPEAKFLAGS
  159. {
  160. SPF_DEFAULT = 0,
  161. SPF_ASYNC = 1L << 0,
  162. SPF_PURGEBEFORESPEAK = 1L << 1,
  163. SPF_IS_FILENAME = 1L << 2,
  164. SPF_IS_XML = 1L << 3,
  165. SPF_IS_NOT_XML = 1L << 4,
  166. SPF_PERSIST_XML = 1L << 5,
  167. SPF_NLP_SPEAK_PUNC = 1L << 6,
  168. SPF_NLP_MASK = SPF_NLP_SPEAK_PUNC,
  169. SPF_VOICE_MASK = SPF_ASYNC | SPF_PURGEBEFORESPEAK | SPF_IS_FILENAME | SPF_IS_XML | SPF_IS_NOT_XML | SPF_NLP_MASK | SPF_PERSIST_XML,
  170. SPF_UNUSED_FLAGS = ~SPF_VOICE_MASK
  171. };
  172. # define CLSID_SpVoice comstl_ns_qual(CLSID_SpVoice_)
  173. # define ISpVoice comstl_ns_qual(ISpVoice_)
  174. namespace
  175. {
  176. const CLSID CLSID_SpVoice_ = { 0x96749377, 0x3391, 0x11D2, { 0x9E, 0xE3, 0x00, 0xC0, 0x4F, 0x79, 0x73, 0x96 } };
  177. const IID IID_ISpVoice_ = { 0x6C44DF74, 0x72B9, 0x4992, { 0xA1, 0xEC, 0xEF, 0x99, 0x6E, 0x04, 0x22, 0xD4 } };
  178. } // anonymous namespace
  179. COMSTL_IID_TRAITS_DEFINE__(ISpVoice_, ISpVoice_)
  180. #endif /* !COMSTL_SPEECH_SAPI_UTIL_USE_MS_SAPI_HEADERS */
  181. /* /////////////////////////////////////////////////////////////////////////
  182. * Functions
  183. */
  184. namespace impl
  185. {
  186. inline HRESULT sapi_speak_(ISpVoice* voice, wchar_t const* words, DWORD flags)
  187. {
  188. COMSTL_ASSERT(NULL != voice);
  189. ULONG streamNumber;
  190. return voice->Speak(words, flags, &streamNumber);
  191. }
  192. inline HRESULT sapi_speak_(ISpVoice* voice, char const* words, DWORD flags)
  193. {
  194. return sapi_speak_(voice, stlsoft_ns_qual(a2w)(words), flags);
  195. }
  196. } // namespace impl
  197. template< ss_typename_param_k V
  198. , ss_typename_param_k S
  199. >
  200. inline HRESULT sapi_speak(V& voice, S const& words, DWORD flags)
  201. {
  202. return impl::sapi_speak_(stlsoft_ns_qual(get_ptr)(voice), stlsoft_ns_qual(c_str_ptr)(words), flags);
  203. }
  204. inline HRESULT sapi_create(stlsoft_ns_qual(ref_ptr)<ISpVoice>& voice)
  205. {
  206. return comstl::co_create_instance(CLSID_SpVoice, voice);
  207. }
  208. /* ////////////////////////////////////////////////////////////////////// */
  209. #ifndef _COMSTL_NO_NAMESPACE
  210. # if defined(_STLSOFT_NO_NAMESPACE) || \
  211. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  212. } /* namespace comstl */
  213. # else
  214. } /* namespace comstl_project */
  215. } /* namespace stlsoft */
  216. # endif /* _STLSOFT_NO_NAMESPACE */
  217. # ifndef COMSTL_SPEECH_SAPI_UTIL_USE_MS_SAPI_HEADERS
  218. using ::comstl::SPF_DEFAULT;
  219. using ::comstl::SPF_ASYNC;
  220. using ::comstl::SPF_PURGEBEFORESPEAK;
  221. using ::comstl::SPF_IS_FILENAME;
  222. using ::comstl::SPF_IS_XML;
  223. using ::comstl::SPF_IS_NOT_XML;
  224. using ::comstl::SPF_PERSIST_XML;
  225. using ::comstl::SPF_NLP_SPEAK_PUNC;
  226. using ::comstl::SPF_NLP_MASK;
  227. using ::comstl::SPF_VOICE_MASK;
  228. using ::comstl::SPF_UNUSED_FLAGS;
  229. # endif /* !COMSTL_SPEECH_SAPI_UTIL_USE_MS_SAPI_HEADERS */
  230. #endif /* !_COMSTL_NO_NAMESPACE */
  231. /* ////////////////////////////////////////////////////////////////////// */
  232. #endif /* COMSTL_INCL_COMSTL_SPEECH_HPP_SAPI_UTIL */
  233. /* ///////////////////////////// end of file //////////////////////////// */