Please give me code demo by C or C++ : Speak file text !

HRESULT             hr = S_OK;
CComPtr <ISpVoice>       cpVoice;
CComPtr <ISpObjectToken> cpToken;
CComPtr <IEnumSpObjectTokens>    cpEnum;

//Create a SAPI voice
hr = cpVoice.CoCreateInstance( CLSID_SpVoice );

//Enumerate voice tokens with attribute "Name=Microsoft Sam” 
if(SUCCEEDED(hr))
{
    hr = SpEnumTokens(SPCAT_VOICES, L"Name=Microsoft Sam", NULL, &cpEnum);
}

//Get the closest token
if(SUCCEEDED(hr))
{
    hr = cpEnum ->Next(1, &cpToken, NULL);
}

//set the voice 
if(SUCCEEDED(hr))
{
    hr = cpVoice->SetVoice( cpToken);
}

//set the output to the default audio device
if(SUCCEEDED(hr))
{
    hr = cpVoice->SetOutput( NULL, TRUE );
}

//Speak the text file (assumed to exist)
if(SUCCEEDED(hr))
{
    hr = cpVoice->Speak( L”c:\\ttstemp.txt”,  SPF_IS_FILENAME, NULL );
}   

//Release objects
cpVoice.Release ();
cpEnum.Release();
cpToken.Release();

it is not run, maybe It have not file *.wav ?
Who help me run it !

If I want It speak file text Unicode ! How do code it ?

For anyone confused on his question, he is asking about how to correctly use the SAPI in Microsoft Windows.

Here is a tutorial straight from Microsoft explaining step by step how to do this: http://msdn.microsoft.com/en-us/library/ms720163%28VS.85%29.aspx

Here is an easy way to do it if you are using Visual Studio with C#: http://windowscoding.com/blogs/blake/archive/2006/11/01/How-to-use-Microsofts-Speech-API-in-a-managed-application.aspx

Thanks your reply all !
It's run ok !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.