Exemple #1
0
    private void Recognizer_Recognized(object sender, IntentRecognitionEventArgs e)
    {
        if (e.Result.Reason == ResultReason.RecognizedIntent)
        {
            Debug.Log($"RECOGNIZED: Text={e.Result.Text}");
            Debug.Log($"    Intent Id: {e.Result.IntentId}.");

            string json = e.Result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult);

            Debug.Log($"    Language Understanding JSON: {json}.");

            result = json.FromJson <IntentResult>();
            if (result != null)
            {
                readyToProcess = true;
            }
        }
        else if (e.Result.Reason == ResultReason.RecognizedSpeech)
        {
            readyToProcess = false;
            Debug.Log($"RECOGNIZED: Text={e.Result.Text}");
            Debug.Log($"    Intent not recognized.");
        }
        else if (e.Result.Reason == ResultReason.NoMatch)
        {
            readyToProcess = false;
            Debug.Log($"NOMATCH: Speech could not be recognized.");
        }
    }
Exemple #2
0
    private void ProcessIntent()
    {
        Entity target = null;

        switch (result.topScoringIntent.intent)
        {
        case "changeColor":
            target = result.entities.FirstOrDefault(e => e.type == "object");
            var color = result.entities.FirstOrDefault(e => e.type == "color");
            if (target != null && color != null)
            {
                SpeechManager.Instance.ChangeColor(target.entity, color.entity);
            }
            break;

        case "moveObject":
            target = result.entities.FirstOrDefault(e => e.type == "object");
            var direction = result.entities.FirstOrDefault(e => e.type == "direction");
            if (target != null && direction != null)
            {
                SpeechManager.Instance.Move(target.entity, direction.entity);
            }
            break;

        default:
            break;
        }

        readyToProcess = false;
        result         = null;
    }
        public void GIVENEmptyActivity_WHENTrackIntentIsInvoked_THENExceptionIsBeingThrown(
            IntentResult luisResult,
            InstrumentationSettings settings)
        {
            // Arrange
            const IActivityAdapter emptyActivity = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => emptyActivity.TrackIntent(luisResult, this.telemetryClient, settings));
        }
        GIVENAnyActivityAnyResultAnAnyProperty_WHENTrackIntentIsInvoked_THENEventTelemetryIsBeingSent(
            IActivityAdapter activity,
            IntentResult result,
            InstrumentationSettings settings)
        {
            // Arrange
            // Act
            activity.TrackIntent(result, this.telemetryClient, settings);

            // Assert
            this.mockTelemetryChannel.Verify(
                tc => tc.Send(It.Is <EventTelemetry>(t =>
                                                     t.Name == EventTypes.Intent &&
                                                     t.Properties[IntentConstants.Intent] == result.Intent &&
                                                     t.Properties[IntentConstants.Score] == result.Score &&
                                                     t.Properties[IntentConstants.Entities] == result.Entities)),
                Times.Once);
        }
 private void RecognizedHandler(object sender, IntentRecognitionEventArgs e)
 {
     if (e.Result.Reason == ResultReason.RecognizedIntent)
     {
         //Console.WriteLine($"    Language Understanding JSON: {e.Result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult)}.");
         UnityEngine.Debug.LogFormat($"RECOGNIZED: Intent={e.Result.IntentId} Text={e.Result.Text}");
         lock (threadLocker)
         {
             recognizedString = $"RESULT: Intent={e.Result.IntentId}";
             string json   = e.Result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult);
             var    result = json.FromJson <IntentResult>();
             if (result != null)
             {
                 recognizedString += $" [Confidence={result.topScoringIntent.score.ToString("0.000")}]";
                 if (result.entities.Count > 0)
                 {
                     recognizedString += $"{Environment.NewLine}Entities=";
                     for (int i = 0; i < result.entities.Count; i++)
                     {
                         recognizedString += $"[{result.entities[i].type}: {result.entities[i].entity}] ";
                     }
                 }
                 lock (threadLocker)
                 {
                     intent        = result;
                     isIntentReady = true;
                 }
             }
             recognizedString += $"{Environment.NewLine}{e.Result.Text}";
         }
     }
     if (e.Result.Reason == ResultReason.RecognizedSpeech)
     {
         UnityEngine.Debug.LogFormat($"RECOGNIZED: Text={e.Result.Text}");
         lock (threadLocker)
         {
             recognizedString = $"RESULT: {Environment.NewLine}{e.Result.Text}";
         }
     }
     else if (e.Result.Reason == ResultReason.NoMatch)
     {
         UnityEngine.Debug.LogFormat($"NOMATCH: Speech could not be recognized.");
     }
 }
        protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            IntentResult result = IntentIntegrator.ParseActivityResult(requestCode, (int)resultCode, data);

            if (result != null)
            {
                if (result.Contents == null)
                {
                    textView1.Text = "No Result.";
                    Toast.MakeText(this, "Cancelled", ToastLength.Long).Show();
                }
                else
                {
                    textView1.Text = result.Contents;
                    Toast.MakeText(this, "Scanned: " + result.Contents, ToastLength.Long).Show();
                }
            }
        }
