Example #1
0
        internal static NarrationEventArgs Create(NarrationEventArgs argsBase, string suggestion)
        {
            var args = new NarrationEventArgs(argsBase.KeyTop, NarrationEventType.GotSuggestion, argsBase.Utterance, argsBase.CursorPosition, argsBase.IsRepeat, argsBase.CompletedWord)
            {
                Suggestion = suggestion
            };

            return(args);
        }
Example #2
0
        internal static NarrationEventArgs Create(AudioGesture gesture)
        {
            var args = new NarrationEventArgs(null, NarrationEventType.VocalGesture, null, 0, false, null)
            {
                Gesture = gesture
            };

            return(args);
        }
Example #3
0
        public void SpeakEffect(AudioGesture effect)
        {
            var args = NarrationEventArgs.Create(effect);

            _lastNarrationEventArgs = args;
            _narrator.OnNarrationEvent(args);

            TelemetryMessage.Telemetry.TraceEvent(TraceEventType.Information, IdMapper.GetId <AudioGesture>(), effect.ToString());
        }
Example #4
0
        internal static NarrationEventArgs Create(object key, NarrationEventType eventType, string utterance, int cursorPosition, bool isRepeat, string completedWord)
        {
            var special = key as SpecialKeytop;
            var vocal   = special != null ? (special.Vocal ?? special.Keytop) : key as string;
            var keyTop  = vocal ?? "wibble";

            var args = new NarrationEventArgs(keyTop, eventType, utterance, cursorPosition, isRepeat, completedWord);

            return(args);
        }
Example #5
0
        void RaiseNarrationEvent(object key, NarrationEventType eventType, string completedWord)
        {
            if (IsAllSelected)
            {
                _trainingStartTime = DateTime.UtcNow;
                _trainingKeyCount  = 1;
            }
            else
            {
                _trainingKeyCount++;
            }

            var args = NarrationEventArgs.Create(key, eventType, TextSlice.Text, TextSlice.Start, IsAllSelected, completedWord);

            _lastNarrationEventArgs = args;
            _narrator.OnNarrationEvent(args);
        }
Example #6
0
        IPrediction DisplaySuggestions(int seedLength, IEnumerable <IPredictionSuggestion> wordSuggestions, IEnumerable <IPredictionSuggestion> phraseSuggestions)
        {
            if (_queuedPrediction == null)
            {
                var isShifted = ShiftToggleState.IsChecked;

                var suggestions = new List <string>();

                var itemPosition = 0;
                foreach (var suggestion in wordSuggestions)
                {
                    if (itemPosition < SuggestionItems.Count)
                    {
                        var item        = SuggestionItems[itemPosition];
                        var shiftedText = ShiftText(isShifted, suggestion.Text);
                        item.Keytop     = shiftedText;
                        item.Visibility = Visibility.Visible;
                        item.IsEnabled  = true;
                        item.Suggestion = suggestion;

                        suggestions.Add(shiftedText);
                    }

                    itemPosition++;
                }

                while (itemPosition < SuggestionItems.Count)
                {
                    var item = SuggestionItems[itemPosition];
                    itemPosition++;

                    item.Visibility = Visibility.Collapsed;
                    item.Suggestion = null;
                }

                SuggestionsHelper.SetSuggestions(suggestions);

                if (suggestions.Count != 0 && _lastNarrationEventArgs != null &&
                    (seedLength != 0 ||
                     _environment.AppSettings.Prediction.PredictionNovelty == PredictionNovelty.FromScratch))
                {
                    var args = NarrationEventArgs.Create(_lastNarrationEventArgs, suggestions[0]);
                    _narrator.OnNarrationEvent(args);
                }

                itemPosition = 0;
                foreach (var phrase in phraseSuggestions)
                {
                    if (itemPosition < PhraseItems.Count)
                    {
                        var item = PhraseItems[itemPosition];
                        item.Keytop     = phrase.Text;
                        item.Visibility = Visibility.Visible;
                        item.IsEnabled  = true;
                        item.Suggestion = phrase;
                    }

                    itemPosition++;
                }

                while (itemPosition < PhraseItems.Count)
                {
                    var item = PhraseItems[itemPosition];
                    itemPosition++;

                    item.Visibility = Visibility.Collapsed;
                    item.Suggestion = null;
                }
            }

            var prediction = _queuedPrediction;

            _queuedPrediction = null;

            _suggesterRunning = prediction != null;
            return(prediction);
        }
        void INarrator.OnNarrationEvent(NarrationEventArgs e)
        {
            var spoken = false;

            if (e.EventType != NarrationEventType.GotSuggestion)
            {
                _activityDisplayProvider.IsTyping = (e.EventType == NarrationEventType.SimpleTyping || !e.IsRepeat) &&
                                                    (e.EventType != NarrationEventType.Utter || e.EventType == NarrationEventType.Reset);

                if (e.CompletedWord != null && _settings.ReadCompletedWords)
                {
                    PlayFeedbackWord(e.Utterance.Substring(0, e.CursorPosition), e.CompletedWord);
                    spoken = true;
                }
            }

            switch (e.EventType)
            {
            case NarrationEventType.VocalGesture:
                if (_settings.PlayVocalGestures)
                {
                    CancelPendingSound();

                    var theme   = _textToAudioProvider.GetAudioTheme(Voice.Sentence);
                    var gesture = _audioProvider.GetAudioGesture(theme, e.Gesture);
                    PlayUnconditionalFeedbackSound(gesture);

                    spoken = true;
                }
                break;

            case NarrationEventType.SimpleTyping:
            case NarrationEventType.Simple:
                if (_settings.ReadKeyTops)
                {
                    PlayFeedback(Voice.Letter, e.KeyTop);
                    spoken = true;
                }
                break;

            case NarrationEventType.WordCompletion:
                if (_settings.ReadKeyTops && !spoken)
                {
                    PlayFeedback(Voice.Letter, e.KeyTop);
                    spoken = true;
                }
                break;

            case NarrationEventType.Reset:
                if (_settings.ReadKeyTops)
                {
                    PlayFeedback(Voice.Letter, e.KeyTop);
                    spoken = true;
                }
                Reset();
                break;

            case NarrationEventType.Utter:
                spoken |= PlayFeedbackComposedSentence(e.KeyTop, e.Utterance, e.IsRepeat);
                break;

            case NarrationEventType.FixedUtter:
                if (_settings.SentenceBehavior != SentenceBehavior.Command)
                {
                    PlayFeedbackFixedSentence(e.KeyTop);
                }
                break;

            case NarrationEventType.AcceptSuggestion:
                if (_settings.ReadKeyTops && !spoken)
                {
                    PlayFeedback(Voice.Letter, e.CompletedWord);
                    spoken = true;
                }
                break;

            case NarrationEventType.GotSuggestion:
                if (_settings.ReadTopSuggestion)
                {
                    PlayFeedback(Voice.Letter, e.Suggestion);
                }
                spoken = true;
                break;

            default:
                Debug.Fail($"Unknown event type {e.EventType}");
                break;
            }

            if (!spoken && _settings.IsClickOn)
            {
                PlayUnconditionalFeedbackSound(_audioProvider.Click);
            }
        }