在做语音播报功能的时候遇到下面的错误,摸索很久
检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80070005
在网上搜索说在VS中添加Microsoft Speech Object Library引用,但是在COM中找了半天都没有找到这个,没有找到这个咱也不怕,去百度下载一个SpeechLib.dll并且引入就可以了
播报语音的方法有两种
1.using System.Speech.Synthesis;
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Speech.Synthesis; 6 7 namespace Com.HuaQin.Restaurant.Tools 8 { 9 10 11 12 public class SpeechUtil 13 { 14 15 public static void SpeekText(string sptext) 16 { 17 try 18 { 19 SpeechSynthesizer reader = new SpeechSynthesizer(); 20 reader.SpeakAsync(sptext); 21 } 22 catch (Exception ex) 23 { 24 } 25 26 } 27 } 28 }
但是这种方法还是失败了!没有测试成功,
2.using SpeechLib;
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using SpeechLib; 6 7 namespace Com.HuaQin.Restaurant.Tools 8 { 9 public class SpeechUtil 10 { 11 public static void SpeekText(string sptext) 12 { 13 try 14 { 15 SpVoice voice = new SpVoice(); 16 voice.Speak(sptext, SpeechVoiceSpeakFlags.SVSFlagsAsync); 17 //SpeechSynthesizer reader = new SpeechSynthesizer(); 18 //reader.SpeakAsync(sptext); 19 } 20 catch (Exception ex) 21 { 22 } 23 24 } 25 } 26 }
这个方法亲测是可以的!