Exemple #7
0
        public static void TrackIntent(this IActivityAdapter activity, IntentResult result, TelemetryClient telemetryClient, InstrumentationSettings settings)
        {
            if (result is null)
            {
                throw new ArgumentNullException(nameof(result));
            }

            if (telemetryClient is null)
            {
                throw new ArgumentNullException(nameof(telemetryClient));
            }

            var properties = new Dictionary <string, string>
            {
                { IntentConstants.Intent, result.Intent },
                { IntentConstants.Score, result.Score },
                { IntentConstants.Entities, result.Entities },
            };

            activity.TrackCustomEvent(telemetryClient, settings, EventTypes.Intent, properties);
        }
    // Update is called once per frame
    void Update()
    {
#if PLATFORM_ANDROID
        if (!micPermissionGranted && Permission.HasUserAuthorizedPermission(Permission.Microphone))
        {
            micPermissionGranted = true;
        }
#endif
        // Used to update results on screen during updates
        lock (threadLocker)
        {
            RecognizedText.text = recognizedString;
            ErrorText.text      = errorString;
            if (isIntentReady && intent != null)
            {
                ProcessIntent(intent);
                isIntentReady = false;
                intent        = null;
            }
        }
    }
Exemple #9
0
        protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
        {
            IntentResult result = IntentIntegrator.ParseActivityResult(requestCode, (int)resultCode, data);

            if (result != null)
            {
                if (result.Contents == null)
                {
                    Log.Debug("MainActivity", "Cancelled scan");
                    Toast.MakeText(this, "Cancelled", ToastLength.Long).Show();
                }
                else
                {
                    Log.Debug("MainActivity", "Scanned");
                    Toast.MakeText(this, "Scanned: " + result.Contents, ToastLength.Long).Show();
                }
            }
            else
            {
                base.OnActivityResult(requestCode, resultCode, data);
            }
        }
Exemple #10
0
        public static IntentResult Handle(string intentName)
        {
            var result = new IntentResult();

            switch (intentName)
            {
            case "ZodiacIntent":
                // 占い結果を返す。今回は適当占いなのでランダムにどちらか
                // (本来はここでスロットの星座を受け取ってそれに基づいた処理を行う)
                if (new System.Random().Next() % 2 == 0)
                {
                    result.AddMessage("今日は絶好調!とてもよい1日になりますよ!");
                }
                else
                {
                    result.AddMessage("今日はあまりついてないかも。転ばないように気を付けてくださいね。");
                }
                result.ShouldEndSession = true;
                break;

            case "AMAZON.HelpIntent":
            case "Clova.GuideIntent":
                // 使い方
                result.AddMessage("あなたの星座を教えてください。占ってあげます。");
                result.ShouldEndSession = false;
                break;

            default:
                // その他のインテントの場合
                result.AddMessage("よくわかりませんでしたが、まあまあだと思います。");
                result.ShouldEndSession = false;
                break;
            }

            return(result);
        }
