SpeechLib 调用异常

lanwah 2013-09-22 03:50:44
// SpeechLib 使用

SpeechLib.SpVoice voice = new SpVoiceClass();
SpeechLib.SpeechVoiceSpeakFlags sVSFDefault = SpeechVoiceSpeakFlags.SVSFDefault;
voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
string sContent = @"本月王菲与李亚鹏突爆离婚,日前有香港媒体报道指王菲因潜心修佛,看淡尘世七情六欲,毅然与李亚鹏斩断8年夫妻情丝。据报道,在前日起先后有好友及有缘人表示,收到早前王菲亲手抄写的佛经作为中秋节礼物。其中一位网友谓:“收到了王菲亲书亲印的经书。精美无比,心生欢喜。”";
voice.Speak(sContent, sVSFDefault);

以上代码在WinForm或ConsoleApplication中可以正常运行并可以朗读上面的文字,可是在windows 服务中,却不能播发此声音。
服务中代码如下:

System.Timers.Timer tmrJob = new Timer();

public Service1()
{
InitializeComponent();

//
this.tmrJob.Interval = 1000 * 30;
this.tmrJob.AutoReset = true;
this.tmrJob.Elapsed += new ElapsedEventHandler(tmrJob_Elapsed);
}

private void tmrJob_Elapsed(object sender, ElapsedEventArgs e)
{
SpeechLib.SpVoice voice = new SpVoiceClass();
SpeechLib.SpeechVoiceSpeakFlags sVSFDefault = SpeechVoiceSpeakFlags.SVSFDefault;
voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
string sContent = @"本月王菲与李亚鹏突爆离婚,日前有香港媒体报道指王菲因潜心修佛,看淡尘世七情六欲,毅然与李亚鹏斩断8年夫妻情丝。据报道,在前日起先后有好友及有缘人表示,收到早前王菲亲手抄写的佛经作为中秋节礼物。其中一位网友谓:“收到了王菲亲书亲印的经书。精美无比,心生欢喜。”";
voice.Speak(sContent, sVSFDefault);
}

protected override void OnStart(string[] args)
{
this.tmrJob.Start();
}

protected override void OnStop()
{
this.tmrJob.Stop();
}

执行这句代码voice.Speak(sContent, sVSFDefault); 出现异常,COMException。
...全文
307 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lanwah 2013-10-21
  • 打赏
  • 举报
回复
现在愿意回答的人都这么少啊。 哎 .... 有问题都需要自己去研究。 给出一种解决方案: 不用第三方提供的Interop.SpeechLib.dll ;使用.net提供的SpeechSynthesizer去实现就好了。算是结贴了吧。
lanwah 2013-09-22
  • 打赏
  • 举报
回复
Interop.SpeechLib.dll 可以到网上自己下载。

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