Exemplo n.º 1
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral        = taskInstance.GetDeferral();
            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            try
            {
                voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

                voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                var interpretation = voiceCommand.SpeechRecognitionResult.SemanticInterpretation;

                await ProcessGenerateFactAsync(interpretation);

                this.serviceDeferral.Complete();
            }
            catch (Exception ex)
            {
            }
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            // Create the deferral by requesting it from the task instance
            serviceDeferral = taskInstance.GetDeferral();

            AppServiceTriggerDetails triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null && triggerDetails.Name.Equals("VoiceCommandService"))
            {
                voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

                VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                // Perform the appropriate command depending on the operation defined in VCD
                switch (voiceCommand.CommandName)
                {
                case "CheckTemperature":
                    VoiceCommandUserMessage userMessage = new VoiceCommandUserMessage();
                    userMessage.DisplayMessage = "The current temperature is 23 degrees";
                    userMessage.SpokenMessage  = "The current temperature is 23 degrees";

                    VoiceCommandResponse response = VoiceCommandResponse.CreateResponse(userMessage, null);
                    await voiceServiceConnection.ReportSuccessAsync(response);

                    break;

                default:
                    break;
                }
            }

            // Once the asynchronous method(s) are done, close the deferral
            serviceDeferral.Complete();
        }
Exemplo n.º 3
0
 private void btnAddVoiceCommand_Click(object sender, EventArgs e)
 {
     // Checking that the user has filled out the form correctly
     if (txtVoiceCommandWord.Text == "" || txtVoiceCommandKeys.Text == "")
     {
         MessageBox.Show("Please ensure you have added a voice keyword and selected the keys you want to fire.",
                         "Error", MessageBoxButtons.OK);
     }
     else
     {
         string keystrings = "";
         voiceCommandKeys.ForEach(x => keystrings += (x).ToString() + " ");
         keystrings = keystrings.TrimEnd();
         keystrings = keystrings.Replace(" ", ",");
         Command command = new VoiceCommand(txtVoiceCommandWord.Text.ToLower(), keystrings,
                                            SharedObjectsSingleton.Instance().inputSimulator);
         settings.Commands.Add(command);
         // Update the list of commands
         FillVoiceCommandTable();
         // Clear the text fields for possible new input
         txtVoiceCommandWord.Text = "";
         txtVoiceCommandKeys.Text = "";
         //Empty the keylist for new possible input
         voiceCommandKeys = new List <Keys>();
     }
 }
Exemplo n.º 4
0
        private void buildBlob(byte[] data)
        {
            if (data == null || data.Length < 16)
                return;

            this.raw = data;
            try
            {
                int i = (this.tell ? 1 : 0);

                byte[] pre = new byte[4];
                pre[0] = 0;
                pre[1] = data[i+0];
                pre[2] = data[i+1];
                pre[3] = data[i+2];

                if (BitConverter.ToInt32(pre, 0) == voicePrefix)
                {
                    i += 3;
                    this.style = (VoiceStyle)Enum.Parse(typeof(VoiceStyle), Packet.popString(ref data, ref i).ToString(), true);
                    this.cmd = (VoiceCommand)Enum.Parse(typeof(VoiceCommand), Packet.popString(ref data, ref i).ToString(), true);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
            }
        }
        public void ExecuteVoiceCommand(VoiceCommand command)
        {
            switch (command)
            {
            case VoiceCommand.Start:
                if (bodyManager != null)
                {
                    initialPositionComputer = new InitialPositionComputer(bodyManager);
                    RecordInitialPosition();
                    StartRecordingTimer();
                }
                break;

            case VoiceCommand.Up:
                if (gestureList.SelectedIndex > 0)
                {
                    gestureList.SelectedIndex--;
                }
                break;

            case VoiceCommand.Down:
                if (gestureList.SelectedIndex < gestureList.Items.Count)
                {
                    gestureList.SelectedIndex++;
                }
                break;
            }
        }
Exemplo n.º 6
0
 private void InitWearHfCommand(VoiceCommand command)
 {
     wearHf.AddVoiceCommand(command.text, (text) =>
     {
         command.action?.Invoke();
     });
 }
Exemplo n.º 7
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            // add service functionality here
            // inform the system that the background task may
            // continue after the Run method has completed
            this._deferral = taskInstance.GetDeferral();

            // added event handler to handle cancel by user
            taskInstance.Canceled += TaskInstance_Canceled;

            // trigger details gives more information about the
            // task instance
            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if ((triggerDetails != null) &&
                (triggerDetails.Name == "CortanaBackgroundService"))
            {
                // try to get the voice command and respond to it.
                try
                {
                    // Retrieves a VoiceCommandServiceConnection object
                    // from the AppServiceTriggerDetails that
                    // contains info associated with the background
                    // task for the app service
                    voiceServiceConection =
                        VoiceCommandServiceConnection.
                        FromAppServiceTriggerDetails(triggerDetails);

                    // set up the command completed method to indicate completion
                    // calls deferral.complete here
                    voiceServiceConection.VoiceCommandCompleted += VoiceServiceConection_VoiceCommandCompleted;

                    // get the voice command information
                    VoiceCommand voiceCommand = await voiceServiceConection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "howsMyCoffee":
                    {
                        sendUpdateMessageByReturn();
                        break;
                    }

                    default:
                    {
                        launchAppInForeground();
                        break;
                    }
                    }
                }
                finally
                {
                    if (this._deferral != null)
                    {
                        // complete the service deferral
                        this._deferral.Complete();
                    }
                } // end try
            }
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral        = taskInstance.GetDeferral();
            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            cortanaResourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("Resources");

            cortanaContext = ResourceContext.GetForViewIndependentUse();

            dateFormatInfo = CultureInfo.CurrentCulture.DateTimeFormat;

            if (triggerDetails != null && triggerDetails.Name == "JeedomAppVoiceCommandService")
            {
                try
                {
                    voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    var    userMessage = new VoiceCommandUserMessage();
                    string message     = "";


                    // Ajout d'une requet jeedom pour retrouver la commande
                    switch (voiceCommand.CommandName)
                    {
                    case "JeedomInteractList":
                        string CortanaVoiceCommande = voiceCommand.Properties["InteractList"][0];
                        await Jeedom.RequestViewModel.Instance.interactTryToReply(CortanaVoiceCommande);

                        message = Jeedom.RequestViewModel.Instance.InteractReply;
                        break;

                    default:
                        LaunchAppInForeground();
                        break;
                    }

                    userMessage.DisplayMessage = message;
                    userMessage.SpokenMessage  = message;


                    var response = VoiceCommandResponse.CreateResponse(userMessage);
                    response.AppLaunchArgument = message;


                    await voiceServiceConnection.ReportSuccessAsync(response);
                }
                catch (Exception ex)
                {
                    //System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
            }
        }
Exemplo n.º 9
0
 public void Stop()
 {
     _recognizer.RecognizeAsyncStop();
     Activated = false;
     Command   = VoiceCommand.None;
     Disabled  = true;
 }
        public void ExecuteVoiceCommand(VoiceCommand command)
        {
            switch (command)
            {
            case VoiceCommand.Start:
                if (bodyManager != null)
                {
                    initialPositionComputer = new InitialPositionComputer(bodyManager);
                    gestureRecorder         = new GestureRecorder(bodyManager, initialPositionComputer, gestureIndex.GestureDB[gestureIndex.NewGesture].fileName);
                    gestureRecorder.GestureRecordEventHandler += GestureRecordEventHandler;
                    gestureRecorder.RecordInitialPosition(true);
                    StartRecordingTimer();
                }
                break;

            case VoiceCommand.Up:
                if (gestureList.SelectedIndex > 0)
                {
                    gestureList.SelectedIndex--;
                }
                break;

            case VoiceCommand.Down:
                if (gestureList.SelectedIndex < gestureList.Items.Count)
                {
                    gestureList.SelectedIndex++;
                }
                break;

            case VoiceCommand.Select: //TODO
                Console.WriteLine("select");
                break;
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Helper method for initalizing the voice service, bridge, and lights. Returns if successful.
        /// </summary>
        private async Task <bool> InitializeAsync(AppServiceTriggerDetails triggerDetails)
        {
            _voiceServiceConnection =
                VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
            _voiceServiceConnection.VoiceCommandCompleted += (s, e) => _deferral.Complete();

            _voiceCommand = await _voiceServiceConnection.GetVoiceCommandAsync();

            _colors = HsbColor.CreateAll().ToDictionary(x => x.Name);

            var localStorage = ApplicationData.Current.LocalSettings.Values;

            _bridge = new Bridge(
                localStorage["bridgeIp"].ToString(), localStorage["userId"].ToString());
            try
            {
                _lights = await _bridge.GetLightsAsync();
            }
            catch (Exception)
            {
                var response = CreateCortanaResponse("Sorry, I couldn't connect to your bridge.");
                await _voiceServiceConnection.ReportFailureAsync(response);

                return(false);
            }
            if (!_lights.Any())
            {
                var response = CreateCortanaResponse("Sorry, I couldn't find any lights.");
                await _voiceServiceConnection.ReportFailureAsync(response);

                return(false);
            }
            return(true);
        }
Exemplo n.º 12
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            this.serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails =
                taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null &&
                triggerDetails.Name == "CortanaAppService")
            {
                try
                {
                    voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted +=
                        VoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "drinkAGlass":
                    {
                        var subject = voiceCommand.Properties["subject"][0];
                        var amount  = voiceCommand.Properties["amount"][0];
                        await SendCompletionMessageForFixedAmount(amount, subject);

                        break;
                    }

                    case "drinkAmount":
                    {
                        var amount   = voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties["amount"][0];
                        var beverage = voiceCommand.Properties["beverage"][0];
                        await SendCompletionMessageForAmount(amount, beverage);

                        break;
                    }

                    // As a last resort launch the app in the foreground
                    default:
                        LaunchAppInForeground();
                        break;
                    }
                }
                finally
                {
                    //if (this.serviceDeferral != null)
                    //{
                    //    //Complete the service deferral
                    //    this.serviceDeferral.Complete();
                    //}
                }
            }
        }
Exemplo n.º 13
0
        /*  ResourceMap cortanaResourceMap;
         * ResourceContext cortanaContext;
         * DateTimeFormatInfo dateFormatInfo;*/

        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            ServiceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += TaskInstance_Canceled;

            var TriggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (TriggerDetails != null && TriggerDetails.Name == "TDTCortanaCommandServices")
            {
                VoiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(TriggerDetails);

                VoiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                // GetVoiceCommandAsync establishes initial connection to Cortana, and must be called prior to any
                // messages sent to Cortana. Attempting to use ReportSuccessAsync, ReportProgressAsync, etc
                // prior to calling this will produce undefined behavior.
                VoiceCommand voiceCommand = await VoiceServiceConnection.GetVoiceCommandAsync();

                switch (voiceCommand.CommandName)
                {
                case "ShowMyTasks":
                    string Style;
                    try
                    {
                        Style = voiceCommand.Properties["Style"][0];
                    }
                    catch
                    {
                        Style = "";
                    }
                    await ShowTasks(Style, voiceCommand.SpeechRecognitionResult.Text.Contains("today"));

                    break;

                case "CompleteSpecificTask":
                    var CompletedTask = voiceCommand.Properties["Tasks"][0];
                    CompleteTask(CompletedTask);
                    break;

                case "DeleteSpecificTask":
                    var DeletedTask = voiceCommand.Properties["Tasks"][0];
                    DeleteTask(DeletedTask);
                    break;

                case "ShowDetailForSpecificTask":
                    var DetailedTask = voiceCommand.Properties["Tasks"][0];
                    ShowDetailsOfTask(DetailedTask);
                    break;

                default:
                    // As with app activation VCDs, we need to handle the possibility that
                    // an app update may remove a voice command that is still registered.
                    // This can happen if the user hasn't run an app since an update.
                    //LaunchAppInForeground();
                    break;
                }
            }
        }
Exemplo n.º 14
0
        public VoiceCommand GetCurrentVoiceCommand()
        {
            VoiceCommand command = lastRecognizedVoiceCommand;

            lastRecognizedVoiceCommand = VoiceCommand.None;

            return command;
        }
Exemplo n.º 15
0
        private void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            if (Activated)
            {
                if (Command == VoiceCommand.Search)
                {
                    VoiceCommandSent?.Invoke($"{e.Result.Text}");
                    Command = VoiceCommand.None;
                    _recognizer.UnloadGrammar(dict);
                    Activated = false;
                }
                else if (Command == VoiceCommand.Play)
                {
                    VoiceCommandSent?.Invoke($"{e.Result.Text}");
                    Command = VoiceCommand.None;
                    _recognizer.UnloadGrammar(dict);
                    Activated = false;
                }
                else if (Command == VoiceCommand.Queue)
                {
                    VoiceCommandSent?.Invoke($"{e.Result.Text}");
                    Command = VoiceCommand.None;
                    _recognizer.UnloadGrammar(dict);
                    Activated = false;
                }
            }

            if (!Activated)
            {
                if (e.Result.Text == "horsify search")
                {
                    Activated = true;
                    VoiceCommandSent?.Invoke($"{e.Result.Text}");
                    Console.WriteLine("horsify search activated");
                    _recognizer.LoadGrammar(dict);
                    Command = VoiceCommand.Search;
                    return;
                }
                else if (e.Result.Text == "horsify play")
                {
                    Activated = true;
                    VoiceCommandSent?.Invoke($"{e.Result.Text}");
                    Console.WriteLine("horsify play activated");
                    _recognizer.LoadGrammar(dict);
                    Command = VoiceCommand.Play;
                    return;
                }
                else if (e.Result.Text == "horsify queue")
                {
                    Activated = true;
                    VoiceCommandSent?.Invoke($"{e.Result.Text}");
                    Console.WriteLine("horsify queue activated");
                    _recognizer.LoadGrammar(dict);
                    Command = VoiceCommand.Queue;
                    return;
                }
            }
        }
