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