SpeechLib 调用异常
// 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。
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。
...全文
相关推荐
SpeechLib文字转语音
这篇文章将深入探讨如何通过Winform界面调用此库,实现文本到语音的转换。首先,我们来理解`Interop.SpeechLib.dll`是什么。
C#与SpeechLib.dll文本转语音实战指南
文本转语音(Text-to-Speech, TTS)技术是将计算机系统中存储的文本信息转换为可听的语音输出的过程。该技术广泛应用于语音合成、语音导航、盲人辅助阅读和其他需要交互式语音反馈的场景中。C#作为一门功能丰富的编程语言,支持多种TTS库和工具,其中SpeechLib.dll是一个广泛使用的库,它提供了一套用于实现TTS的接口和对象。TTS在C#中的应用使得开发者能够创建各种动态交互式应用程序,如阅读器、提示系统和语音控制系统。
语音支持库
**错误处理和调试**:在使用"Interop.SpeechLib.dll"时,务必包含适当的错误处理代码,因为非托管代码可能会抛出异常。
CustomMarshalers.zip
`interop.speechlib.dll`是一个.NET兼容的包装器,它允许C#代码调用由C++或COM接口提供的原生函数。
SpeechLib.rar
在Unity项目中,我们需要将这些dll文件导入到Assets目录下,以便在代码中调用相关API。导入dll文件后,接下来就是如何在Unity脚本中使用SpeechLib。