Exemplo n.º 16
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            this.serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null &&
                triggerDetails.Name == "TalkToMeVoiceCommandService")
            {
                try
                {
                    voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
                    voiceServiceConnection.VoiceCommandCompleted += VoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "startMyPresentation":
                        ShowStartMyPresentation();
                        break;

                    case "endMyPresentation":
                        ShowEndMyPresentation();
                        break;

                    case "bankBalance":
                        SendCompletionMessageForBankAccount();
                        break;

                    case "whatDoYouThinkAbout":
                        var name = voiceCommand.Properties["name"][0];
                        SendCompletionMessageForName(name);
                        break;

                    case "birthday":
                        var birthdayName = voiceCommand.Properties["name"][0];
                        SingABirthdaySong(birthdayName);
                        break;

                    default:
                        LaunchAppInForeground();
                        break;
                    }
                }
                finally
                {
                    if (this.serviceDeferral != null)
                    {
                        //Complete the service deferral
                        this.serviceDeferral.Complete();
                    }
                }
            }
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            //Take a service deferral so the service isn&#39;t terminated.
            this.serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails =
                taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null &&
                triggerDetails.Name == "VoiceCommandsService")
            {
                try
                {
                    voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted += VoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "calculatePropablityDSA":
                    {
                        string e1             = voiceCommand.Properties["eigenschaft1"][0];
                        string e2             = voiceCommand.Properties["eigenschaft2"][0];
                        string e3             = voiceCommand.Properties["eigenschaft3"][0];
                        string tawString      = voiceCommand.Properties["taw"][0];
                        var    voiceParameter = new DSAVoiceCommand(e1, e2, e3);
                        var    calculator     = new DSAPropabilityCaluator(voiceParameter.Eigentschaft1, voiceParameter.Eigentschaft2, voiceParameter.Eigentschaft3);
                        int    taw;
                        if (!int.TryParse(tawString, out taw))
                        {
                            taw = 5;
                        }
                        var probability = calculator.CalcualteDicePropability(taw);
                        SendCompletionMessageForDestination(probability, voiceParameter);
                        break;
                    }

                    // As a last resort, launch the app in the foreground.
                    default:
                        LaunchAppInForeground();
                        break;
                    }
                }
                finally
                {
                    if (this.serviceDeferral != null)
                    {
                        // Complete the service deferral.
                        this.serviceDeferral.Complete();
                    }
                }
            }
        }
Exemplo n.º 18
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral        = taskInstance.GetDeferral();
            taskInstance.Canceled += TaskInstance_Canceled;

            httpClient = new HttpClient();

            AppServiceTriggerDetails triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null && triggerDetails.Name == "HuemongousVoiceCommandService")
            {
                voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
                voiceServiceConnection.VoiceCommandCompleted += VoiceServiceConnection_VoiceCommandCompleted;

                VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                if (voiceCommand.CommandName == "LightsOnOrOff")
                {
                    string lightState = voiceCommand.Properties["lightState"][0];
                    await HandleLightsOnOrOff(lightState);
                }
                else if (voiceCommand.CommandName == "LightOnOrOff")
                {
                    string lightState     = voiceCommand.Properties["lightState"][0];
                    string lightOrRoom    = voiceCommand.Properties["lightOrRoom"][0];
                    string lightPlurality = voiceCommand.Properties["lightPlurality"][0];
                    await HandleLightOnOrOff(lightState, lightOrRoom, lightPlurality);
                }
                else if (voiceCommand.CommandName == "SpecifyLightOnOrOff")
                {
                    string lightState = voiceCommand.Properties["lightState"][0];
                }
                else if (voiceCommand.CommandName == "SetLightScene")
                {
                    string scene = voiceCommand.Properties["scene"][0];
                }
                else if (voiceCommand.CommandName == "SetLightsColor")
                {
                    string color = voiceCommand.Properties["color"][0];
                    await HandleSetLightsColor(color);
                }
                else if (voiceCommand.CommandName == "SetLightColor")
                {
                    string lightOrRoom    = voiceCommand.Properties["lightOrRoom"][0];
                    string lightPlurality = voiceCommand.Properties["lightPlurality"][0];
                    string color          = voiceCommand.Properties["color"][0];
                }
                else if (voiceCommand.CommandName == "SpecifyLightColor")
                {
                    string color = voiceCommand.Properties["color"][0];
                }
                else
                {
                    Debug.WriteLine("unknown command");
                }
            }
        }
