prompt.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Speech / Src / Synthesis / prompt.cs / 1 / prompt.cs

                            //------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------- 

using System; 
using System.Diagnostics; 
using System.IO;
using System.Speech.Internal; 

#pragma warning disable 1634, 1691 // Allows suppression of certain PreSharp messages.

namespace System.Speech.Synthesis 
{
    ///  
    /// TODOC 
    /// 
    [DebuggerDisplay ("{_text}")] 
    public class Prompt
    {
        //*******************************************************************
        // 
        // Constructors
        // 
        //******************************************************************* 

        #region Constructors 

        /// 
        /// TODOC
        ///  
        /// 
        public Prompt (string textToSpeak) 
            : this (textToSpeak, SynthesisTextFormat.Text) 
        {
        } 

        /// 
        /// TODOC
        ///  
        /// 
        ///  
        public Prompt (PromptBuilder promptBuilder) 
        {
            Helpers.ThrowIfNull (promptBuilder, "promptBuilder"); 

            _text = promptBuilder.ToXml ();
            _media = SynthesisMediaType.Ssml;
        } 

        // Disable parameter validation check for empty strings 
#pragma warning disable 56507 

        ///  
        /// TODOC
        /// 
        /// 
        ///  
        public Prompt (string textToSpeak, SynthesisTextFormat media)
        { 
            Helpers.ThrowIfNull (textToSpeak, "textToSpeak"); 

            switch (_media = (SynthesisMediaType) media) 
            {
                case SynthesisMediaType.Text:
                case SynthesisMediaType.Ssml:
                    _text = textToSpeak; 
                    break;
 
                default: 
                    throw new ArgumentException (SR.Get (SRID.SynthesizerUnknownMediaType), "media");
            } 
        }

#pragma warning restore 56507
 
        /// 
        /// TODOC 
        ///  
        /// 
        ///  
        internal Prompt (Uri promptFile, SynthesisMediaType media)
        {
            Helpers.ThrowIfNull (promptFile, "promptFile");
 
            switch (_media = media)
            { 
                case SynthesisMediaType.Text: 
                case SynthesisMediaType.Ssml:
                    string localPath; 
                    string mimeType;
                    Uri baseUri;
                    using (Stream stream = _resourceLoader.LoadFile (promptFile, out mimeType, out baseUri, out localPath))
                    { 
                        try
                        { 
                            using (TextReader reader = new StreamReader (stream)) 
                            {
                                _text = reader.ReadToEnd (); 
                            }
                        }
                        finally
                        { 
                            _resourceLoader.UnloadFile (localPath);
                        } 
                    } 

                    break; 

                case SynthesisMediaType.WaveAudio:
                    _text = promptFile.ToString ();
                    _audio = promptFile; 
                    break;
 
                default: 
                    throw new ArgumentException (SR.Get (SRID.SynthesizerUnknownMediaType), "media");
            } 
        }

        #endregion
 
        //********************************************************************
        // 
        // Public Properties 
        //
        //******************************************************************* 

        #region public Properties

        ///  
        /// TODOC
        ///  
        ///  
        public bool IsCompleted
        { 
            get
            {
                return _completed;
            } 
            internal set
            { 
                _completed = value; 
            }
        } 

        internal object Synthesizer
        {
            set 
            {
                if (value != null && (_synthesizer != null || _completed)) 
                { 
                    throw new ArgumentException (SR.Get (SRID.SynthesizerPromptInUse), "synthesizer");
                } 

                _synthesizer = value;
            }
        } 

        #endregion 
 
        //********************************************************************
        // 
        // Internal Fields
        //
        //********************************************************************
 
        #region Internal Fields
 
        ///  
        /// Could be some raw text or SSML doc or the file name (wave file)
        ///  
        internal string _text;

        /// 
        /// Audio data 
        /// 
        internal Uri _audio; 
 
        /// 
        /// Unused at this point 
        /// 
        internal SynthesisMediaType _media;

        ///  
        /// Is this prompt played asynchrounously
        ///  
        internal bool _syncSpeak; 

        ///  
        /// What errors occurred during this operation?
        /// 
        internal Exception _exception;
 
        #endregion
 
        //******************************************************************* 
        //
        // Private Fields 
        //
        //********************************************************************

        #region Private Fields 

        ///  
        /// Is this SpeakToken canceled before it was completed? 
        /// 
        private bool _completed; 

        /// 
        /// The synthesizer this prompt is played on
        ///  
        private object _synthesizer;
 
        static private ResourceLoader _resourceLoader = new ResourceLoader (); 

        #endregion 
    }

    //*******************************************************************
    // 
    // Public Enums
    // 
    //******************************************************************* 

    #region Public Enums 

    /// 
    /// TODOC
    ///  
    public enum SynthesisMediaType
    { 
        ///  
        /// TODOC
        ///  
        Text = 0,
        /// 
        /// TODOC
        ///  
        Ssml = 1,
        ///  
        /// TODOC 
        /// 
        WaveAudio 
    }

    /// 
    /// TODOC 
    /// 
    public enum SynthesisTextFormat 
    { 
        /// 
        /// TODOC 
        /// 
        Text = 0,
        /// 
        /// TODOC 
        /// 
        Ssml = 1, 
    } 

    #endregion 

    //*******************************************************************
    //
    // Internal Types 
    //
    //******************************************************************** 
 
    #region Internal Types
 
    /// 
    /// TODOC
    /// 
    internal enum PromptPriority 
    {
        Normal, 
        High 
    }
 
