54 std::wstring s2ws(
const std::string& s)
57 int slength = (int)s.length() + 1;
58 len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
59 wchar_t* buf =
new wchar_t[len];
60 MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
65 std::string ws2s(LPCWSTR s)
67 char *pmbbuf = (
char *)malloc(100);
68 wcstombs(pmbbuf, s, 100);
74 int main(
int argc,
char* argv[])
77 std::string voice =
"iCub_eng";
80 std::cout <<
"Voice is: " << voice << std::endl;
81 std::cout <<
"TODO : select the right token from this option." << voice << std::endl;
83 std::string textInput;
84 std::getline(std::cin, textInput);
85 std::cout <<
"Text is: " << textInput << std::endl;
87 if (::CoInitializeEx(NULL, COINIT_MULTITHREADED) == S_OK)
90 CComPtr<IEnumSpObjectTokens> cpIEnum;
91 CComPtr<ISpObjectToken> cpToken;
92 CComPtr<ISpVoice> cpVoice;
95 hr = SpEnumTokens(SPCAT_VOICES, L
"Language=409", L
"Gender=Female;", &cpIEnum);
100 hr = cpIEnum->Next(1, &cpToken , NULL);
106 hr = cpVoice.CoCreateInstance(CLSID_SpVoice);
112 hr = cpVoice->SetVoice(cpToken);
118 hr = cpVoice->SetOutput(NULL, TRUE);
124 hr = cpVoice->Speak(s2ws(textInput).c_str(), NULL, NULL);