public MainPage()
        {
            this.InitializeComponent();

            var windowsSpeechRecognizer = new WindowsSpeechRecognizer();

            // Create the client. By default, it will poll the REST endpoint provided by the direct line, but optionally, we can give it a websocket implementation to use
            _botClient = new Microsoft.Bot.Client.BotClient(BotConnection.DirectLineSecret, BotConnection.ApplicationName)
            {
                // Use the speech synthesizer implementation in the WinRT Windows.Media.SpeechSynthesis namespace
                // Any voice supported by the API can be used. See this page as a reference: https://docs.microsoft.com/en-us/azure/cognitive-services/speech/api-reference-rest/bingvoiceoutput
                // The Built-in Windows speech synthesizer can be used here as an alternative, for a free solution:
                // SpeechSynthesizer = new WindowsSpeechSynthesizer(),
                SpeechSynthesizer = new CognitiveServicesSpeechSynthesizer(BotConnection.BingSpeechKey, Microsoft.Bot.Client.SpeechSynthesis.CognitiveServices.VoiceNames.Jessa_EnUs),

                // Use the Cognitive Services Speech-To-Text API, with speech priming support, as the speech recognizer
                // The Built-in WindowsSpeechRecognizer can be used here as an alternative, for a free solution:
                // SpeechRecognizer = windowsSpeechRecognizer,
                SpeechRecognizer = new CognitiveServicesSpeechRecognizer(BotConnection.BingSpeechKey),

                // Give us the ability to trigger speech recognition on keywords
                // The WindowsMediaSpeechRecognizer can also be used as the primary speech recognizer, instead of CognitiveServicesSpeechRecognizer (above)
                // for a free solution.
                TriggerRecognizer = windowsSpeechRecognizer
            };

            // Attach to the callbacks the client provides for observing the state of the bot
            // This will be called every time the bot sends down an activity
            _botClient.ConversationUpdated += OnConversationUpdated;

            // Speech-related events
            _botClient.SpeechRecognitionStarted += OnSpeechRecognitionStarted;
            _botClient.IntermediateSpeechRecognitionResultReceived += OnIntermediateSpeechRecognitionResultReceived;
            _botClient.SpeechRecognitionEnded += OnSpeechRecognitionEnded;
            _botClient.FinalSpeechRecognitionResultReceived += OnFinalSpeechRecognitionResultReceived;
            _botClient.SpeechSynthesisEnded += OnSpeechSynthesisEnded;

            // Set triggers, so that, when the user says "listen" or "what is" the bot client will start speech recognition
            _botClient.SetStartSpeechRecognitionTriggers(new string[] { "listen", "trivia bot" });

            _countdownTimer.PropertyChanged += UpdateCountdown;

            // Kick off the conversation
            _startConversationTask = _botClient.StartConversation();
        }
Пример #2
0
        public MainPage()
        {
            this.InitializeComponent();

            var windowsSpeechRecognizer = new WindowsMediaSpeechRecognizer();

            // Create the client. By default, it will poll the REST endpoint provided by the direct line, but optionally, we can give it a websocket implementation to use
            _botClient = new Microsoft.Bot.Client.BotClient(BotConnection.DirectLineSecret, BotConnection.ApplicationName, new Microsoft.Bot.Client.DirectLine.WebSocketConnection())
            {
                // Use the speech synthesizer implementation in the WinRT Windows.Media.SpeechSynthesis namespace
                SpeechSynthesizer = new WindowsMediaSpeechSynthesizer(),

                // Use the Cognitive Services Speech-To-Text API, with speech priming support, as the speech recognizer
                #error Please provide a Bing Speech API key, or replace this line with "SpeechRecognizer = windowsSpeechRecognizer,"
                SpeechRecognizer = new CognitiveServicesSpeechRecognizer(null),

                // Give us the ability to trigger speech recognition on keywords
                // The WindowsMediaSpeechRecognizer can also be used as the primary SpeechRecognizer, instead of CognitiveServicesSpeechRecognizer (above)
                // for a free solution.
                TriggerRecognizer = windowsSpeechRecognizer
            };

            // Attach to the callbacks the client provides for observing the state of the bot
            // This will be called every time the bot sends down an activity
            _botClient.ConversationUpdated += OnConversationUpdated;

            // Speech-related events
            _botClient.SpeechRecognitionStarted += OnSpeechRecognitionStarted;
            _botClient.IntermediateSpeechRecognitionResultReceived += OnIntermediateSpeechRecognitionResultReceived;
            _botClient.SpeechRecognitionEnded += OnSpeechRecognitionEnded;
            _botClient.FinalSpeechRecognitionResultReceived += OnFinalSpeechRecognitionResultReceived;
            _botClient.SpeechSynthesisEnded += OnSpeechSynthesisEnded;

            // Set triggers, so that, when the user says "listen" or "what is" the bot client will start speech recognition
            _botClient.SetStartSpeechRecognitionTriggers(new string[] { "listen", "trivia bot" });

            _countdownTimer.PropertyChanged += UpdateCountdown;

            // Kick off the conversation
            _startConversationTask = _botClient.StartConversation();
        }