Exemplo n.º 19
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            _serviceDeferral = taskInstance.GetDeferral();

            // Register to receive an event if Cortana dismisses the background task. This will
            // occur if the task takes too long to respond, or if Cortana's UI is dismissed.
            // Any pending operations should be cancelled or waited on to clean up where possible.
            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;


            // Select the system language, which is what Cortana should be running as.
            _cortanaContext = ResourceContext.GetForViewIndependentUse();

            // This should match the uap:AppService and VoiceCommandService references from the
            // package manifest and VCD files, respectively. Make sure we've been launched by
            // a Cortana Voice Command.
            if (triggerDetails != null && triggerDetails.Name == "CortanaDialogFlow")
            {
                try
                {
                    _voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    _voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                    // GetVoiceCommandAsync establishes initial connection to Cortana, and must be called prior to any
                    // messages sent to Cortana. Attempting to use ReportSuccessAsync, ReportProgressAsync, etc
                    // prior to calling this will produce undefined behavior.
                    VoiceCommand voiceCommand = await _voiceServiceConnection.GetVoiceCommandAsync();

                    // Depending on the operation (defined in TestCortana:TestCortanaCommands.xml)
                    // perform the appropriate command.
                    switch (voiceCommand.CommandName)
                    {
                    case "changeAmbiance":
                        await SendCompletionMessageForAmbiance();

                        break;

                    default:
                        // As with app activation VCDs, we need to handle the possibility that
                        // an app update may remove a voice command that is still registered.
                        // This can happen if the user hasn't run an app since an update.
                        LaunchAppInForeground();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
            }
        }
Exemplo n.º 20
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            //Take a service deferral so the service isn't terminated
            this.serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails =
                taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null &&
                triggerDetails.Name == "CortanaAppService")
            {
                try
                {
                    voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted +=
                        VoiceCommandCompleted;

                    VoiceCommand voiceCommand = await
                                                voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "toggleSwitch":
                    {
                        var pref =
                            voiceCommand.Properties["pref"][0];
                        var switchname =
                            voiceCommand.Properties["switch"][0];
                        var state =
                            voiceCommand.Properties["state"][0];
                        await ToggleSwitch(pref, switchname, state);

                        break;
                    }

                    // As a last resort launch the app in the foreground
                    default:
                        LaunchAppInForeground();
                        break;
                    }
                }
                finally
                {
                    if (this.serviceDeferral != null)
                    {
                        //Complete the service deferral
                        this.serviceDeferral.Complete();
                    }
                }
            }
        }
        /// <summary>
        /// Background task entrypoint. Voice Commands using the <VoiceCommandService Target="...">
        /// tag will invoke this when they are recognized by Cortana, passing along details of the
        /// invocation.
        ///
        /// Background tasks must respond to activation by Cortana within 0.5 seconds, and must
        /// report progress to Cortana every 5 seconds (unless Cortana is waiting for user
        /// input). There is no execution time limit on the background task managed by Cortana,
        /// but developers should use plmdebug (https://msdn.microsoft.com/en-us/library/windows/hardware/jj680085%28v=vs.85%29.aspx)
        /// on the Cortana app package in order to prevent Cortana timing out the task during
        /// debugging.
        ///
        /// Cortana dismisses its UI if it loses focus. This will cause it to terminate the background
        /// task, even if the background task is being debugged. Use of Remote Debugging is recommended
        /// in order to debug background task behaviors. In order to debug background tasks, open the
        /// project properties for the app package (not the background task project), and enable
        /// Debug -> "Do not launch, but debug my code when it starts". Alternatively, add a long
        /// initial progress screen, and attach to the background task process while it executes.
        /// </summary>
        /// <param name="taskInstance">Connection to the hosting background service process.</param>
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral = taskInstance.GetDeferral();

            // Register to receive an event if Cortana dismisses the background task. This will
            // occur if the task takes too long to respond, or if Cortana's UI is dismissed.
            // Any pending operations should be cancelled or waited on to clean up where possible.
            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            // This should match the uap:AppService and VoiceCommandService references from the
            // package manifest and VCD files, respectively. Make sure we've been launched by
            // a Cortana Voice Command.
            if (triggerDetails != null && triggerDetails.Name == "AdventureWorksVoiceCommandService")
            {
                try
                {
                    voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    // Depending on the operation (defined in AdventureWorks:AdventureWorksCommands.xml)
                    // perform the appropriate command.
                    switch (voiceCommand.CommandName)
                    {
                    case "whenIsTripToDestination":
                        var destination = voiceCommand.Properties["destination"][0];
                        await SendCompletionMessageForDestination(destination);

                        break;

                    case "cancelTripToDestination":
                        var cancelDestination = voiceCommand.Properties["destination"][0];
                        await SendCompletionMessageForCancellation(cancelDestination);

                        break;

                    default:
                        // As with app activation VCDs, we need to handle the possibility that
                        // an app update may remove a voice command that is still registered.
                        // This can happen if the user hasn't run an app since an update.
                        LaunchAppInForeground();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
            }
        }
Exemplo n.º 22
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            _serviceDeferral = taskInstance.GetDeferral();


            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null && triggerDetails.Name == "CortanaBGService")
            {
                try
                {
                    voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted += VoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "blinds":
                    {
                        foreach (var prop in voiceCommand.Properties)
                        {
                            Debug.WriteLine(String.Format("prop {0} = {1}", prop.Key, prop.Value.ToString()));
                        }

                        var state = voiceCommand.Properties["blindState"][0];
                        var blind = voiceCommand.Properties["blindId"][0];

                        await ChangeBlindState(blind, state);

                        break;
                    }

                    // As a last resort launch the app in the foreground
                    default:
                        _serviceDeferral.Complete();
                        break;
                    }
                }
                catch (Exception)
                {
                    Debugger.Break();
                }
                finally
                {
                    if (_serviceDeferral != null)
                    {
                        //Complete the service deferral
                        _serviceDeferral.Complete();
                        _serviceDeferral = null;
                    }
                }
            }
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral        = taskInstance.GetDeferral();
            taskInstance.Canceled += OnTaskCancelled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            cortanaResourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("Resources");
            cortanaContext     = ResourceContext.GetForViewIndependentUse();

            if (triggerDetails != null && triggerDetails.Name == "VoiceCommandService")
            {
                try
                {
                    voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    var client = await this.GetClient();

                    // Depending on the operation (defined in the VoiceCommands.xml file)
                    // perform the appropriate command.
                    switch (voiceCommand.CommandName)
                    {
                    case "turnOnItem":
                        var onTarget = voiceCommand.Properties["target"][0];
                        await SendCompletionMessageForOnOff(client, onTarget, true);

                        break;

                    case "turnOffItem":
                        var offTarget = voiceCommand.Properties["target"][0];
                        await SendCompletionMessageForOnOff(client, offTarget, false);

                        break;

                    default:
                        // As with app activation VCDs, we need to handle the possibility that
                        // an app update may remove a voice command that is still registered.
                        // This can happen if the user hasn't run an app since an update.
                        //LaunchAppInForeground();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
            }
        }
        private void RedirectVoiceCommand(VoiceCommand command)
        {
            switch (focusedPanel)
            {
            case FocusedPanel.Train:
                trainPanel.ExecuteVoiceCommand(command);
                break;

            case FocusedPanel.Exercise:
                exercisePanel.ExecuteVoiceCommand(command);
                break;
            }
        }
Exemplo n.º 25
0
 public bool CommandsContain(string s, out VoiceCommand command)
 {
     foreach (VoiceCommand v in commands)
     {
         if (v.commands.Contains(s))
         {
             command = v;
             return(true);
         }
     }
     command = null;
     return(false);
 }
Exemplo n.º 26
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            //Take a service deferral so the service isn&#39;t terminated.
            this.serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += VoiceCommandCanceled;

            var triggerDetails =
                taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null &&
                triggerDetails.Name == "ContactsVoiceCommandService")
            {
                try
                {
                    voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted +=
                        VoiceCommandCompleted;

                    VoiceCommand voiceCommand = await
                                                voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "zeige":
                    {
                        var contactName =
                            voiceCommand.Properties["nutzer"][0];
                        SendCompletionMessageForContact(contactName);
                        break;
                    }

                    // As a last resort, launch the app in the foreground.
                    default:
                        LaunchAppInForeground();
                        break;
                    }
                }
                finally
                {
                    if (this.serviceDeferral != null)
                    {
                        // Complete the service deferral.
                        this.serviceDeferral.Complete();
                    }
                }
            }
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            taskDeferall = taskInstance.GetDeferral();

            //we add OnTaskCanceled event
            taskInstance.Canceled += OnTaskCanceled;

            //grab triggerDetails and cast on ApppService type 
            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;
            try
            {
                //here we creating connection which has all our information
                voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

                //Add CompletedEvent without it Cortand will hang up very often that's why Cortans won't know when task is completed
                //I divided  Completed into two ways  one: TaskCompleted and second VoiceCommand Completed to let Cortana know when task and command is completed 
                voiceServiceConnection.OnVoiceCommandCompleted += OnVoiceCommandCompleted;

                //voiceCommand is part of voiceSerivceConnection  I'm gonna to use it for....
                VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                //grab interpretation
                //Interpreatin is very important to inform Cortan what we want, it's all we care about 
                var interpretation = voiceCommand.SpeechRecognitionResult.SemanticInterpretation;
                VoiceCommandType commandType = (VoiceCommandType)Enum.Parse(typeof(VoiceCommandType), voiceCommand.CommandName, true);
                switch(commandType)
                {
                    case VoiceCommandType.InterestingFactQueryCommand:
                        await ProcessInterestingFactAsync(interpretation);
                        break;
                    case VoiceCommandType.WeekOfYearQueryCommand:
                        await ProcessWeekOfYearAsync(interpretation);
                        break;

                    case VoiceCommandType.FindBusinessQueryCommand:
                        ProcessFindBusinessAsync(interpretation);
                        break;

                    default:
                        break;
                }

            }
            catch(Exception ex)
            {

            }



        }
