コード例 #1
0
ファイル: App.xaml.cs プロジェクト: jle33/hackuci
        protected override void OnActivated(IActivatedEventArgs args)
        {
            azureConnector conn = new azureConnector();
            base.OnActivated(args);
            if (args.Kind == ActivationKind.VoiceCommand)
            {
                var commandArgs = args as VoiceCommandActivatedEventArgs;
                if (commandArgs != null)
                {
                    SpeechRecognitionResult speechRecognitionResult = commandArgs.Result;
                    var voiceCommandName = speechRecognitionResult.RulePath[0];

                    switch (voiceCommandName)
                    {
                        case "OrderBurger":
                            conn.sendSBMessageToTopic("Ordered one burger", "ordermeal");
                            break;
                        case "OrderSoda":
                            conn.sendSBMessageToTopic("Ordered one soda", "ordermeal");
                            break;
                    }
                }
            }
            Window.Current.Activate();
        }
コード例 #2
0
ファイル: MainPage.xaml.cs プロジェクト: n3d0r/hackuci
        public MainPage()
        {
            this.InitializeComponent();

            // This is a static public property that allows downstream pages to get a handle to the MainPage instance
            // in order to call methods that are in this class.
            Current = this;
            SampleTitle.Text = FEATURE_NAME;
            azureConnector conn = new azureConnector();
            conn.sendSBMessageToTopic("Hello from hack uci", "ordermeal");
            conn.runSubscriptionReceiver("ordermeal", "orderMealSubscription");
        }
コード例 #3
0
       /* string dfa = "";
        class msgQueue { public string msg; };

        private async void dowork(object obj)
        {
            while (true)
            {
                string temp = conn.getMessage();
                if (temp != null)
                {
                    textToSynthesize.Text = temp;
                }
            }
        } */

        public SynthesizeTextScenario()
        {
            InitializeComponent();
            synthesizer = new SpeechSynthesizer();
            
            speechContext = ResourceContext.GetForCurrentView();
            speechContext.Languages = new string[] { SpeechSynthesizer.DefaultVoice.Language };

            speechResourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("LocalizationTTSResources");

            
            conn = new azureConnector();
            //conn.sendSBMessageToTopic("Hello hello", "ordermeal");
            //conn.sendSBMessageToTopic("Oh Burger Burger", "ordermeal");
            conn.runSubscriptionReceiver("ordermeal", "orderMealSubscription");

            //workerThread msgChecker = new workerThread(this.dowork);
            //msgChecker.Start(new msgQueue() {msg = ""});
            InitializeListboxVoiceChooser();
        }
コード例 #4
0
        /// <summary>
        /// Uses the recognizer constructed earlier to listen for speech from the user before displaying 
        /// it back on the screen. Uses developer-provided UI for user feedback.
        /// </summary>
        /// <param name="sender">Button that triggered this event</param>
        /// <param name="e">State information about the routed event</param>
        private async void RecognizeWithoutUIDictationGrammar_Click(object sender, RoutedEventArgs e)
        {
            heardYouSayTextBlock.Visibility = resultTextBlock.Visibility = Visibility.Collapsed;

            // Disable the UI while recognition is occurring, and provide feedback to the user about current state.
            btnRecognizeWithUI.IsEnabled = false;
            btnRecognizeWithoutUI.IsEnabled = false;
            cbLanguageSelection.IsEnabled = false;
            hlOpenPrivacySettings.Visibility = Visibility.Collapsed;
            listenWithoutUIButtonText.Text = " listening for speech...";

            // Start recognition.
            try
            {
                recognitionOperation = speechRecognizer.RecognizeAsync();
                SpeechRecognitionResult speechRecognitionResult = await recognitionOperation;
                // If successful, display the recognition result.
                if (speechRecognitionResult.Status == SpeechRecognitionResultStatus.Success)
                {
                    azureConnector conn = new azureConnector();
                    heardYouSayTextBlock.Visibility = resultTextBlock.Visibility = Visibility.Visible;
                    resultTextBlock.Text = speechRecognitionResult.Text;


                    switch (resultTextBlock.Text)
                    {
                        case "I would like a burger.":
                            conn.sendSBMessageToTopic("An order of one burger has been placed.", "ordermeal");
                            break;
                        case "I would like a soda.":
                            conn.sendSBMessageToTopic("An order of one soda has been placed.", "ordermeal");
                            break;
                        case "And a big order of fries.":
                            conn.sendSBMessageToTopic("An order of one big fries has been placed.", "ordermeal");
                            break;
                    }

                    outBox.Text = resultTextBlock.Text;
                    //conn.runSubscriptionReceiver("ordermeal", "orderMealSubscription");
                    //outBox.Text = conn.getMessage();
                }
                else
                {
                    resultTextBlock.Visibility = Visibility.Visible;
                    resultTextBlock.Text = string.Format("Speech Recognition Failed, Status: {0}", speechRecognitionResult.Status.ToString());
                }
            }
            catch (TaskCanceledException exception)
            {
                // TaskCanceledException will be thrown if you exit the scenario while the recognizer is actively
                // processing speech. Since this happens here when we navigate out of the scenario, don't try to 
                // show a message dialog for this exception.
                System.Diagnostics.Debug.WriteLine("TaskCanceledException caught while recognition in progress (can be ignored):");
                System.Diagnostics.Debug.WriteLine(exception.ToString());
            }
            catch (Exception exception)
            {
                // Handle the speech privacy policy error.
                if ((uint)exception.HResult == HResultPrivacyStatementDeclined)
                {
                    hlOpenPrivacySettings.Visibility = Visibility.Visible;
                }
                else
                {
                    var messageDialog = new Windows.UI.Popups.MessageDialog(exception.Message, "Exception");
                    await messageDialog.ShowAsync();
                }
            }

            // Reset UI state.
            listenWithoutUIButtonText.Text = " without UI";
            cbLanguageSelection.IsEnabled = true;
            btnRecognizeWithUI.IsEnabled = true;
            btnRecognizeWithoutUI.IsEnabled = true;
        }