TTS multi-language (2)

Source: Internet
Author: User

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/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.