Click here to Skip to main content
15,891,033 members
Articles / Programming Languages / Visual C++ 9.0

A Very Easy Introduction to Microsoft .NET Speech Synthesis (VB, C#, C++)

Rate me:
Please Sign up or sign in to vote.
4.23/5 (37 votes)
21 Aug 2008CPOL1 min read 242.7K   15.5K   104  
A sample application with source code in three .NET languages (Basic, C#, C++) on using the new (.NET 3.0+) System.Speech Class.
namespace Sounds
{
    partial class speakerForm
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #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.speakTextBox = new System.Windows.Forms.TextBox();
            this.speakButton = new System.Windows.Forms.Button();
            this.exportButton = new System.Windows.Forms.Button();
            this.exitButton = new System.Windows.Forms.Button();
            this.fileTextBox = new System.Windows.Forms.TextBox();
            this.fileButton = new System.Windows.Forms.Button();
            this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
            this.speedUpDown = new System.Windows.Forms.NumericUpDown();
            this.speedLabel = new System.Windows.Forms.Label();
            this.volumeUpDown = new System.Windows.Forms.NumericUpDown();
            this.volumeLabel = new System.Windows.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.speedUpDown)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.volumeUpDown)).BeginInit();
            this.SuspendLayout();
            // 
            // speakTextBox
            // 
            this.speakTextBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.speakTextBox.Location = new System.Drawing.Point(12, 12);
            this.speakTextBox.Multiline = true;
            this.speakTextBox.Name = "speakTextBox";
            this.speakTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
            this.speakTextBox.Size = new System.Drawing.Size(240, 140);
            this.speakTextBox.TabIndex = 0;
            this.speakTextBox.Text = "Type here to speak.";
            // 
            // speakButton
            // 
            this.speakButton.Location = new System.Drawing.Point(14, 210);
            this.speakButton.Name = "speakButton";
            this.speakButton.Size = new System.Drawing.Size(75, 23);
            this.speakButton.TabIndex = 5;
            this.speakButton.Text = "&Speak";
            this.speakButton.UseVisualStyleBackColor = true;
            this.speakButton.Click += new System.EventHandler(this.speakButton_Click);
            // 
            // exportButton
            // 
            this.exportButton.Location = new System.Drawing.Point(95, 210);
            this.exportButton.Name = "exportButton";
            this.exportButton.Size = new System.Drawing.Size(75, 23);
            this.exportButton.TabIndex = 6;
            this.exportButton.Text = "&Export";
            this.exportButton.UseVisualStyleBackColor = true;
            this.exportButton.Click += new System.EventHandler(this.exportButton_Click);
            // 
            // exitButton
            // 
            this.exitButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.exitButton.Location = new System.Drawing.Point(176, 210);
            this.exitButton.Name = "exitButton";
            this.exitButton.Size = new System.Drawing.Size(75, 23);
            this.exitButton.TabIndex = 7;
            this.exitButton.Text = "E&xit";
            this.exitButton.UseVisualStyleBackColor = true;
            this.exitButton.Click += new System.EventHandler(this.exitButton_Click);
            // 
            // fileTextBox
            // 
            this.fileTextBox.Location = new System.Drawing.Point(14, 184);
            this.fileTextBox.Name = "fileTextBox";
            this.fileTextBox.ReadOnly = true;
            this.fileTextBox.Size = new System.Drawing.Size(203, 20);
            this.fileTextBox.TabIndex = 3;
            // 
            // fileButton
            // 
            this.fileButton.Location = new System.Drawing.Point(223, 182);
            this.fileButton.Name = "fileButton";
            this.fileButton.Size = new System.Drawing.Size(28, 23);
            this.fileButton.TabIndex = 4;
            this.fileButton.Text = "...";
            this.fileButton.UseVisualStyleBackColor = true;
            this.fileButton.Click += new System.EventHandler(this.fileButton_Click);
            // 
            // saveFileDialog1
            // 
            this.saveFileDialog1.DefaultExt = "wav";
            this.saveFileDialog1.Filter = "wav files|*.wav";
            this.saveFileDialog1.Title = "Export wav file...";
            // 
            // speedUpDown
            // 
            this.speedUpDown.Location = new System.Drawing.Point(186, 158);
            this.speedUpDown.Maximum = new decimal(new int[] {
            10,
            0,
            0,
            0});
            this.speedUpDown.Minimum = new decimal(new int[] {
            10,
            0,
            0,
            -2147483648});
            this.speedUpDown.Name = "speedUpDown";
            this.speedUpDown.Size = new System.Drawing.Size(65, 20);
            this.speedUpDown.TabIndex = 2;
            this.speedUpDown.Value = new decimal(new int[] {
            1,
            0,
            0,
            0});
            // 
            // speedLabel
            // 
            this.speedLabel.AutoSize = true;
            this.speedLabel.Location = new System.Drawing.Point(139, 160);
            this.speedLabel.Name = "speedLabel";
            this.speedLabel.Size = new System.Drawing.Size(41, 13);
            this.speedLabel.TabIndex = 7;
            this.speedLabel.Text = "Speed:";
            // 
            // volumeUpDown
            // 
            this.volumeUpDown.Location = new System.Drawing.Point(62, 158);
            this.volumeUpDown.Name = "volumeUpDown";
            this.volumeUpDown.Size = new System.Drawing.Size(63, 20);
            this.volumeUpDown.TabIndex = 1;
            this.volumeUpDown.Value = new decimal(new int[] {
            100,
            0,
            0,
            0});
            // 
            // volumeLabel
            // 
            this.volumeLabel.AutoSize = true;
            this.volumeLabel.Location = new System.Drawing.Point(11, 160);
            this.volumeLabel.Name = "volumeLabel";
            this.volumeLabel.Size = new System.Drawing.Size(45, 13);
            this.volumeLabel.TabIndex = 9;
            this.volumeLabel.Text = "Volume:";
            // 
            // speakerForm
            // 
            this.AcceptButton = this.speakButton;
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.CancelButton = this.exitButton;
            this.ClientSize = new System.Drawing.Size(262, 242);
            this.Controls.Add(this.volumeLabel);
            this.Controls.Add(this.volumeUpDown);
            this.Controls.Add(this.speedLabel);
            this.Controls.Add(this.speedUpDown);
            this.Controls.Add(this.fileButton);
            this.Controls.Add(this.fileTextBox);
            this.Controls.Add(this.exitButton);
            this.Controls.Add(this.exportButton);
            this.Controls.Add(this.speakButton);
            this.Controls.Add(this.speakTextBox);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.Name = "speakerForm";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Speaker (C#)";
            ((System.ComponentModel.ISupportInitialize)(this.speedUpDown)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.volumeUpDown)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.TextBox speakTextBox;
        private System.Windows.Forms.Button speakButton;
        private System.Windows.Forms.Button exportButton;
        private System.Windows.Forms.Button exitButton;
        private System.Windows.Forms.TextBox fileTextBox;
        private System.Windows.Forms.Button fileButton;
        private System.Windows.Forms.SaveFileDialog saveFileDialog1;
        private System.Windows.Forms.NumericUpDown speedUpDown;
        private System.Windows.Forms.Label speedLabel;
        private System.Windows.Forms.NumericUpDown volumeUpDown;
        private System.Windows.Forms.Label volumeLabel;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Unknown
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions