다음 기능을 사용하여 텍스트를 웨이브 파일로 변환하려고합니다. 기본 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