Source code of Windows XP (NT5)
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.

258 lines
6.1 KiB

  1. /******************************************************************************
  2. * RegPrompt.cpp *
  3. *---------------*
  4. *
  5. *------------------------------------------------------------------------------
  6. * Copyright (C) 2000 Microsoft Corporation Date: 05/05/00
  7. * All Rights Reserved
  8. *
  9. ********************************************************************* PACOG ***/
  10. #include <windows.h>
  11. #include "sphelper.h"
  12. #include "spddkhlp.h"
  13. #include <stdio.h>
  14. #include <assert.h>
  15. #include <spunicode.h>
  16. const CLSID CLSID_PromptEng = {0x4BA3C5FA,0x2236,0x4EE7,{0xBA,0x28,0x1C,0x8B,0x39,0xD3,0x1D,0x48}};
  17. const int g_iNumDbs = 2;
  18. const int g_iNumLevelsBack = 4;
  19. struct Confg
  20. {
  21. WCHAR* voiceName;
  22. WCHAR* name409;
  23. WCHAR* contextRules;
  24. WCHAR* ttsVoice;
  25. WCHAR* promptGain;
  26. WCHAR* gender;
  27. WCHAR* age;
  28. WCHAR* language;
  29. WCHAR* vendor;
  30. WCHAR* rulesLang;
  31. WCHAR rulesPath[MAX_PATH];
  32. WCHAR* dbNames[g_iNumDbs];
  33. WCHAR dbPaths[g_iNumDbs][MAX_PATH];
  34. };
  35. static Confg g_sarahCfg =
  36. {
  37. L"MSSarah",
  38. L"MS Sarah",
  39. L"DEFAULT",
  40. L"TrueTalk Simon Min",
  41. L"1.0",
  42. L"Female",
  43. L"Adult",
  44. L"409;9",
  45. L"Microsoft",
  46. L"JScript",
  47. L"",
  48. {L"DEFAULT", L"TEST"},
  49. {L"", L""}
  50. };
  51. static HRESULT CreateVoiceSubKey( Confg* pConfg, bool fVendorDefault );
  52. //-- Static
  53. CSpUnicodeSupport g_Unicode;
  54. /*****************************************************************************
  55. * main *
  56. *-------*
  57. * Description:
  58. * Locate the abs path to prompt example database.
  59. * and register it in the system registry.
  60. *
  61. ******************************************************************* PACOG ***/
  62. int wmain (int argc, wchar_t* argv[])
  63. {
  64. HRESULT hr = S_OK;
  65. WCHAR szVoiceDataPath[MAX_PATH];
  66. CoInitialize(NULL);
  67. switch (argc)
  68. {
  69. case 2:
  70. wcscpy (szVoiceDataPath, argv[1]);
  71. wcscat (szVoiceDataPath, L"\\" );
  72. break;
  73. case 1:
  74. //-- Get the exe's location...
  75. if( !g_Unicode.GetModuleFileName(NULL, szVoiceDataPath, MAX_PATH) )
  76. {
  77. hr = HRESULT_FROM_WIN32(GetLastError());
  78. }
  79. //-- ...and derive abs path to VOICE and DICT data
  80. if( SUCCEEDED(hr) )
  81. {
  82. WCHAR *psz;
  83. // modulename is "<speech>\TTS\Prompts\RegPrompts\Objd\i386\RegPrompts.exe"
  84. // data is at "<speech>\TTS\Prompts\Voices\sw"
  85. for ( int i = 0; i < g_iNumLevelsBack; i++ )
  86. {
  87. psz = wcsrchr( szVoiceDataPath, '\\' );
  88. if (psz != 0)
  89. {
  90. *psz= 0;
  91. }
  92. else
  93. {
  94. hr = E_FAIL;
  95. break;
  96. }
  97. }
  98. }
  99. wcscat( szVoiceDataPath, L"\\Voices\\sw\\" );
  100. break;
  101. default:
  102. printf ("RegPrompts [voicePath]\n");
  103. goto exit;
  104. }
  105. wcscat( wcscpy(g_sarahCfg.rulesPath, szVoiceDataPath), L"rules.js");
  106. wcscat( wcscpy(g_sarahCfg.dbPaths[0], szVoiceDataPath), L"prompts_main.vdb");
  107. wcscat( wcscpy(g_sarahCfg.dbPaths[1], szVoiceDataPath), L"prompts_test.vdb");
  108. //-- Register the voice
  109. hr = CreateVoiceSubKey(&g_sarahCfg, FALSE);
  110. exit:
  111. CoUninitialize();
  112. if (FAILED(hr))
  113. {
  114. return -1;
  115. }
  116. return 0;
  117. }
  118. /*****************************************************************************
  119. * CreateVoiceSubKey *
  120. *--------------------*
  121. * Description:
  122. * Each TTS voice gets installed under one registry sub-key.
  123. * This function installs the single voice from the passed params.
  124. *
  125. ********************************************************************** MC ***/
  126. HRESULT CreateVoiceSubKey( Confg* pConfg, bool fVendorDefault)
  127. {
  128. HRESULT hr;
  129. CComPtr<ISpObjectToken> cpToken;
  130. CComPtr<ISpDataKey> cpDataKeyAttribs;
  131. ISpDataKey* pRulesKey = 0;
  132. ISpDataKey* pDbKey = 0;
  133. hr = SpCreateNewTokenEx(
  134. SPCAT_VOICES,
  135. pConfg->voiceName,
  136. &CLSID_PromptEng,
  137. pConfg->name409,
  138. 0x409,
  139. pConfg->name409,
  140. &cpToken,
  141. &cpDataKeyAttribs);
  142. //Set attributes
  143. if (SUCCEEDED(hr))
  144. {
  145. hr = cpDataKeyAttribs->SetStringValue(L"Name", pConfg->name409);
  146. }
  147. if (SUCCEEDED(hr))
  148. {
  149. hr = cpDataKeyAttribs->SetStringValue(L"Gender", pConfg->gender);
  150. }
  151. if (SUCCEEDED(hr))
  152. {
  153. hr = cpDataKeyAttribs->SetStringValue(L"Age", pConfg->age);
  154. }
  155. if (SUCCEEDED(hr))
  156. {
  157. hr = cpDataKeyAttribs->SetStringValue(L"Vendor", pConfg->vendor);
  158. }
  159. if (SUCCEEDED(hr))
  160. {
  161. hr = cpDataKeyAttribs->SetStringValue(L"Language", pConfg->language);
  162. }
  163. if (SUCCEEDED(hr) && fVendorDefault)
  164. {
  165. hr = cpDataKeyAttribs->SetStringValue(L"VendorDefault", L"");
  166. }
  167. // Now, the string values in the main key
  168. if (SUCCEEDED(hr))
  169. {
  170. hr = cpToken->SetStringValue(L"TTSVoice", pConfg->ttsVoice);
  171. }
  172. if (SUCCEEDED(hr))
  173. {
  174. hr = cpToken->SetStringValue(L"PromptGain", pConfg->promptGain);
  175. }
  176. // Create rules key
  177. if (SUCCEEDED (hr))
  178. {
  179. hr = cpToken->CreateKey(L"PromptRules", &pRulesKey);
  180. }
  181. if (SUCCEEDED(hr))
  182. {
  183. hr = pRulesKey->SetStringValue(L"ScriptLanguage", pConfg->rulesLang);
  184. }
  185. if (SUCCEEDED(hr))
  186. {
  187. hr = pRulesKey->SetStringValue(L"Path", pConfg->rulesPath);
  188. }
  189. if (pRulesKey)
  190. {
  191. pRulesKey->Release();
  192. }
  193. // Database Key
  194. if (SUCCEEDED(hr))
  195. {
  196. WCHAR pszKeyName[MAX_PATH];
  197. for (int i = 0; i<g_iNumDbs && SUCCEEDED(hr); i++)
  198. {
  199. swprintf(pszKeyName, L"PromptData%d", i);
  200. hr = cpToken->CreateKey(pszKeyName, &pDbKey);
  201. if (SUCCEEDED(hr))
  202. {
  203. hr = pDbKey->SetStringValue(L"Name", pConfg->dbNames[i]);
  204. }
  205. if (SUCCEEDED(hr))
  206. {
  207. hr = pDbKey->SetStringValue(L"Path", pConfg->dbPaths[i]);
  208. }
  209. if (pDbKey)
  210. {
  211. pDbKey->Release();
  212. }
  213. }
  214. }
  215. return hr;
  216. }