コード例 #1
0
        /// <summary>
        /// Application voice uses a separate SAPI voice to speak self-voicing text.
        /// </summary>
        private ApplicationVoice()
        {
            _isEnabled = false;

            if (SapiVoice.IsEnabled())
            {
                _voice = new SapiVoice(true);
                _voice.FinishedImmediatePhrase += OnSpeakFinished;

                _isEnabled = true;
            }
        }
コード例 #2
0
        // Public Methods (1)
        /// <summary>
        /// Determines and returns the voice to use for the given phrase. Also takes in a MediaElement
        /// as we cannot easily programmatically instantiate a MediaElement (since in order to function
        /// a MediaElement must be inserted into the UI Tree).
        /// </summary>
        /// <param name="currentPhrase">The current phrase to speak.</param>
        /// <param name="player">The MediaElement player used to play MP3 audio.</param>
        /// <returns>The IVoice to use to speak the given phrase.</returns>
        public static VoiceBase GetVoice(Phrase currentPhrase, MediaElement player)
        {
            if (currentPhrase == null) return null;

            if (SapiVoice.IsEnabled() && !currentPhrase.Silent)
                _sapiVoice = new SapiVoice(false);
            else
                _sapiVoice = new SilentVoice(); //Text-to-speech unavailable - use a silent voice instead.

            //If there is no included audio use the SAPi/Silent voice, otherwise the MP3
            if (currentPhrase.Audio == null)
            {
                _sapiVoice.Volume = Volume;
                return _sapiVoice;
            }
            if (_mp3Voice == null)
                _mp3Voice = new MP3Voice(player) { Volume = Volume };
            else
                _mp3Voice.ResetVoice();
            return _mp3Voice;
        }