//引用组件: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)声卡驱动安装成功。"
class="csharp plain" style="margin: 0px !important; padding: 0px !important; outline: 0px !important; border-radius: 0px !important; border: 0px currentColor !important; left: auto !important; top: auto !important; width: auto !important; height: auto !important; text-align: left !important; right: auto !important; bottom: auto !important; color: #000000 !important; line-height: 1.8em !important; overflow: visible !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 12px !important; font-style: normal !important; font-weight: normal !important; vertical-align: baseline !important; float: none !important; white-space: pre-wrap; position: static !important; min-height: inherit !important; box-sizing: content-box !important; background-image: none !important;">功能强大之处在于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表示日语。
后台:
logs_code_hide('7610be96-ea27-4635-b482-431b46d12c8b',event)" src="/Upload/Images/2014112119/2B1B950FA3DF188F.gif" alt="" />
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