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)
            {

            }



        }
Example #2
0
        /// <summary>
        /// Unsets the command list.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <privilege>
        /// http://tizen.org/privilege/recorder
        /// </privilege>
        /// <privlevel>
        /// public
        /// </privlevel>
        /// <feature>
        /// http://tizen.org/feature/speech.control
        /// http://tizen.org/feature/microphone
        /// </feature>
        /// <param name="type">Command type</param>
        /// <exception cref="InvalidOperationException">This exception can be due to an invalid state.</exception>
        /// <exception cref="ArgumentException">This exception can be due to an invalid parameter.</exception>
        /// <exception cref="NotSupportedException">This exception can be due to not supported.</exception>
        /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
        /// <pre>
        /// The state should be ready.
        /// </pre>
        public static void UnsetCommandList(CommandType type)
        {
            if ((type == CommandType.Foreground) || (type == CommandType.Background))
            {
                VoiceCommandType commandType = VoiceCommandType.Foreground;
                if (type == CommandType.Background)
                {
                    commandType = VoiceCommandType.BackGround;
                }
                ErrorCode error = VcUnsetCommandList(commandType);
                if (error != ErrorCode.None)
                {
                    Log.Error(LogTag, "UnsetCommandList Failed with error " + error);
                    throw ExceptionFactory.CreateException(error);
                }
            }

            else
            {
                throw ExceptionFactory.CreateException(ErrorCode.InvalidParameter);
            }
        }
Example #3
0
        protected override void OnActivated(IActivatedEventArgs args)
        {
            InitializeRoot(args);
            //it will happen when cortan gets navigate
            if(args.Kind==ActivationKind.VoiceCommand)
            {

                Frame rootFrame = Window.Current.Content as Frame;

                //grab command argument and then cast on properly type 
                VoiceCommandActivatedEventArgs comandArgs = (VoiceCommandActivatedEventArgs)args;

                string VoiceCommandName = comandArgs.Result.RulePath.FirstOrDefault();
                VoiceCommandType commandType = (VoiceCommandType)Enum.Parse(typeof(VoiceCommandType), VoiceCommandName,true);

                switch(commandType)
                {

                    //performing logic based on command type 
                    //Cortana checks what type of voice command we have  and  take right action
                    //in dependence on what type commands we have cortan makes decision what should do 
                    case VoiceCommandType.NavigateToSupportCommand:
                        rootFrame.Navigate(typeof(Pages.SupportPage), comandArgs.Result.Text);
                        break;
                    default:
                        break;

                }

            }
            else if(args.Kind==ActivationKind.Protocol)
            {

            }
                    
                    }
Example #4
0
 internal static extern ErrorCode VcSetCommandList(SafeCommandListHandle cmdList, VoiceCommandType type);
Example #5
0
 internal static extern ErrorCode VcUnsetCommandList(VoiceCommandType type);
        public static async void LaunchAppInForeground(VoiceCommandServiceConnection voiceServiceConnection, VoiceCommandType commandType, string parameters)
        {
            var userMessage = new VoiceCommandUserMessage();

            userMessage.DisplayMessage = "Launching OfficePoint...";

            var response = VoiceCommandResponse.CreateResponse(userMessage);

            response.AppLaunchArgument = "type=" + commandType + "&" + parameters;

            await voiceServiceConnection.RequestAppLaunchAsync(response);
        }