6: Get the local region option ID
Langid lid = getuserdefaultlangid ();
The returned value is a hexadecimal region value. For example, 0x409 is English and 0x804 is Chinese.
7. Select the TTS voice based on the region options (PS: The machine has a TTS Language Pack that supports this region)
Int _ tmain (INT argc, _ tchar * argv []) <br/>{< br/> ispvoice * pvoice = NULL; <br/> hresult hR = s_ OK; <br/> ccomptr <ispdatakey> cptokenkey; <br/> ccomptr <strong> cpvoicetoken; <br/> ccomptr <ienumspobjecttokens> cpenum; <br/> ulong ulcount = 0; <br/> If (failed (: coinitialize (null) <br/> return false; <br/> hR = cocreateinstance (clsid_spvoice, null, clsctx_all, iid_ispvoice, (void **) & pvoice); <br/> I F (succeeded (HR) <br/>{< br/> // enumerate the available voices <br/> If (succeeded (HR )) <br/> hR = spenumtokens (spcat_voices, null, null, & cpenum); <br/> // get the number of voices <br/> If (succeeded (HR )) <br/> hR = cpenum-> getcount (& ulcount); <br/> bool bfind = false; <br/> langid lid = getuserdefaultlangid (); <br/> // obtain a list of available voice tokens, set the voice to the token, and call speak <Br/> while (succeeded (HR) & ulcount --) <br/>{< br/> cpvoicetoken. release (); <br/> If (succeeded (HR) <br/> hR = cpenum-> next (1, & cpvoicetoken, null ); </P> <p> wchar * strtemp = NULL; <br/> int iindex = 0; <br/> cptokenkey. release (); <br/> hresult HR2 = cpvoicetoken-> openkey (_ T ("attributes"), & cptokenkey); <br/> If (succeeded (HR2 )) <br/>{< br/> cptokenkey-> getstringvalue (_ T ("language"), & strtemp); <br/> LAN GID ltempid = (langid) wcstol (strtemp, null, 16); <br/> If (ltempid = lid) <br/>{< br/> pvoice-> setvoice (cpvoicetoken); <br/> break; <br/>}< br/> hR = pvoice-> speak (L "Hi, my name is Li Jiangong, I hope to make friends with you! Haha ", 0, null); <br/> pvoice-> release (); <br/> pvoice = NULL; <br/>}< br/> :: couninitialize (); <br/> return 0; <br/>}< br/>