var speechEngine = new SpVoiceClass();
SetVoice(speechEngine, job.Voice);
var fileMode = SpeechStreamFileMode.SSFMCreateForWrite;
var fileStream = new SpFileStream();
try
{
fileStream.Open(filePath, fileMode, false);
speechEngine.AudioOutputStream = fileStream;
speechEngine.Speak(job.Script, SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak | SpeechVoiceSpeakFlags.SVSFDefault); //TODO: Change to XML
//Wait for 15 minutes only
speechEngine.WaitUntilDone((uint)new TimeSpan(0, 15, 0).TotalMilliseconds);
}
finally
{
fileStream.Close();
}
這個確切的代碼在一個WinForm的應用程序,但是當我運行一個Web服務中,我得到以下C#SAPI在Web服務
System.Runtime.InteropServices.COMException was unhandled
Message="Exception from HRESULT: 0x80045003"
Source="Interop.SpeechLib"
ErrorCode=-2147201021
沒有人有任何想法可能是造成這個錯誤?該錯誤代碼的含義
SPERR_UNSUPPORTED_FORMAT
爲了完整這裏是SetVoice方法
void SetVoice(SpVoiceClass speechEngine, string voiceName)
{
var voices = speechEngine.GetVoices(null, null);
for (int index = 0; index < voices.Count; index++)
{
var currentToken = (SpObjectToken)voices.Item(index);
if (currentToken.GetDescription(0) == voiceName)
{
speechEngine.SetVoice((ISpObjectToken)currentToken);
return;
}
}
throw new Exception("Voice not found: " + voiceName);
}
我已經給予了充分的用戶訪問該文件夾C:\ Temp其中的文件將被寫入。任何幫助,將不勝感激!
哪一行產生錯誤? – ChrisF 2009-10-28 20:51:18
SpeechEngine.Speak導致錯誤 – 2009-10-29 10:20:00