| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 论坛
 上传资源
上传编程相关的资源,源源不断赚取资源分,以备将来下载之需
baelbael
文件大小:664.32 KB
文件类型:rar
发布时间:2011-12-29 19:28:21
需资源分:1
下载次数:7
Tag:sapi  tts
::资源简介::
英语朗读源码
//=============================================================================
//
// Copyright (c) Microsoft Corporation All Rights Reserved.
//
//=============================================================================

namespace SimpleTTS
{
    using System;
    using System.Windows.Forms;
    using System.Threading;
    using SpeechLib;

    /// <summary>
    ///     This form shows how TTS speak works. 
    /// </summary>
    public class MainForm : System.Windows.Forms.Form
    {
        private System.Windows.Forms.CheckBox chkSaveToWavFile;
        private System.Windows.Forms.Button btnSpeak;
        private System.Windows.Forms.TextBox txtSpeakText;
        private System.Windows.Forms.Button btnExit;
        private System.ComponentModel.IContainer components;

        public MainForm()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
        }

        /// <summary>
        ///     Clean up any resources being used.
        /// </summary>
       

        #region Windows Form Designer generated code
        /// <summary>
        ///     Required method for Designer support - do not modify
        ///     the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.btnSpeak = new System.Windows.Forms.Button();
            this.chkSaveToWavFile = new System.Windows.Forms.CheckBox();
            this.btnExit = new System.Windows.Forms.Button();
            this.txtSpeakText = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // btnSpeak
            // 
            this.btnSpeak.Location = new System.Drawing.Point(130, 86);
            this.btnSpeak.Name = "btnSpeak";
            this.btnSpeak.Size = new System.Drawing.Size(96, 26);
            this.btnSpeak.TabIndex = 4;
            this.btnSpeak.Text = "&Speak";
            this.btnSpeak.Click += new System.EventHandler(this.btnSpeak_Click);
            // 
            // chkSaveToWavFile
            // 
            this.chkSaveToWavFile.Location = new System.Drawing.Point(10, 86);
            this.chkSaveToWavFile.Name = "chkSaveToWavFile";
            this.chkSaveToWavFile.Size = new System.Drawing.Size(108, 26);
            this.chkSaveToWavFile.TabIndex = 5;
            this.chkSaveToWavFile.Text = "Save to .wav";
            // 
            // btnExit
            // 
            this.btnExit.Location = new System.Drawing.Point(240, 86);
            this.btnExit.Name = "btnExit";
            this.btnExit.Size = new System.Drawing.Size(96, 26);
            this.btnExit.TabIndex = 2;
            this.btnExit.Text = "&Exit";
            this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
            // 
            // txtSpeakText
            // 
            this.txtSpeakText.Location = new System.Drawing.Point(10, 9);
            this.txtSpeakText.Multiline = true;
            this.txtSpeakText.Name = "txtSpeakText";
            this.txtSpeakText.Size = new System.Drawing.Size(340, 64);
            this.txtSpeakText.TabIndex = 3;
            this.txtSpeakText.Text = "This is Simple TTS application.";
            // 
            // MainForm
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(299, 120);
            this.Controls.Add(this.btnExit);
            this.Controls.Add(this.btnSpeak);
            this.Controls.Add(this.txtSpeakText);
            this.Controls.Add(this.chkSaveToWavFile);
            this.MaximizeBox = false;
            this.Name = "MainForm";
            this.Text = "SimpleTTS";
            this.Load += new System.EventHandler(this.MainForm_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }
        #endregion

        /// <summary>
        ///     The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new MainForm());
        }

        private void btnSpeak_Click(object sender, System.EventArgs e)
        {
            //Create a TTS voice and speak.
            try 
            {
                SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
                SpVoice Voice = new SpVoice();
                if (chkSaveToWavFile.Checked)
                {
                    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(txtSpeakText.Text, SpFlags);
                        Voice.WaitUntilDone(Timeout.Infinite);

                        SpFileStream.Close();

                    }
                }
                else
                {
                    Voice.Speak(txtSpeakText.Text, SpFlags);
                }
            }
            catch(Exception error)
            {
                MessageBox.Show("Speak error", "SimpleTTS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        private void btnExit_Click(object sender, System.EventArgs e)
        {
          this.Dispose();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {

        }
    }
}
::下载地址::

BCCN本地下载 
开通VIP
可免资源分下载所有资源
::下载本资源的人也下载了::
::作者其它资源::
 
>> 评论
 
热门Tag:
 
编程中国 版权所有,并保留所有权利。
Powered by BCCN 1.020, Processed in 0.010614 second(s)
Copyright©2010-2024, BCCN.NET, All Rights Reserved