調用 Windows 7 中英文混合朗讀

來源:互聯網
上載者:User

1、windows7內建語音辨識

2、文字轉換語音增加了 Microsoft Lili - Chinese(China) ,支援中英文混合朗讀

3、女聲、部分片語基本發音準確

 

以上讓我有做個小程式的衝動;如下:

 

1、引入SpeechLib.dll

2、建立form

3、編寫代碼

 


    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            GetVoices();
        }

        private void GetVoices()
        {
            SpVoice voice = new SpVoiceClass();
            ISpeechObjectTokens voices = voice.GetVoices("", "");
            var list = new List<string>();
            foreach (ISpeechObjectToken token in voices)
                list.Add(token.GetDescription(0));
            cbSpeechType.DataSource = list;
        }

        private void btnSpeechText_Click(object sender, EventArgs e)
        {
            SpeechText(null);
        }

        private void SpeechText(string fileName)
        {
            Cursor = Cursors.WaitCursor;
            SpFileStream stream = null;
            SpVoice voice = new SpVoiceClass();
            if (fileName + "" != "")
            {
                stream = new SpFileStreamClass();
                stream.Open(fileName, SpeechStreamFileMode.SSFMCreateForWrite, false);
                voice.AudioOutputStream = stream;
            }
            voice.Voice = voice.GetVoices("", "").Item(cbSpeechType.SelectedIndex);
            voice.Volume = tbVol.Value;
            voice.Rate = tbSpeechSpeed.Value;
            voice.Speak(tbText.Text, SpeechVoiceSpeakFlags.SVSFDefault);
            if (fileName + "" != "" && stream != null)
                stream.Close();
            Cursor = Cursors.Arrow;
        }

        private void btnRecordSpeech_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            using (var saveFileDialog = new SaveFileDialog())
            {
                saveFileDialog.FileName = "MyVoice.wav";
                saveFileDialog.Filter = "Wave (*.wav)|*.wav";
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    SpeechText(saveFileDialog.FileName);
                }
            }
            Cursor = Cursors.Arrow;
        }
    }

 

以上功能支援朗讀文字框內文本,支援講文本輸出語音檔案;

 

參考應用情境:

1、嘗嘗鮮,再刪除

2、將小說文本轉化為音頻放MP3內去聽

3、騙騙小孩

 

運行環境需求:

1、WINDOWS 7

2、其他未知

 

 

說再多不如放個代碼,所以本文從簡,請下載後編譯運行。

 

/Files/Chinasf/AnySpeech.rar

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.