一个简单的网页读字符串 SpeechLib

2018-06-22 06:38:47来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

//引用组件:Interop.SpeechLib.dll
//导入空间:SpeechLib

 

//引用组件:Interop.SpeechLib.dll
//导入空间:SpeechLib

前面设置内容引用别人博客

//1.SpVoice voice = new SpVoice();

//2.voice.Speak(txt.Text, SpeechVoiceSpeakFlags.SVSFDefault); //同步朗读

//3.voice.Speak(txt.Text, SpeechVoiceSpeakFlags.SVSFlagsAsync); //异步朗读

//voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);//设置中文语音
//voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(1);设置英文语音


//错误修改:VS2010中 错误无法嵌入互操作类型“SpeechLib.SpVoiceClass”。请改用适用的接口
//解决方案:选中项目中引入的dll,鼠标右键,选择属性,把“嵌入互操作类型”设置为False。

//异常来自 HRESULT:0x8004503异常信息。一般是由Windows Audio服务没有开启造成的,尤其是win2003默认不开Windows Audio服务。
//1)请确认Windows Audio(AudioSrv)服务启动。
//进入cmd 输入net start AudioSrv
//2)声卡驱动安装成功。"

功能强大之处在于TTS能识别XML标记,通过给文本加上XML标记,我们让TTS朗读出更加符合语言阅读习惯的句子。例如:
<volume level="60"></volume> 用于设置文本朗读的音量;
<rate absspeed="1"/>、<rate speed="5"/> 分别用于设置文本朗读的绝对速度和相对速度;
<pitch absmiddle="2"/>、<pitch middle="5"/> 分别用于设置文本朗读的绝对语调和相对语调;
<emph></emph> 在他们之间的句子被视为强调;
<spell></spell> 可以将单词逐个字母的拼写出来;
<silence msec="500"/> 表示停止发声,并保持500微秒;
<context id="date_mdy">02/03/07</context> 可以按要求朗读出日期
<voice required="Language=409"></voice> 用于设置朗读所用的语言,其中409表示使用英语,804表示使用汉语,而411表示日语。
后台:
 1   public ActionResult speak(string speechSounds)
 2         {
 3             SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
 4             SpVoice spVoice = new SpVoice();
 5             spVoice.Rate = spVoice.Rate - 5;
 6             if (spVoice.Volume < 100)
 7             {
 8                 spVoice.Volume = spVoice.Volume + 10;
 9             }
10 
11             if (spVoice.Volume > 9)
12             {
13                 spVoice.Volume = spVoice.Volume - 10;
14             }
15             spVoice.Speak("<lang langid=\"804\">" + speechSounds + "告警</lang>", SpFlags);
16             return Content("成功");
17         }
View Code

前端:

 1      function a() {
 2             var url = '/Alarm/speak';
 3             var speechSounds = "你的剑就是我的剑dfdf1234567899652554412235441235"
 4             $.ajax({
 5                 type: "POST",
 6 
 7                 url: url,
 8                 data: { speechSounds: speechSounds },
 9                 success: function (msg) {
10                   
11                 }
12 
13             })
View Code

 

 

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:.NET基础之迭代器

下一篇:编码表理解