C# 导入speech lib,阅读文本信息,support text to speech


1. 第一步,需要三个dll

using System.Speech.Synthesis;
using System.Speech.Recognition;
using SpeechLib;

SpeechLib的导入有点不太好找,参考下图(图片排版不太好)

 

 

 

 

 

 

 2.准备个测试demo

///获取计算机本身自带的语言系统

public static List<string> GetInstalledVoiceIdList()
        {
            List<string> resultList = new List<string>();
            try
            {
                SpVoice voice = new SpVoice();
                ISpeechObjectTokens ss = voice.GetVoices(string.Empty, string.Empty);
                if (ss != null && ss.Count > 0)
                {
                    for (int i = 0; i < ss.Count; i++)
                    {
                        resultList.Add(ss.Item(i).Id);
                    }
                }
            }
            catch (Exception)
            {
            }
            return resultList;
        }

//指定语言Speak方法中第二个参数,指定语言,从上段代码中获取到中文系统的index 是3,所以将传递3进行阅读

voice.Speak(txt.Text, GetInstalledVoiceIdList()[3]);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM