I am trying to convert text to a wave file using the following function. It works great if called from the main user interface thread. But it does not work when called from another thread. What to call it from a multithreaded function?
void Pan_Channel::TextToPlaybackFile( CString Text, CString FileName )
{
HRESULT Result = S_OK;
CComPtr<ISpVoice> cpVoice;
Result = cpVoice.CoCreateInstance( CLSID_SpVoice );
CSpStreamFormat cAudioFmt;
if( SUCCEEDED( Result ) )
{
Result = cAudioFmt.AssignFormat( SPSF_8kHz16BitMono );
}
CComPtr<ISpStream> cpStream;
if( SUCCEEDED( Result ) )
{
Result = SPBindToFile( FileName, SPFM_CREATE_ALWAYS, &cpStream,
&cAudioFmt.FormatId(), cAudioFmt.WaveFormatExPtr() );
}
if( SUCCEEDED( Result ) )
{
Result = cpVoice->SetOutput( cpStream, TRUE );
}
if( SUCCEEDED( Result ) )
{
Result = cpVoice->Speak( Text.AllocSysString(), SPF_DEFAULT, NULL );
}
if( SUCCEEDED( Result ) )
{
Result = cpStream->Close();
}
cpStream.Release();
cpVoice.Release();
}
source
share