www.pudn.com > speechapp.rar > Form1.cs


using dotnetspeech; 
using System; 
using System.Drawing; 
using System.Collections; 
using System.ComponentModel; 
using System.Windows.Forms; 
using System.Data; 
 
namespace tts 
{ 
	///  
	/// Form1 的摘要说明。 
	///  
	public class Form1 : System.Windows.Forms.Form 
	{ 
		///  
		private System.Windows.Forms.Button button1; 
		private System.Windows.Forms.CheckBox checkBox1; 
		private System.Windows.Forms.Button SPEAK; 
		private System.Windows.Forms.TextBox textBox1; 
 
		/// 必需的设计器变量。 
		///  
		 
 
		public Form1() 
		{ 
			// 
			// Windows 窗体设计器支持所必需的 
			// 
			InitializeComponent(); 
 
			// 
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码 
			// 
		} 
 
		///  
		/// 清理所有正在使用的资源。 
		///  
		 
 
 
		#region Windows 窗体设计器生成的代码 
		///  
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改 
		/// 此方法的内容。 
		///  
		private void InitializeComponent() 
		{ 
			this.checkBox1 = new System.Windows.Forms.CheckBox(); 
			this.SPEAK = new System.Windows.Forms.Button(); 
			this.button1 = new System.Windows.Forms.Button(); 
			this.textBox1 = new System.Windows.Forms.TextBox(); 
			this.SuspendLayout(); 
			//  
			// checkBox1 
			//  
			this.checkBox1.BackColor = System.Drawing.Color.DodgerBlue; 
			this.checkBox1.Location = new System.Drawing.Point(112, 216); 
			this.checkBox1.Name = "checkBox1"; 
			this.checkBox1.Size = new System.Drawing.Size(134, 25); 
			this.checkBox1.TabIndex = 2; 
			this.checkBox1.Text = "生成声音文件(Wav)"; 
			//  
			// SPEAK 
			//  
			this.SPEAK.BackColor = System.Drawing.Color.LightGray; 
			this.SPEAK.Location = new System.Drawing.Point(48, 256); 
			this.SPEAK.Name = "SPEAK"; 
			this.SPEAK.Size = new System.Drawing.Size(120, 26); 
			this.SPEAK.TabIndex = 1; 
			this.SPEAK.Text = "合成"; 
			this.SPEAK.Click += new System.EventHandler(this.SPEAK_Click); 
			//  
			// button1 
			//  
			this.button1.BackColor = System.Drawing.Color.LightGray; 
			this.button1.Location = new System.Drawing.Point(192, 256); 
			this.button1.Name = "button1"; 
			this.button1.Size = new System.Drawing.Size(120, 25); 
			this.button1.TabIndex = 3; 
			this.button1.Text = "退出"; 
			this.button1.Click += new System.EventHandler(this.button1_Click); 
			//  
			// textBox1 
			//  
			this.textBox1.BackColor = System.Drawing.Color.AntiqueWhite; 
			this.textBox1.Location = new System.Drawing.Point(48, 24); 
			this.textBox1.Multiline = true; 
			this.textBox1.Name = "textBox1"; 
			this.textBox1.Size = new System.Drawing.Size(259, 173); 
			this.textBox1.TabIndex = 0; 
			this.textBox1.Text = ""; 
			//  
			// Form1 
			//  
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); 
			this.BackColor = System.Drawing.Color.DodgerBlue; 
			this.ClientSize = new System.Drawing.Size(374, 302); 
			this.Controls.Add(this.button1); 
			this.Controls.Add(this.checkBox1); 
			this.Controls.Add(this.SPEAK); 
			this.Controls.Add(this.textBox1); 
			this.Name = "Form1"; 
			this.Text = "语音合成NO.1"; 
			this.ResumeLayout(false); 
 
		} 
		#endregion 
 
		///  
		/// 应用程序的主入口点。 
		 
 
		///  
		[STAThread] 
		static void Main()  
		{ 
			Application.Run(new Form1()); 
		} 
 
		private void SPEAK_Click(object sender, System.EventArgs e) 
		{ 
 
			try  
			{ 
				SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync; 
				SpVoice speech = new SpVoice(); 
				if (checkBox1.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); 
						speech.AudioOutputStream = SpFileStream; 
						speech.Speak(textBox1.Text, SpFlags); 
						 
						SpFileStream.Close(); 
					} 
				} 
				else 
				{ 
					speech.Speak(textBox1.Text, SpFlags); 
				} 
			} 
			catch 
			{ 
				MessageBox.Show("Speak error"); 
			} 
 
		} 
 
 
		private void button1_Click(object sender, System.EventArgs e) 
		{ 
			this.Close(); 
		} 
	} 
}