最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C# 語(yǔ)音功能的實(shí)現(xiàn)方法

 更新時(shí)間:2013年03月10日 19:35:22   作者:  
最近看了一些資料,是c#實(shí)現(xiàn)語(yǔ)音功能的?,F(xiàn)在就簡(jiǎn)單的講一下怎么實(shí)現(xiàn)。

首先要安裝SpeechSDK5.1 開(kāi)發(fā)包和SpeechSDK5.1 Langague Pack(中英文) 語(yǔ)言包,不過(guò)VS2010里是自帶SpeechSDK5.0的com組件的,也可以用。

 簡(jiǎn)單講一下四個(gè)方法:

朗讀時(shí),使用

復(fù)制代碼 代碼如下:

voice.Speak(string,SpeechVoiceSpeakFlags.SVSFlagsAsync);

暫停,使用
復(fù)制代碼 代碼如下:

voice.Pause();

從暫停中繼續(xù)剛才的朗讀,使用
復(fù)制代碼 代碼如下:

voice.Resume();

停止功能
復(fù)制代碼 代碼如下:

voice.Speak(string.Empty, SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);

這樣就可以完整地實(shí)現(xiàn)了“朗讀”、“暫?!?、“繼續(xù)”、“停止”的功能。

下面就直接給出實(shí)例代碼:

復(fù)制代碼 代碼如下:

 private void button1_Click(object sender, EventArgs e)
        {
            Analyse(this.textBox1.Text);
        }

 

public void Analyse(string strSpeak)
        {
            int iCbeg = 0;
            int iEbeg = 0;
            bool IsChina = true;
            for (int i = 0; i < strSpeak.Length; i++)
            {
                char chr = strSpeak[i];
                if (IsChina)
                {
                    if (Convert.ToInt32(chr) <= 122 && Convert.ToInt32(chr) >= 65)
                    {
                        int iLen = i - iCbeg;
                        string strValue =
             strSpeak.Substring(iCbeg, iLen);
                        SpeakChina(strValue);
                        iEbeg = i;
                        IsChina = false;
                    }
                }
                else
                {
                    if (Convert.ToInt32(chr) > 122 || Convert.ToInt32(chr) < 65)
                    {
                        int iLen = i - iEbeg;
                        string strValue =
strSpeak.Substring(iEbeg, iLen);
                        this.SpeakEnglishi(strValue);
                        iCbeg = i;
                        IsChina = true;
                    }
                }
            }

             if (IsChina)    
             {       int iLen = strSpeak.Length - iCbeg;
                 string strValue = strSpeak.Substring(iCbeg, iLen);
                 SpeakChina(strValue);
             }     
             else
             {
                 int iLen = strSpeak.Length - iEbeg;
                 string strValue = strSpeak.Substring(iEbeg, iLen);
                 SpeakEnglishi(strValue);
             }



        }

 

        //中文
        private void SpeakChina(string speak)
        {
            voice = new SpVoice();
            voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(3);//其中3為中文,024為英文
            voice.Speak(speak, SpeechVoiceSpeakFlags.SVSFDefault);

        }
        //英文
        private void SpeakEnglishi(string speak)
        {
            voice = new SpVoice();
            voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);//其中3為中文,024為英文
            voice.Speak(speak, SpeechVoiceSpeakFlags.SVSFDefault);

        }

 

//保存語(yǔ)音
        private void button2_Click(object sender, EventArgs e)
        {
                 try    
                 {
                     SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
                     SpVoice Voice = new SpVoice();      
                     SaveFileDialog sfd = new SaveFileDialog();     
                     sfd.Filter = "All files (*.*)|*.*|wav files (*.wav)|*.wav";      
                     sfd.Title = "Save to a wave file";      
                     sfd.FilterIndex = 2;      
                     sfd.RestoreDirectory = true;      
                     if (sfd.ShowDialog() == DialogResult.OK)      
                     {        
                         SpeechStreamFileMode SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite;
                         SpFileStream SpFileStream = new SpFileStream();
                         SpFileStream.Open(sfd.FileName, SpFileMode, false);
                         Voice.AudioOutputStream = SpFileStream;
                         Voice.Speak(this.textBox1.Text, SpFlags);
                         Voice.WaitUntilDone(100);
                         SpFileStream.Close();
                     }    
                 }  
                 catch (Exception er)
                 {
                     MessageBox.Show("An Error Occured!", "SpeechApp", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }


        }

相關(guān)文章

最新評(píng)論

卓资县| 文登市| 玉树县| 时尚| 岳阳县| 湘西| 东源县| 南靖县| 香河县| 镇赉县| 甘谷县| 合作市| 东乡族自治县| 邵阳县| 阿勒泰市| 宝山区| 密山市| 荣成市| 金华市| 龙游县| 庆安县| 辽宁省| 喀什市| 石渠县| 南康市| 枣庄市| 上高县| 涡阳县| 天峻县| 修武县| 桦甸市| 田东县| 调兵山市| 临夏市| 万州区| 普兰店市| 壤塘县| 铜陵市| 苗栗县| 泰兴市| 石阡县|