Touch tone generator.
Inheritance: DTMF
Exemple #1
0
        /// <summary>
        /// Get array of touch tones for given string.
        /// </summary>
        /// <param name="keys">String of touch tone characters to convert to touch tones.</param>
        /// <param name="keyDuration">Duration of touch tone key press in seconds, typically fractional.</param>
        /// <param name="interKeyPause">Time to wait between key presses in seconds, typically fractional.</param>
        /// <returns>Array of touch tones for given string.</returns>
        /// <remarks>Non-touch tone characters are ignored. Commas are interpreted as a one second pause.</remarks>
        public static DTMF[] GetTouchTones(string keys, double keyDuration, double interKeyPause)
        {
            List <DTMF> touchTones = new List <DTMF>();
            TouchTone   touchTone;
            DTMF        pause     = new DTMF(0.0D, 0.0D, interKeyPause);
            DTMF        longPause = new DTMF(0.0D, 0.0D, 1.0D);

            foreach (char key in keys)
            {
                if (key == ',')
                {
                    // Interpret commas as long pauses
                    touchTones.Add(longPause);
                }
                else if (TouchTone.TryParse(key, out touchTone))
                {
                    if (touchTones.Count > 0)
                    {
                        touchTones.Add(pause);
                    }

                    touchTone.Duration = keyDuration;
                    touchTones.Add(touchTone);
                }
            }

            return(touchTones.ToArray());
        }
Exemple #2
0
        /// <summary>
        /// Converts the character representation of a touch tone key into
        /// an instance of the <see cref="TouchTone"/> class. A return value
        /// indicates whether the conversion succeeded.
        /// </summary>
        /// <param name="key">A character containing a touch tone key to convert.</param>
        /// <param name="result">
        /// When this method returns, contains an instance of the <see cref="TouchTone"/>
        /// class equivalent to the touch tone key, if the conversion succeeded, or null
        /// if the conversion failed. The conversion fails if the <paramref name="key"/>
        /// parameter is not a valid touch tone.</param>
        /// <returns>true if s was converted successfully; otherwise, false.</returns>
        public static bool TryParse(char key, out TouchTone result)
        {
            TouchToneKey parsedKey;

            if (TryParseKey(key, out parsedKey))
            {
                result = new TouchTone(parsedKey);
                return(true);
            }
            else
            {
                result = null;
                return(false);
            }
        }
Exemple #3
0
        /// <summary>
        /// Converts the character representation of a touch tone key into 
        /// an instance of the <see cref="TouchTone"/> class. A return value
        /// indicates whether the conversion succeeded.
        /// </summary>
        /// <param name="key">A character containing a touch tone key to convert.</param>
        /// <param name="result">
        /// When this method returns, contains an instance of the <see cref="TouchTone"/>
        /// class equivalent to the touch tone key, if the conversion succeeded, or null
        /// if the conversion failed. The conversion fails if the <paramref name="key"/>
        /// parameter is not a valid touch tone.</param>
        /// <returns>true if s was converted successfully; otherwise, false.</returns>
        public static bool TryParse(char key, out TouchTone result)
        {
            TouchToneKey parsedKey;

            if (TryParseKey(key, out parsedKey))
            {
                result = new TouchTone(parsedKey);
                return true;
            }
            else
            {
                result = null;
                return false;
            }
        }