Exemple #11
0
        private void StartInternal(CancellationToken cancellationToken)
        {
            Field.GetCell(Team1.Agent1.Position).SetState(Teams.Team1, CellState.Occupied);
            Field.GetCell(Team1.Agent2.Position).SetState(Teams.Team1, CellState.Occupied);
            Field.GetCell(Team2.Agent1.Position).SetState(Teams.Team2, CellState.Occupied);
            Field.GetCell(Team2.Agent2.Position).SetState(Teams.Team2, CellState.Occupied);

            IsGaming = true;
            RaiseStarted(TeamHandler1, TeamHandler2);
            Started?.Invoke(this, new EventArgs());

            int  length   = Length;
            bool infinite = length <= 0;

            if (infinite)
            {
                length = 1;
                if (WriteConsole)
                {
                    Console.WriteLine("Game Started : Infinity Turns");
                }
            }
            else
            if (WriteConsole)
            {
                Console.WriteLine("Game Started : " + length + " Turns");
            }

            if (Abort(cancellationToken, TeamHandler1, TeamHandler2))
            {
                return;
            }

            for (Turn = 1; length >= Turn; Turn++)
            {
                //TeamHandler1, 2を排他ロックします
                HandlerSemaphore.Wait();

                if (Abort(cancellationToken, TeamHandler1, TeamHandler2))
                {
                    return;
                }

                if (WriteConsole)
                {
                    Console.WriteLine("Turn " + Turn);
                }

                TurnChanged?.Invoke(this, new EventArgs());
                var intents = MakeIntents(Turn, TeamHandler1, TeamHandler2);

                if (Abort(cancellationToken, TeamHandler1, TeamHandler2))
                {
                    return;
                }

                IntentResult[] results = new IntentResult[4];

                //インテントを受け取って判断(マップの状態が正しいと仮定しています)
                for (int i = 0; intents.Length > i; i++)
                {
                    var  intent = intents[i];
                    bool res    = intent.Intention == Intentions.Stay;
                    GetParamsForResult(i, out var team, out var current, out var agent);
                    var teamEnum    = team == Team1 ? Teams.Team1 : Teams.Team2;
                    var anotherEnum = (Teams.Team1 | Teams.Team2) & ~teamEnum;

                    if (Abort(cancellationToken, TeamHandler1, TeamHandler2))
                    {
                        return;
                    }

                    if (!res)
                    {
                        Point next = intent.GetNextPoint(current);

                        if (next.X < 0 || next.Y < 0 || next.X >= Field.Width || next.Y >= Field.Height)
                        {
                            throw new Exception($"Invalid intent requested : {next}({intent.Intention}, {intent.Direction})");
                        }

                        switch (intent.Intention)
                        {
                        case Intentions.Move:
                            current = next;
                            res     = true;
                            break;

                        //http://www.procon.gr.jp/wp-content/uploads//2016/12/e017e38ca89f7a0d04d6ad74319ffde0-1.pdf 10ページ目の試合の進行(3).ii.③を参照
                        case Intentions.Remove:
                            var cell  = Field.GetCell(next);
                            var state = cell.GetState(anotherEnum);

                            //敵チームのセル状態が占有かどうかを判定
                            if (state == CellState.Occupied)
                            {
                                current = next;
                                res     = true;
                            }
                            break;
                        }
                    }

                    IntentResult ir = new IntentResult()
                    {
                        Team         = team,
                        Agent        = agent,
                        Intent       = intent,
                        NextPosition = current,
                        Result       = res
                    };

                    results[i] = ir;
                }

                if (Abort(cancellationToken, TeamHandler1, TeamHandler2))
                {
                    return;
                }

                //自分が動けるかをまず確認
                foreach (var res in results)
                {
                    if (res.Intent.Intention == Intentions.Move)
                    {
                        res.Result = this.CanMove(res.Agent, res.Intent.Direction);
                    }
                    else if (res.Intent.Intention == Intentions.Remove)
                    {
                        res.Result = Field.IsInField(res.Agent, res.Intent.Direction);
                    }

                    if (!res.Result)
                    {
                        res.NextPosition = res.Agent.Position;
                    }
                }

                var list = results.Where(r => r.Result).ToList();
                foreach (var res1 in list)
                {
                    foreach (var res2 in list)
                    {
                        if (res1 != res2)
                        {
                            bool r1 = false, r2 = false;

                            if (res1.NextPosition == res2.NextPosition)
                            {
                                r1 = true;
                                r2 = true;
                            }

                            if (res2.NextPosition == res1.Agent.Position)
                            {
                                r2 = true;
                            }

                            if (r1)
                            {
                                res1.NextPosition = res1.Agent.Position;
                                res1.Result       = false;
                            }

                            if (r2)
                            {
                                res2.NextPosition = res2.Agent.Position;
                                res2.Result       = false;
                            }
                        }
                    }
                }

                //実際に移動
                foreach (var res in results)
                {
                    if (res.Intent.Intention == Intentions.Move)
                    {
                        res.Agent.Position = res.NextPosition;

                        var team  = res.Team == Team1 ? Teams.Team1 : Teams.Team2;
                        var cell  = Field.GetCell(res.NextPosition);
                        var state = cell.GetState(team);
                        cell.SetState(team, CellState.Occupied);
                    }
                }

                var remList  = results.Where(r => r.Intent.Intention == Intentions.Remove).ToList();
                var agentPos = GetAgentPositions(Team1.Agent1, Team1.Agent2, Team2.Agent1, Team2.Agent2);

                //削除ができるものを実際に削除
                foreach (var rem in remList.Where(r => r.Result))
                {
                    //除去動作は自チームも許可されるため修正
                    var cell = Field.GetCell(rem.NextPosition);
                    cell.State1 = CellState.None;
                    cell.State2 = CellState.None;
                }

                if (Abort(cancellationToken, TeamHandler1, TeamHandler2))
                {
                    return;
                }

                int intentIndex = 0;
                InvokeTeams(t => t.TeamHandler.IntentResult(results[intentIndex++].Result, results[intentIndex++].Result));
                Result?.Invoke(this, new IntentResultEventArgs(intents, results.Select(r => r.Result).ToArray()));

                if (infinite)
                {
                    length++;
                }

                HandlerSemaphore.Release();
            }

            IsGaming = false;
            RaiseFinished(TeamHandler1, TeamHandler2);
            if (WriteConsole)
            {
                Console.WriteLine("Game Finished");
            }

            Finished?.Invoke(this, new EventArgs());

            Length = 0;
            Turn   = 0;
        }
    /// <summary>
    /// Processes the user's voice command captured via speech recognition based on the
    /// intent & entities returned by the LUIS service.
    /// To learn more about a more advanced approach for processing LUIS results from
    /// within Unity projects, check out http://aka.ms/MrLuis (external blog link)
    /// </summary>
    /// <param name="intent"></param>
    void ProcessIntent(IntentResult intent)
    {
        string target    = "";
        string attribute = "";

        // Extract the entities if any, this can be the target shape or the
        // transformation such as colors or scaling.
        if (intent.entities.Count > 0)
        {
            recognizedString += $"{Environment.NewLine}Entities=";
            for (int i = 0; i < intent.entities.Count; i++)
            {
                if (intent.entities[i].type.ToLower() == "target")
                {
                    target = intent.entities[i].entity;
                }
                if (intent.entities[i].type.ToLower() == "color")
                {
                    attribute = intent.entities[i].entity;
                }
                if (intent.entities[i].type.ToLower() == "scaling")
                {
                    attribute = intent.entities[i].entity;
                }
            }
        }

        // We support many names to refer to the various shapes in the scene.
        GameObject targetObject;

        switch (target)
        {
        case "cube":
        case "box":
        case "square":
            targetObject = Cube;
            break;

        case "ball":
        case "sphere":
        case "circle":
            targetObject = Sphere;
            break;

        case "cylinder":
        case "tube":
        case "pipe":
            targetObject = Cylinder;
            break;

        default:
            targetObject = null;
            break;
        }

        // Identify the target color change if applicable
        Color color        = Color.clear;
        float scalingratio = 0.0f;

        switch (attribute)
        {
        case "increase":
        case "large":
        case "big":
        case "bigger":
        case "larger":
        case "bigly":
        case "huge":
        case "enlarge":
            scalingratio = 0.1f;
            break;

        case "reduce":
        case "small":
        case "smaller":
        case "minimize":
        case "reduction":
        case "tiny":
        case "decrease":
            scalingratio = -0.1f;
            break;

        case "yellow":
            color = Color.yellow;
            break;

        case "black":
            color = Color.black;
            break;

        case "blue":
            color = Color.blue;
            break;

        case "cyan":
        case "turquoise":
        case "scion":       // common confusion in the recognizer
            color = Color.cyan;
            break;

        case "gray":
            color = Color.gray;
            break;

        case "green":
            color = Color.green;
            break;

        case "magenta":
        case "purple":
            color = Color.magenta;
            break;

        case "red":
        case "read":      // common confusion in the recognizer
            color = Color.red;
            break;

        case "orange":
            color = new Color(255, 112, 0);
            break;

        case "white":
            color = Color.white;
            break;

        default:
            color = Color.white;
            break;
        }

        // Process the intent: ChangeColor or Transform (scaling)
        switch (intent.topScoringIntent.intent)
        {
        case "color":
        case "ChangeColor":
            if (targetObject != null)
            {
                targetObject.GetComponent <Renderer>().material.color = color;
            }
            break;

        case "transform":
        case "Transform":
            if (targetObject != null)
            {
                targetObject.transform.localScale += new Vector3(scalingratio, scalingratio, scalingratio);
            }
            break;

        case "help":
            // For future use
            break;

        case "none":
        default:
            break;
        }
    }