Exemplo n.º 28
0
        private async Task DetermineAction(VoiceCommand voiceCommand)
        {
            switch (voiceCommand.CommandName)
            {
            case "showNotesForPerson":
                var person = voiceCommand.Properties["person"][0];
                await GetNotesForPerson(person);

                break;

            default:
                break;
            }
        }
Exemplo n.º 29
0
        /* Unused, because this project does not yet need localised resources
         * /// <summary>
         * /// ResourceMap containing localized strings for display in Cortana.
         * /// </summary>
         * ResourceMap cortanaResourceMap;
         *
         * /// <summary>
         * /// The context for localized strings.
         * /// </summary>
         * ResourceContext cortanaContext;
         */

        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            //Use to let Cortana know what's up
            serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            AppServiceTriggerDetails triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null && triggerDetails.Name == "AdventureWorksVoiceCommandService")
            {
                try
                {
                    voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    // Perform the appropriate command (defined in Manto:MantoCortanaCommands.xml)
                    switch (voiceCommand.CommandName)
                    {
                    case "whenIsTripToDestination":
                        var destination = voiceCommand.Properties["destination"][0];
                        await SendCompletionMessageForDestination(destination);

                        break;

                    case "cancelTripToDestination":
                        var cancelDestination = voiceCommand.Properties["destination"][0];
                        await SendCompletionMessageForCancellation(cancelDestination);

                        break;

                    default:
                        // As with app activation VCDs, we need to handle the possibility that
                        // an app update may remove a voice command that is still registered.
                        // This can happen if the user hasn't run an app since an update.
                        LaunchAppInForeground();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
            }
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            //service deferral so that the  app service is not terminated while handling the voice command.
            this.serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails =
                taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null && triggerDetails.Name == "HelloCortanaVoiceCommandService")
            {
                try
                {
                    voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted +=
                        VoiceCommandCompleted;

                    VoiceCommand voiceCommand = await
                                                voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "showInCanvas":
                    {
                        var destination =
                            voiceCommand.Properties["destination"][0];
                        SendCompletionMessageForDestination(destination);
                        break;
                    }


                    default:
                        LaunchAppInForeground();
                        break;
                    }
                }
                finally
                {
                    if (this.serviceDeferral != null)
                    {
                        // Complete the service deferral.
                        this.serviceDeferral.Complete();
                    }
                }
            }
        }
