Esempio n. 1
0
        protected async override void OnNavigatedFrom(NavigationEventArgs e)
        {
            if (IsRecognizing)
            {
                Cancellation?.Cancel();
                await SpeechRec?.StopRecognitionAsync();
            }
            else
            {
                Cancellation?.Dispose();
                Cancellation = null;
            }

            AudioPlay.Stop();
            AudioPlay.Source = null;

            SpeechRec?.Dispose();
            SpeechRec = null;

            SpeechSynth?.Dispose();
            SpeechSynth                 = null;
            LoadTask                    = null;
            StatusText.Visibility       = Visibility.Collapsed;
            ListeningDisplay.Visibility = Visibility.Collapsed;
        }
Esempio n. 2
0
        private async void Ellipse_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            lock (SyncRootProvider.SyncRoot)
            {
                if (IsRecognizing)
                {
                    return;
                }
                IsRecognizing = true;
            }

            AudioPlay.Stop();

            StatusText.Visibility       = Visibility.Collapsed;
            ListeningDisplay.Visibility = Visibility.Visible;

            string RecResult = await WindowsLocalRecognizeAsync();

            if (RecResult == null)
            {
                IsRecognizing = false;
                return;
            }
            if (RecResult == "Failure")
            {
                ListeningDisplay.Visibility = Visibility.Collapsed;
                StatusText.Visibility       = Visibility.Visible;
                StatusText.Text             = "麦克风未检测到声音输入";
            }
            else
            {
                ListeningDisplay.Visibility = Visibility.Collapsed;
                StatusText.Visibility       = Visibility.Visible;
                StatusText.Text             = RecResult;
            }

            SpeechSynthesisStream stream = await SpeechSynth.SynthesizeTextToStreamAsync(StatusText.Text);

            AudioPlay.SetSource(stream, stream.ContentType);
            AudioPlay.Play();

            IsRecognizing = false;
        }