我已经使用Speechlib SpVoice为文本到语音创建了一个应用程序。它在windows应用程序中运行得很好。
但是当我使用相同的代码创建windows服务时。它给了我这个错误
System.Runtime.InteropServices.COMException ( 0x8004503A ):HRESULT异常:0x8004503A在SpeechLib.ISpeechVoice.Speak
这是我的密码
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;
}
}
请帮帮我..。
发布于 2014-10-10 13:58:08
这是一个由SAPI调用SPERR_NOT_FOUND返回的低级错误.当您不发布代码片段和异常的堆栈跟踪时,您将非常难以可靠地回答这个问题。或者您如何观察它,这些COM错误通常被转换为.NET异常。
错误代码不会比“找不到完成任务所需的内容”更多。调用上下文应该清楚地说明可能缺少什么,但我们看不到这一点。在服务中运行此代码是一种提示。运行此服务的用户帐户很重要,System.Speech的许多配置都存储在注册表中,服务将很难找到存储在HKCU而不是HKLM中的配置。例如,如果您购买了一个声音并注册了它,这并不少见。它很可能很难找到硬件,如麦克风或扬声器。
因此,首先要尝试的是将服务配置为使用特定的用户帐户(如您的帐户)来运行,而不是使用默认的系统帐户。接下来要尝试的是使用SysInternals的Process,您将看到您的程序在注册表中搜索键。比较一个好的跟踪,一个您从桌面程序运行它得到的跟踪,与您从服务运行它时得到的跟踪进行比较。并更新您的问题与所需的信息,以获得更好的答案。
https://stackoverflow.com/questions/26249292
复制相似问题