public

Subversion Repositories:
[/] [Say++/] [Say++/] [Say++.cpp] - Rev 23

Compare with Previous - Blame


// Say++.cpp : Defines the entry point for the console application.

// Copyright 2007-2009 Martin Krolik
/*
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/



#include "stdafx.h"

using namespace sapi;

int _tmain(int argc, _TCHAR* argv[])
{
        int iSize = 0;
        for (int i = 0; i < argc; i++)
        {
                iSize = iSize + _tcslen(argv[i]) + 1;
        }

        TCHAR * wstrText ; 

        wstrText = new TCHAR[iSize];

        ZeroMemory(wstrText, sizeof(wstrText));

        for (int i = 1; i < argc; i++)
        {
                _tcscat(wstrText, argv[i]);
                _tcscat(wstrText, L" ");
        }
        
        HRESULT hr = CoInitialize(NULL); 
        
        CLSID clsid ;
        hr = CLSIDFromProgID(OLESTR("SAPI.SpVoice"), &clsid);

        if (FAILED(hr))
        {
                printf("Failed to retrive CLSID for COM server");
                return -1;
        }

        ISpVoice * spvoice;

        hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, __uuidof(ISpVoice), (LPVOID *)&spvoice);
        
        if (FAILED(hr))
        {
                printf("Failed to start COM server");
                return -1;
        }


        unsigned long ulngVoiceNumber = 0;

        spvoice->Speak(wstrText, SpeechVoiceSpeakFlags::SVSFDefault, &ulngVoiceNumber);

        CoUninitialize();

        delete [] wstrText;
        
        return 0;
}