我想使用以下功能將文本轉換爲波形文件。如果從主UI線程調用,它工作正常。但從另一個線程調用時會失敗。如何從多線程函數調用它?如何使用SAPI和多線程將文本轉換爲Wave?
void Pan_Channel::TextToPlaybackFile(CString Text, CString FileName)
{
// Result variable
HRESULT Result = S_OK;
// Voice Object
CComPtr<ISpVoice> cpVoice;
// Create a SAPI Voice
Result = cpVoice.CoCreateInstance(CLSID_SpVoice);
// Audio format
CSpStreamFormat cAudioFmt;
// Set the audio format
if(SUCCEEDED(Result))
{
Result = cAudioFmt.AssignFormat(SPSF_8kHz16BitMono);
}
// File Stream
CComPtr<ISpStream> cpStream;
// Call SPBindToFile, a SAPI helper method, to bind the audio stream to the file
if(SUCCEEDED(Result))
{
Result = SPBindToFile(FileName, SPFM_CREATE_ALWAYS, &cpStream,
&cAudioFmt.FormatId(), cAudioFmt.WaveFormatExPtr());
}
// set the output to cpStream so that the output audio data will be stored in cpStream
if(SUCCEEDED(Result))
{
Result = cpVoice->SetOutput(cpStream, TRUE);
}
// Speak the text syncronously
if(SUCCEEDED(Result))
{
Result = cpVoice->Speak(Text.AllocSysString(), SPF_DEFAULT, NULL);
}
// close the stream
if(SUCCEEDED(Result))
{
Result = cpStream->Close();
}
// Release stream
cpStream.Release();
// Release voice object
cpVoice.Release();
}
定義失敗。什麼失敗。如果有的話,你會得到什麼錯誤信息? – Glen 2009-10-05 16:38:31