Getting Exception from HRESULT: 0x8004503A in Speechlib

3

I have create a application for text to speech using Speechlib SpVoice. it is working fine with windows application.

But when i Create windows service using same code . It give me this error

System.Runtime.InteropServices.COMException (0x8004503A): Exception from HRESULT: 0x8004503A at SpeechLib.ISpeechVoice.Speak

this is my code

 public partial class LEDPlayService : ServiceBase
    {
        static int MessageID = 0;
        static SpeechLib.SpVoice VoiceObj = new SpeechLib.SpVoice();
        static System.Timers.Timer myTimer = new System.Timers.Timer();
        protected override void OnStart(string[] args)
         {

            myTimer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
            //This statement is used to set interval to 1 minute (= 60,000 milliseconds)
            myTimer.Interval = 60* 1000;
            // enabling the timer
            myTimer.Enabled = true; ;
            myTimer.AutoReset = false;
        }

        private static void OnElapsedTime(object source, ElapsedEventArgs e)
        {
            ((System.Timers.Timer)source).Stop();
            myTimer.Enabled = false; ;
            bool result =PlayAudio("Hello prithvi");
            ((System.Timers.Timer)source).Start();
            myTimer.Enabled = true;

            // TraceService(""+DateTime.Now.TimeOfDay);
        }

        public static bool PlayAudio(string text)
        {
          bool res = false;
            try
            {
                VoiceObj.Speak(text, SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault);
                res = true;
            }
            catch(Exception e)
            {
                TraceService("error in sound........."+e.InnerException+e.Message+"   "+e.ToString());
                res = false;
            }
            return res;
        }

    }

Please help me..

c#
windows-services
text-to-speech
speech-synthesis
asked on Stack Overflow Oct 8, 2014 by Prithvi Raj Nandiwal • edited Oct 15, 2014 by Prithvi Raj Nandiwal

1 Answer

4

It is a low-level error returned by a SAPI call, SPERR_NOT_FOUND. You are making it excessively difficult to answer the question reliably when you don't post a snippet and the stack trace of the exception. Or how you even observed it, these COM errors are normally translated to .NET exceptions.

The error code doesn't much more than "can't find what's needed to do the job". The call context ought to make it bit clear what might be missing, but we can't see this. Having this code run in a service is a cue of sorts. The user account under which this service runs matters, a lot of config for System.Speech is stored in the registry and a service is going to have a hard time finding config that's stored in HKCU instead of HKLM. Not uncommon for example if you purchased a voice and registered it. And it might well have a hard time finding hardware, like a microphone or speaker.

So first thing to try is to configure the service to run with a specific user account (like yours) instead of the default System account. Next thing to try is to use SysInternals' Process Monitor, you'll see your program search the registry for keys. Compare a good trace, one you got from running it as a desktop program, against the trace you got when running it from the service. And update your question with the required info to get a better answer.

answered on Stack Overflow Oct 10, 2014 by Hans Passant

User contributions licensed under CC BY-SA 3.0