0
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 服务中运行它时,我得到以下

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 上的用户的完全访问权限。任何帮助,将不胜感激!

4

4 回答 4

1

我不认为 System.Speech 在 Windows 服务中工作。看起来对 Shell 存在依赖关系,而服务对它不可用。尝试与 SAPI 的 C++ 接口互操作。System.Runtime.InteropServices 中的某些类可能对此有所帮助。

于 2009-10-28T22:42:15.130 回答
1

Our naming convention requires us to use a non-standard file extension. This works fine in a Winforms app, but failed on our web server. Changing the file extension back to .wav solved this error for us.

于 2011-07-25T15:55:06.653 回答
0

Make sure you explicitly set the format on the SPFileStream object. ISpAudio::SetState (which gets called in a lower layer from speechEngine.Speak) will return SPERR_UNSUPPORTED_FORMAT if the format isn't supported.

于 2009-10-29T18:18:17.193 回答
0

I just got the webservice to spawn a console app to do the processing. PITA :-)

于 2009-10-30T18:51:50.107 回答