簡單C#文字轉語音


跟着微軟走妥妥的,C#文字轉語音有很多參數我就不說了,畢竟我也是初學者。跟大家分享最簡單的方法,要好的效果得自己琢磨嘍;

先添加引用System.Speech程序集;

using System;
using System.Speech.Synthesis;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
             
            
            SpeechSynthesizer hello = new SpeechSynthesizer();
            string str = "請輸入您的名字";
            hello.Speak(str);  //Speak(string),Speak加上字符串類型的參數
            Console.ReadKey(); 
        }     
    

我個人覺得有些時候就是要直接講重點,要的就是這種簡單粗暴,呵呵

雖是簡單的代碼,多段疊加就不得了啊,個人覺得編程就是要用最少的代碼干最多的事。

簡單的代碼加上不同的想法就有不同的效果

using System;
using System.Speech.Synthesis;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
             
            /*下面這個程序不支持英文,我剛接觸,英文的我還不懂,呵呵*/
            SpeechSynthesizer hello = new SpeechSynthesizer();
            string str = "請輸入您的名字";
            Console.WriteLine(str);
            hello.Speak(str);
            string input = Console.ReadLine();
            Console.WriteLine ("你好,"+input);
            hello.Speak("你好,"+input);
            str = "我是您的助手,很高興認識你";
            Console.WriteLine(str);
            hello.Speak(str);  
            Console.ReadKey(); 
        }
     
    }
}

 這是我第一次寫博文,寫得不好的地方請多多包涵,若有錯的地方歡迎指正,謝謝!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM