/////Accesso al motore TTS (Text To Speech) SAPI di Microsoft - Fischetti P. #include #include #include #include "sapi.h" #include #include using namespace std; #pragma comment(lib, "ole32.lib") wchar_t* charToWChar(const char* text) { size_t size = strlen(text) + 1; wchar_t* wa = new wchar_t[size]; mbstowcs(wa,text,size); return wa; } int main(int argc, char* argv[]) { string sTxt; wchar_t *wTxt = NULL; ISpVoice * pVoice = NULL; if (FAILED(::CoInitialize(NULL))) return FALSE; HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice); if( SUCCEEDED( hr ) ) { if (1 == argc) { while (cin >> sTxt) { //cout << sTxt << endl; wTxt = charToWChar(sTxt.c_str()); hr = pVoice->Speak(wTxt, 0, NULL); delete[] wTxt; wTxt = NULL; } } else { wTxt = charToWChar(argv[1]); hr = pVoice->Speak(wTxt, 0, NULL); delete[] wTxt; wTxt = NULL; } pVoice->Release(); pVoice = NULL; } ::CoUninitialize(); return 0; }