C++ sapi: User input, edit voice out -
#include <sapi.h> #include <string> #include <iostream> //user inputs said// int main(int argc, char* argv[]) { ispvoice * pvoice = null; if (failed(::coinitialize(null))) return false; hresult hr = cocreateinstance(clsid_spvoice, null, clsctx_all, iid_ispvoice, (void **)&pvoice); if (succeeded(hr)) { std::wstring input; while (true) { std::cout << "enter text:\n"; std::getline(std::wcin, input); hr = pvoice->speak(input.c_str(), 0, null); } } pvoice->release(); pvoice = null; ::couninitialize(); return 0; }
the code above allows user input want have spoken , works perfectly.
below msdn method of changing pitch , other similar action done same way.
hr = pvoice->speak(l"this sounds normal <pitch middle = '-10'/> pitch drops half way through", spf_is_xml, null );
i want change pitch, can't figure out how same action code have.
i know post 22-23 days old, decided take shot @ it. haven't been able voices @ disposal change pitch on fly, ms anna can.
#include <sapi.h> #include <sphelper.h> #include <string> #include <conio.h> void setvoice(ccomptr<ispvoice> _cpvoice, std::wstring _voicename) { ienumspobjecttokens *pprofileenum; spenumtokens(spcat_voices, null, null, &pprofileenum); unsigned long l; pprofileenum->getcount(&l); for(unsigned long = 0; < l; ++i) { ccomptr<ispobjecttoken> it; pprofileenum->item(i, &it); wchar *wptr; it->getid(&wptr); cspdynamicstring dstrdefaultname; spgetdescription(it, &dstrdefaultname); if(wcsncmp(dstrdefaultname, _voicename.c_str(), _voicename.size()) == 0){ _cpvoice->setvoice(it); } } } int main(int argc, char* argv[]) { coinitialize(0); ccomptr<ispvoice> cpvoice; ccomptr<ispaudio> cpoutaudio; hresult hr = cpvoice.cocreateinstance(clsid_spvoice); spcreatedefaultobjectfromcategoryid(spcat_audioout, &cpoutaudio); if(nullptr != cpvoice) { hr = cpvoice->setoutput(cpoutaudio, false); } setvoice(cpvoice, l"microsoft anna - english (united states)"); if(cpvoice) { cpvoice->speak(l"<pitch absmiddle=\"+10\">this high pitched voice</pitch> <pitch absmiddle=\"-10\"> pitch drops half way through</pitch>", svsfisxml | svsfpurgebeforespeak, null); } puts("press key continue..."); getch(); return 0; }
Comments
Post a Comment