九色国产,午夜在线视频,新黄色网址,九九色综合,天天做夜夜做久久做狠狠,天天躁夜夜躁狠狠躁2021a,久久不卡一区二区三区

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
.NET 語(yǔ)音轉(zhuǎn)文字 文字轉(zhuǎn)語(yǔ)音

文字轉(zhuǎn)語(yǔ)音

這個(gè)比較簡(jiǎn)單只要引用COM中的 Microsoft Speech objcet Library

using SpeechLib;     public ActionResult speak(string speechSounds)        {            SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;            SpVoice spVoice = new SpVoice();            spVoice.Rate = spVoice.Rate - 5;            if (spVoice.Volume < 100)            {                spVoice.Volume = spVoice.Volume + 10;            }            if (spVoice.Volume > 9)            {                spVoice.Volume = spVoice.Volume - 10;            }            spVoice.Speak(speechSounds, SpFlags);            return Content("成功");        }

 

文字生成語(yǔ)音文件

引用程序集中的 System.Speech

using System.Speech.Synthesis;private SpeechSynthesizer synth = null;        /// <summary>        /// 返回一個(gè)SpeechSynthesizer對(duì)象        /// </summary>        /// <returns></returns>        private SpeechSynthesizer GetSpeechSynthesizerInstance()        {            if (synth == null)            {                synth = new SpeechSynthesizer();            }            return synth;        }        /// <summary>        ///  播放        /// </summary>        public void Play(string text)        {            Thread thread = new Thread(new ParameterizedThreadStart(SaveMp3));            thread.Start(text);        }        /// <summary>        /// 保存語(yǔ)音文件        /// </summary>        /// <param name="text"></param>        public void SaveMp3(object text)        {                synth = GetSpeechSynthesizerInstance();                string spText = text.ToString();                synth.Rate = 1;                synth.Volume = 100;                string filename = DateTime.Now.ToString("yyyyMMddHHmmss");                string str = "C:\\Users\\admin1\\Desktop\\新建文件夾\\" + filename + ".wav";                synth.SetOutputToWaveFile(str);                synth.Speak(spText);                synth.SetOutputToNull();                //調(diào)用語(yǔ)音轉(zhuǎn)文字                //Thread threadVoice = new Thread(VoiceToText);                //threadVoice.Start(str);        }

 

語(yǔ)音轉(zhuǎn)文本

using System.Speech.Recognition;        private SpeechRecognitionEngine SRE = new SpeechRecognitionEngine();        /// <summary>        //  語(yǔ)音轉(zhuǎn)文本        /// </summary>        /// <param name="str"></param>        private void VoiceToText(object str)        {            try            {                string filepath = str.ToString(); ;                SRE.SetInputToWaveFile(filepath);         //<=======默認(rèn)的語(yǔ)音輸入設(shè)備,你可以設(shè)定為去識(shí)別一個(gè)WAV文件。                GrammarBuilder GB = new GrammarBuilder();                //需要判斷的文本(相當(dāng)于語(yǔ)音庫(kù))                GB.Append(new Choices(new string[] { "時(shí)間", "電話", "短信", "定位", "天氣", "幫助" }));                Grammar G = new Grammar(GB);                G.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(G_SpeechRecognized);                SRE.LoadGrammar(G);                SRE.RecognizeAsync(RecognizeMode.Multiple); //<=======異步調(diào)用識(shí)別引擎,允許多次識(shí)別(否則程序只響應(yīng)你的一句話)            }            catch (Exception ex)            {                string s = ex.ToString();            }        }        /// <summary>        /// 判斷語(yǔ)音并轉(zhuǎn)化為需要輸出的文本        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void G_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)        {            string result = e.Result.Text;            string RetSpeck = string.Empty;            switch (result)            {                case "時(shí)間":                    RetSpeck = "你輸入了時(shí)間";                    break;                case "電話":                    RetSpeck = "你輸入了電話";                    break;                case "短信":                    RetSpeck = "你輸入了短信";                    break;                case "定位":                    RetSpeck = "你輸入了定位";                    break;                case "天氣":                    RetSpeck = "你輸入了天氣";                    break;                case "幫助":                    RetSpeck = "你輸入了幫助";                    break;            }            speak(RetSpeck);

}

轉(zhuǎn)自:https://www.cnblogs.com/-maomao/p/6861447.html

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
.net4.0 動(dòng)態(tài)類型和動(dòng)態(tài)編程之3行搞定一個(gè)語(yǔ)音朗讀器
C#語(yǔ)音朗讀文本
驗(yàn)證整數(shù)的正則表達(dá)式與C#驗(yàn)證整數(shù)-大叔學(xué)編程-博客園
LoadRunner字符串與參數(shù)的操作及轉(zhuǎn)換技巧
將輸入函數(shù)體的文字寫(xiě)到文本文件里面
高效的找出兩個(gè)List中的不同元素
更多類似文章 >>
生活服務(wù)
熱點(diǎn)新聞
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服