There are three methods for text-to-speech reading in C #, and one of these methods is described below.
在项目中引用System.Speech,具体方法为右键点击项目 > 添加引用 > .Net > 找到System.Speech点击确定。下面为实现代码,将以控制台程序为例:
usingSystem.Speech.Synthesis; namespaceconsoleapplication1{classprogram{Static voidMain (string[] args) {SpeechSynthesizer Voice=NewSpeechSynthesizer ();//Create a speech instanceVoice. Rate =-1;//set speech speed, [ -10,10]Voice. Volume = -;//set volume, [0,100]Voice. Speakasync ("Hellow Word");//plays the specified string, which is read asynchronously//The following code is for some SpeechSynthesizer properties to see if the actual situation requires using theVoice. Dispose ();//Release all voice resourcesVoice. Speakasynccancelall ();//Cancel read aloudVoice. Speak ("Hellow Word");//Synchronous ReadingVoice. Pause ();//Pause ReadingVoice. Resume ();//Continue reading } } }
C # to read text in speech