Exemplo n.º 31
0
 public MessageViewModel(MessageView messageView)
 {
     MessageView  = messageView;
     MessageList  = new ObservableCollection <ClientEntity>();
     PaperclipCmd = new PaperclipCommand(messageView, this);
     SmileCmd     = new SmileCommand(this, messageView);
     VoiceCmd     = new VoiceCommand();
     Smile1Cmd    = new Smile1Command(this);
     Smile2Cmd    = new Smile2Command();
     Smile3Cmd    = new Smile3Command();
     Smile4Cmd    = new Smile4Command();
     Smile5Cmd    = new Smile5Command();
     SentCmd      = new SentCommand(this, messageView);
 }
 public void SetArgs(WheelmapVoiceCommandService service, VoiceCommand command) {
     this.service = service;
     this.voiceCommand = command;
     context = ResourceContext.GetForViewIndependentUse();
 }
Exemplo n.º 33
0
 void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
 {
     if (e.Result.Confidence > 0.75f)
     {
         switch (e.Result.Text)
         {
             case "Новая игра":
             //case "New Game" :
                 lastRecognizedVoiceCommand = VoiceCommand.NewGame;
                 break;
             case "Выход":
             //case "Exit" :
                 lastRecognizedVoiceCommand = VoiceCommand.Exit;
                 break;
             case "Пауза":
             //case "Pause" :
                 lastRecognizedVoiceCommand = VoiceCommand.Pause;
                 break;
             case "Продолжить":
             //case "Continue" :
                 lastRecognizedVoiceCommand = VoiceCommand.Continue;
                 break;
             default:
                 lastRecognizedVoiceCommand = VoiceCommand.None;
                 break;
         }
     }
 }
