title: C# SAPI in a web service
body: <pre><code>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();
  }
  </code></pre>
  
  <p>This exact code works in a WinForm app, but when I run it inside a webservice I get the following</p>
  
  <pre><code>System.Runtime.InteropServices.COMException was unhandled
    Message="Exception from HRESULT: 0x80045003"
    Source="Interop.SpeechLib"
    ErrorCode=-2147201021
  </code></pre>
  
  <p>Does anyone have any ideas what might be causing this error?  The error code means</p>
  
  <pre><code>SPERR_UNSUPPORTED_FORMAT
  </code></pre>
  
  <p>For completeness here is the SetVoice method</p>
  
  <pre><code>void SetVoice(SpVoiceClass speechEngine, string voiceName)
  {
      var voices = speechEngine.GetVoices(null, null);
      for (int index = 0; index &lt; 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);
  }
  </code></pre>
  
  <p>I have given full access to USERS on the folder C:\Temp where the file is to be written.  Any help would be appreciated!</p>