// 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;
        }
        /// <summary>
        /// This method is called when an asynchronous request for an audio element has completed.
        /// </summary>
        /// <param name="currentPhrase"></param>
        /// <param name="canResumePhrase"></param>
        private void PlayPhrase(Phrase currentPhrase, bool canResumePhrase)
        {
            Logger.Log("Playing phrase of element: {0}", currentPhrase.ElementID);

            // If in the meantime the navigator has moved to another element then don't even bother trying
            // to play it.
            if (_state.Navigator.CurrentElementID == currentPhrase.ElementID)
            {
                //Only want to execute speaking phrases if the element exists on the surface.
                if (View.ApplicationView.DisplaySurface.ElementExists(_state.Navigator.CurrentElementID) || currentPhrase.Silent)
                {
                    //Don't want to reset player position if the player was previously paused.
                    if (!canResumePhrase)
                        View.StartSpeakingPhrase(currentPhrase);
                    else
                        View.ResumeSpeakingPhrase();

                    View.SetPlayButtonState(_state.CanPlay, _state.IsPlaying);
                }
                else
                {
                    //Move to next element
                    MoveNext();
                }
            }
        }
        /// <summary>
        /// Starts playing the given phrase.
        /// </summary>
        /// <param name="currentPhrase">The current phrase.</param>
        public override void StartPlaying(Phrase currentPhrase)
        {
            //TODO Should check for unspeakable characters, not just dots and spaces
            string pattern = "^['.' ]*$";
            Match m = Regex.Match(currentPhrase.Text, pattern);

            if (!m.Success)
            {
                try
                {
                    HtmlPage.Window.Invoke("PlaySpeech", currentPhrase.Text);
                }
                catch (Exception)
                {
                }
            } else
            {
                if (FinishedPlaying != null)
                    FinishedPlaying(this, new EventArgs());
            }
        }
 /// <summary>
 /// Load the given phrase without playing.
 /// </summary>
 /// <param name="currentPhrase">The current phrase.</param>
 public override void LoadPhrase(Phrase currentPhrase)
 {
     //since SAPI voices properly queue themselves
     //we are able to do nothing different than start playing
     StartPlaying(currentPhrase);
 }
 // Public Methods (8)
 /// <summary>
 /// Interrupts the existing playback with the given phrase. If the voice is not currently playing, 
 /// the given phrase is simply spoken.
 /// </summary>
 /// <param name="immediatePhrase">The immediate phrase to speak.</param>
 /// <remarks>If another voice is speaking, it is the presenter's responsibility to pause and resume
 /// playback as needed.</remarks>
 public override void InterruptPlayback(Phrase immediatePhrase)
 {
     try
     {
         HtmlPage.Window.Invoke("PlayHighPrioritySpeech", immediatePhrase.Text);
     }
     catch(Exception)
     {
     }
 }
 // Public Methods (7)
 /// <summary>
 /// Interrupts the existing playback with the given phrase. If the voice is not currently playing, 
 /// the given phrase is simply spoken.
 /// </summary>
 /// <param name="immediatePhrase">The immediate phrase to speak.</param>
 /// <remarks>If another voice is speaking, it is the presenter's responsibility to pause and resume
 /// playback as needed.</remarks>
 public override void InterruptPlayback(Phrase immediatePhrase)
 {
     //Do nothing.
     OnFinishedImmediatePhrase();
 }
 /// <summary>
 /// Starts playing the given phrase.
 /// </summary>
 /// <param name="currentPhrase">The current phrase.</param>
 public override void StartPlaying(Phrase currentPhrase)
 {
     LoadPhrase(currentPhrase);
     _playOnMediaLoad = true; //will start playing when the media is loaded
     _player.Play();
 }
        /// <summary>
        /// Load the given phrase without playing.
        /// </summary>
        /// <param name="currentPhrase">The current phrase.</param>
        public override void LoadPhrase(Phrase currentPhrase)
        {
            _resetPlayerPosition = true;
            _currentPhrase = currentPhrase;

            Audio currentAudio = _currentPhrase.Audio;
            if(currentAudio.SourceStream != null)
            {
                //reset source stream to beginning
                currentAudio.SourceStream.Seek(0, SeekOrigin.Begin);
                _player.SetSource(currentAudio.SourceStream);
            }
            else
            {
                _player.Source = currentAudio.SourceUri;
            }
            _playOnMediaLoad = false;
        }
 /// <summary>
 /// Load the given phrase without playing.
 /// </summary>
 /// <param name="currentPhrase">The current phrase.</param>
 public abstract void LoadPhrase(Phrase currentPhrase);
 /// <summary>
 /// Starts playing the given phrase.
 /// </summary>
 /// <param name="currentPhrase">The current phrase.</param>
 public abstract void StartPlaying(Phrase currentPhrase);
 // Public Methods (7)
 /// <summary>
 /// Interrupts the existing playback with the given phrase. If the voice is not currently playing, 
 /// the given phrase is simply spoken.
 /// </summary>
 /// <param name="immediatePhrase">The immediate phrase to speak.</param>
 /// <remarks>If another voice is speaking, it is the presenter's responsibility to pause and resume
 /// playback as needed.</remarks>
 public abstract void InterruptPlayback(Phrase immediatePhrase);
Exemple #12
0
        /// <summary>
        /// Starts the audio playback of the given phrase.
        /// </summary>
        /// <param name="currentPhrase">The phrase to speak.</param>
        public void StartSpeakingPhrase(Phrase currentPhrase)
        {
            if(CurrentVoice != null)
            {
                CurrentVoice.Stop();
            }

            CurrentVoice = VoiceFactory.GetVoice(currentPhrase, AudioPlayer);

            if(CurrentVoice != null)
            {
                //Set handler delegate and start playing
                CurrentVoice.FinishedPlaying = currentVoice_FinishedPlaying;

                //if the application voice is currently speaking, then we only want to load the new phrase
                if(!_appVoiceSpeaking)
                {
                    CurrentVoice.StartPlaying(currentPhrase);
                }
                else
                {
                    CurrentVoice.LoadPhrase(currentPhrase);
                }
            }
        }
 internal PhraseConstructionKit()
 {
     ConstructedPhrase = new Phrase();
 }
 /// <summary>
 /// Load the given phrase without playing.
 /// </summary>
 /// <param name="currentPhrase">The current phrase.</param>
 public override void LoadPhrase(Phrase currentPhrase)
 {
     //do nothing different than start playing
     StartPlaying(currentPhrase);
 }
        /// <summary>
        /// Starts playing the given phrase.
        /// </summary>
        /// <param name="currentPhrase">The current phrase.</param>
        public override void StartPlaying(Phrase currentPhrase)
        {
            _startTime = DateTime.Now;
            _totalElapsedtime = new TimeSpan(0L); //Reset elapsed time.

            //Calculate appropriate interval to 'play' based on length of text.
            int totalInterval = 0;
            string text = currentPhrase.Text;
            if (!String.IsNullOrEmpty(text))
                totalInterval = text.Length * _MILLISECONDS_PER_CHARACTER;
            totalInterval = Math.Max(totalInterval, _MIN_MILLISECONDS_DURATION);
            _startingInterval = new TimeSpan(0, 0, 0, 0, totalInterval);

            _timer.Interval = _startingInterval;
            _timer.Start();
        }