// This is the constructor of a class that has been exported.
// see CMTTSEngine.h for the class definition
CCMTTSEngine::CCMTTSEngine()
{
m_bPause = FALSE; // pause audio?
m_bStop = TRUE; // stop audio?
// Get default output format index
if (SUCCEEDED(hr))
{
CComPtr<ISpStreamFormat> cpStream;
HRESULT hrOutputStream = m_cpVoice->GetOutputStream(&cpStream);
if (hrOutputStream == S_OK)
{
CSpStreamFormat Fmt;
hr = Fmt.AssignFormat(cpStream);
if (SUCCEEDED(hr))
{
SPSTREAMFORMAT eFmt = Fmt.ComputeFormatEnum();
for (int i = 0; i<NUM_OUTPUTFORMATS; i++ )
{
if (g_aOutputFormat[i] == eFmt )
{
m_nFormatIndex = i;
break;
}
}
}
}
}
// Get all token engine
if (SUCCEEDED(hr))
{
ISpObjectToken * pToken; // NOTE: Not a CComPtr! Be Careful.
CComPtr<IEnumSpObjectTokens> cpEnum;
hr = SpEnumTokens(SPCAT_VOICES, NULL, NULL, &cpEnum);
if (hr == S_OK)
{
bool fSetDefault = false;
while (cpEnum->Next(1, &pToken, NULL) == S_OK)
{
CSpDynamicString dstrDesc;
hr = SpGetDescription(pToken, &dstrDesc);
if (SUCCEEDED(hr))
{
USES_CONVERSION;
//Determine if it is the current voice
CComPtr<ISpObjectToken> pOldToken;
hr = m_cpVoice->GetVoice( &pOldToken );
if (SUCCEEDED(hr))
{
if (pOldToken != pToken)
{
// Stop speaking. This is not necesary, for the next call to work,
// but just to show that we are changing voices.
hr = m_cpVoice->Speak( NULL, SPF_PURGEBEFORESPEAK, 0);
// And set the new voice on the global voice object
if (SUCCEEDED (hr) )
{
hr = m_cpVoice->SetVoice( pToken );
}
}
}
return hr;
}
void CCMTTSEngine::SetEngine(int nIndex)
{
if (m_cpVoice == NULL)
return;
if (nIndex < 0 || nIndex >= m_nTotolTTSEngine)
return;
if (m_nCurrentEngine == nIndex)
return;
m_nCurrentEngine = nIndex;
VoiceChange();
}
void CCMTTSEngine::SetVolume(USHORT uVolume)
{
if (m_cpVoice == NULL)
return;
if (uVolume < SPMIN_VOLUME || uVolume > SPMAX_VOLUME)
return;