Search code examples
c++windowsvisual-studio-2010sapi

How to setup SAPI with Visual C++ 2010 Express?


I need to know how can I set up SAPI (Windows Speech API) with visual C++ 2010 express. I got to know Windows 7 comes with built in SAPI libs, and I am using windows 7. However, I downloaded SAPI 5.1 in case it is needed. MS instructions about setting up SAPI with VS is pretty old, which didn't work for me.

How can I set it up with VS 2010 Express, because I need to apply those settings to QT and proceed with my final year project.


Solution

  • Well what do you know. I took code from your previous question, and removed the ATL stuff (ATL not supported on Visual Studio Express 2010). I was left with this

    #include <windows.h>
    #include <sapi.h>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char* argv[])
    {
        cout << "Hello" << endl;
        ISpVoice * pVoice = NULL;
    
        if (FAILED(::CoInitialize(NULL)))
            return FALSE;
    
        HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
        if( SUCCEEDED( hr ) )
        {
            cout << "Succeeded" << endl;
            hr = pVoice->Speak(L"Hello world", 0, NULL);
            pVoice->Release();
            pVoice = NULL;
        }
        else
        {
            cout << "Not succeeded" << endl;
        }
    
        ::CoUninitialize();
        return TRUE;
    }
    

    I created a standard Windows Console Application project and used this code as the only source file. Compiled and ran it and it worked. It spoke! In a female voice.

    I've done zero set up at all. So it obviously works out the box. I never knew about this library before.

    I have Windows 7 and VS 2010 express.