Exemplo n.º 34
0
 private bool GetAllParameters(int model, VoiceCommand voiceCommand, ref double Lambda, ref double Mu)
 {
     bool valid = true;
     switch (model)
     {
         case 1:
             if (!double.TryParse(voiceCommand.Properties["vLambda"][0], out Lambda)
                 || !double.TryParse(voiceCommand.Properties["vMu"][0], out Mu))
             { 
                 valid = false;
                 break;
             }
             if (double.Parse(voiceCommand.Properties["vLambda"][0]) / double.Parse(voiceCommand.Properties["vMu"][0]) >= 1
             || double.Parse(voiceCommand.Properties["vLambda"][0]) / double.Parse(voiceCommand.Properties["vMu"][0]) <= 0)
                 valid = false;
             break;
         case 2:
             if (!double.TryParse(voiceCommand.Properties["vLambda"][0], out Lambda)
                 || !double.TryParse(voiceCommand.Properties["vMu"][0], out Mu))
             { 
                 valid = false;
                 break;
             }
             if (double.Parse(voiceCommand.Properties["vLambda"][0]) / double.Parse(voiceCommand.Properties["vMu"][0]) <= 0)
                 valid = false;
             break;
         case 3:
         case 4:
         case 5:
             break;
         default:
             valid = false;
             break;
     }
     return valid;
 }
    static string ExtractPropertyFromVoiceCommand(VoiceCommand voiceCommand, string propertyKey)
    {
      string result = string.Empty;

      if (voiceCommand.Properties.ContainsKey(propertyKey))
      {
        var entries = voiceCommand.Properties[propertyKey];

        if ((entries != null) && (entries.Count > 0))
        {
          result = entries[0];
        }
      }
      return(result);
    }
        /// <summary>
        /// Helper method for initalizing the voice service, bridge, and lights. Returns if successful. 
        /// </summary>
        private async Task<bool> InitializeAsync(AppServiceTriggerDetails triggerDetails)
        {
            _voiceServiceConnection = 
                VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
            _voiceServiceConnection.VoiceCommandCompleted += (s, e) => _deferral.Complete();

            _voiceCommand = await _voiceServiceConnection.GetVoiceCommandAsync();
            _colors = HsbColor.CreateAll().ToDictionary(x => x.Name);

            var localStorage = ApplicationData.Current.LocalSettings.Values;
            _bridge = new Bridge(
                localStorage["bridgeIp"].ToString(), localStorage["userId"].ToString());
            try
            {
                _lights = await _bridge.GetLightsAsync();
            }
            catch (Exception)
            {
                var response = CreateCortanaResponse("Sorry, I couldn't connect to your bridge.");
                await _voiceServiceConnection.ReportFailureAsync(response);
                return false;
            }
            if (!_lights.Any())
            {
                var response = CreateCortanaResponse("Sorry, I couldn't find any lights.");
                await _voiceServiceConnection.ReportFailureAsync(response);
                return false;
            }
            return true;
        }