- Code: Select all
SpMemoryStream speechStream = new SpMemoryStreamClass();
SpVoice voice = new SpVoice();
ISpeechObjectTokens tokens = voice.GetVoices("Name=Cepstral David");
if (tokens.Count != 1)
{
throw new Exception("Failed to find Cepstral David voice");
}
voice.Voice = tokens.Item(0);
// Tell the voice events will be handled by calling WaitForNotifyEvent
ISpEventSource eventSource = (ISpEventSource)voice;
eventSource.SetNotifyWin32Event();
voice.EventInterests = SpeechVoiceEvents.SVEWordBoundary | SpeechVoiceEvents.SVEEndInputStream | SpeechVoiceEvents.SVEBookmark;
// Set the stream on the SpVoice object
voice.AudioOutputStream = (ISpeechBaseStream)speechStream;
// Speak
voice.Speak(ttsMapper.TtsString, SpeechVoiceSpeakFlags.SVSFlagsAsync | SpeechVoiceSpeakFlags.SVSFIsXML);
The exception is being thrown from the call to Speak. It consistently fails on Windows Server 2003 when running in an ASP.NET application. My same application is working on Windows 7 (in IIS 7), and the same code also works fine in a desktop application on both Windows 2003 and Windows 7. I've tried the default voice built into Windows and it works fine in every scenario.
Any ideas? I found a 4 year old thread with someone else complaining about the same problem, but there was no resolution.