Exemple #13
0
    //Function to send the message to the OSCOVA bot
    //It will then review all the intents in the loaded .west/.json workspace
    //Once it found the nearest match, it will send the response
    public void SendMessageToBot(string inputField)
    {
        var userMessage = inputField;

        if (!string.IsNullOrEmpty(userMessage))
        {
            Debug.Log($"OscovaBot:[USER] {userMessage}");
            AddMessage($"User: {userMessage}", MessageType.User);

            //Create a request for bot to process.
            var request = MainBot.MainUser.CreateRequest(userMessage);

            //Evaluate the request (Compute NLU - Natural Language Understanding)
            var evaluationResult = MainBot.Evaluate(request);

            //Invoke the best suggested intent found. This is compel a response generation.
            evaluationResult.Invoke();

            //Get the intent name to change the Tobor expression
            IntentResult intentResult = evaluationResult.SuggestedIntent;
            string       intentName   = intentResult.Name.ToString();
            Debug.Log("Intent Name: " + intentName);


            //Phrase will be loading according to the current date
            //Different phrases loads different JSON

            // if intentname contain "sad", show sad, contain "happy" show happy(check dialogs name) eg: happy_dialog_ep1.happy
            //Currently Tobor only have "Greeting" and "Feeling" dialogs -> loads "Happy" expression and "Happy" body movement
            ExpressionAnim    = FindObjectOfType <ExpressionControl>();
            toborBodyAnimator = GameObject.FindGameObjectWithTag("BodyAnimator").GetComponent <Animator>();

            if (phaseInitiated < 3)
            {
                if (intentName == "BotDialog.DefaultFallback")
                {
                    ExpressionAnim.SetExpression(SAD_STATE_INDEX);
                    StartCoroutine(BackToBodyNormal(3, NORMAL_STATE_INDEX, NORMAL_STATE_INDEX));
                }
                else
                {
                    ExpressionAnim.SetExpression(NORMAL_STATE_INDEX);
                }
            }
            else
            {
                if (intentName == "BotDialog.DefaultFallback")
                {
                    ExpressionAnim.SetExpression(SAD_STATE_INDEX);
                    toborBodyAnimator.SetInteger(BODY_ANIM_STATE, SAD_STATE_INDEX);

                    StartCoroutine(BackToBodyNormal(3, SAD_BACKNORMAL_STATE_INDEX, NORMAL_STATE_INDEX));
                }
                else if (intentName.Contains("feeling"))
                {
                    ExpressionAnim.SetExpression(HAPPY_STATE_INDEX);
                    toborBodyAnimator.SetInteger(BODY_ANIM_STATE, HAPPY_STATE_INDEX);

                    StartCoroutine(BackToBodyNormal(3, HAPPY_BACKNORMAL_STATE_INDEX, NORMAL_STATE_INDEX));
                }
                else
                {
                    ExpressionAnim.SetExpression(NORMAL_STATE_INDEX);
                    toborBodyAnimator.SetInteger(BODY_ANIM_STATE, NORMAL_STATE_INDEX);
                }
            }

            chatBox.text = "";
            //  }
        }
    }