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上给予USERS完全访问权限。任何帮助将不胜感激!

有帮助吗?

解决方案

我不认为System.Speech在Windows服务中有效。它看起来像有一个依赖于Shell ,这是服务无法使用的。尝试与SAPI的C ++接口互操作。 System.Runtime.InteropServices中的某些类可能对此有所帮助。

其他提示

我们的命名约定要求我们使用非标准文件扩展名。这在Winforms应用程序中工作正常,但在我们的Web服务器上失败。将文件扩展名更改回.wav为我们解决了此错误。

确保在SPFileStream对象上显式设置格式。 ISpAudio :: SetState (被调用如果不支持该格式,则来自speechEngine.Speak的较低层将返回 SPERR_UNSUPPORTED_FORMAT

我刚刚获得了webservice来生成一个控制台应用程序来进行处理。 PITA: - )

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top