    #endregion

}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------- 

using System; 
using System.Diagnostics; 
using System.IO;
using System.Speech.Internal; 

#pragma warning disable 1634, 1691 // Allows suppression of certain PreSharp messages.

namespace System.Speech.Synthesis 
{
    ///  
    /// TODOC 
    /// 
    [DebuggerDisplay ("{_text}")] 
    public class Prompt
    {
        //*******************************************************************
        // 
        // Constructors
        // 
        //******************************************************************* 

        #region Constructors 

        /// 
        /// TODOC
        ///  
        /// 
        public Prompt (string textToSpeak) 
            : this (textToSpeak, SynthesisTextFormat.Text) 
        {
        } 

        /// 
        /// TODOC
        ///  
        /// 
        ///  
        public Prompt (PromptBuilder promptBuilder) 
        {
            Helpers.ThrowIfNull (promptBuilder, "promptBuilder"); 

            _text = promptBuilder.ToXml ();
            _media = SynthesisMediaType.Ssml;
        } 

        // Disable parameter validation check for empty strings 
#pragma warning disable 56507 

        ///  
        /// TODOC
        /// 
        /// 
        ///  
        public Prompt (string textToSpeak, SynthesisTextFormat media)
        { 
            Helpers.ThrowIfNull (textToSpeak, "textToSpeak"); 

            switch (_media = (SynthesisMediaType) media) 
            {
                case SynthesisMediaType.Text:
                case SynthesisMediaType.Ssml:
                    _text = textToSpeak; 
                    break;
 
                default: 
                    throw new ArgumentException (SR.Get (SRID.SynthesizerUnknownMediaType), "media");
            } 
        }

#pragma warning restore 56507
 
        /// 
        /// TODOC 
        ///  
        /// 
        ///  
        internal Prompt (Uri promptFile, SynthesisMediaType media)
        {
            Helpers.ThrowIfNull (promptFile, "promptFile");
 
            switch (_media = media)
            { 
                case SynthesisMediaType.Text: 
                case SynthesisMediaType.Ssml:
                    string localPath; 
                    string mimeType;
                    Uri baseUri;
                    using (Stream stream = _resourceLoader.LoadFile (promptFile, out mimeType, out baseUri, out localPath))
                    { 
                        try
                        { 
                            using (TextReader reader = new StreamReader (stream)) 
                            {
                                _text = reader.ReadToEnd (); 
                            }
                        }
                        finally
                        { 
                            _resourceLoader.UnloadFile (localPath);
                        } 
                    } 

                    break; 

                case SynthesisMediaType.WaveAudio:
                    _text = promptFile.ToString ();
                    _audio = promptFile; 
                    break;
 
                default: 
                    throw new ArgumentException (SR.Get (SRID.SynthesizerUnknownMediaType), "media");
            } 
        }

        #endregion
 
        //********************************************************************
        // 
        // Public Properties 
        //
        //******************************************************************* 

        #region public Properties

        ///  
        /// TODOC
        ///  
        ///  
        public bool IsCompleted
        { 
            get
            {
                return _completed;
            } 
            internal set
            { 
                _completed = value; 
            }
        } 

        internal object Synthesizer
        {
            set 
            {
                if (value != null && (_synthesizer != null || _completed)) 
                { 
                    throw new ArgumentException (SR.Get (SRID.SynthesizerPromptInUse), "synthesizer");
                } 

                _synthesizer = value;
            }
        } 

        #endregion 
 
        //********************************************************************
        // 
        // Internal Fields
        //
        //********************************************************************
 
        #region Internal Fields
 
        ///  
        /// Could be some raw text or SSML doc or the file name (wave file)
        ///  
        internal string _text;

        /// 
        /// Audio data 
        /// 
        internal Uri _audio; 
 
        /// 
        /// Unused at this point 
        /// 
        internal SynthesisMediaType _media;

        ///  
        /// Is this prompt played asynchrounously
        ///  
        internal bool _syncSpeak; 

        ///  
        /// What errors occurred during this operation?
        /// 
        internal Exception _exception;
 
        #endregion
 
        //******************************************************************* 
        //
        // Private Fields 
        //
        //********************************************************************

        #region Private Fields 

        ///  
        /// Is this SpeakToken canceled before it was completed? 
        /// 
        private bool _completed; 

        /// 
        /// The synthesizer this prompt is played on
        ///  
        private object _synthesizer;
 
        static private ResourceLoader _resourceLoader = new ResourceLoader (); 

        #endregion 
    }

    //*******************************************************************
    // 
    // Public Enums
    // 
    //******************************************************************* 

    #region Public Enums 

    /// 
    /// TODOC
    ///  
    public enum SynthesisMediaType
    { 
        ///  
        /// TODOC
        ///  
        Text = 0,
        /// 
        /// TODOC
        ///  
        Ssml = 1,
        ///  
        /// TODOC 
        /// 
        WaveAudio 
    }

    /// 
    /// TODOC 
    /// 
    public enum SynthesisTextFormat 
    { 
        /// 
        /// TODOC 
        /// 
        Text = 0,
        /// 
        /// TODOC 
        /// 
        Ssml = 1, 
    } 

    #endregion 

    //*******************************************************************
    //
    // Internal Types 
    //
    //******************************************************************** 
 
    #region Internal Types
 
    /// 
    /// TODOC
    /// 
    internal enum PromptPriority 
    {
        Normal, 
        High 
    }
 
    #endregion

}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK