//引用组件: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)声卡驱动安装成功。"
后台: 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 } 前端: 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 }) |