//set face data
    public void setFaceData(string json)
    {
        if (json == null)
        {
            return;
        }

        //Quick Blink message
        if (json.Equals("blink"))
        {
            blinkTimer = 0; return;
        }

        //Tank control message (Prefaced with a "t")
        if (json.Substring(0, 1).Equals("t"))
        {
            TankSpeed tankSpeed = JsonUtility.FromJson <TankSpeed>(json.Substring(1));
            tankController.remoteControlTank(tankSpeed.x * 0.01f, tankSpeed.y * 0.01f);
            return;
        }

        //Full face message
        previousExpression = expression;
        FaceData faceData = JsonUtility.FromJson <FaceData>(json);

        if (faceData != null)
        {
            try {
                rate       = faceData.ra * 0.01f;
                pitch      = faceData.p * 0.01f;
                expression = faceData.e;
                speech     = faceData.s;
                faceColor  = new Color(faceData.r / 255f,
                                       faceData.g / 255f,
                                       faceData.b / 255f);
                Speaker.Silence();
                Speaker.Speak(speech, null, null, true, rate, pitch, 1); //rate = 0-3, pitch = 0-2, volume = 0-1
                if (chatlog)
                {
                    chatlog.userSpoke(speech);
                }
                //Blink
                eyeBlend = 0f;
            } catch (Exception e) { Debug.LogException(e, this); }
        }
    }
Example #2
0
    //set face data
    public void setFaceData(string json)
    {
        if (json == null)
        {
            return;
        }

        //Quick Blink message
        if (json.Equals("blink"))
        {
            blinkTimer = 0; return;
        }

        //Tank control message (Prefaced with a "t")
        if (json.Substring(0, 1).Equals("t"))
        {
            TankSpeed tankSpeed = JsonUtility.FromJson <TankSpeed>(json.Substring(1));
            tankController.remoteControlTank(tankSpeed.x * 0.01f, tankSpeed.y * 0.01f);
            return;
        }

        //Full face message
        previousExpression = expression;
        FaceData faceData = JsonUtility.FromJson <FaceData>(json);

        if (faceData != null)
        {
            try {
                rate       = faceData.ra * 0.01f;
                pitch      = faceData.p * 0.01f;
                expression = faceData.e;
                speech     = faceData.s;
                faceColor  = new Color(faceData.r / 255f,
                                       faceData.g / 255f,
                                       faceData.b / 255f);

                Speaker.Silence();
                mp3MusicPlayer.StopMP3();

                youtubePlayer.Stop();
                youtubePlayer.HideLoading();
                youtubePlayer.OnVideoPlayerFinished();

                //If detect Youtube video, play Youtube video!
                string checkYoutubeUrl = speech;
                if (youtubePlayer.TryNormalizeYoutubeUrlLocal(checkYoutubeUrl, out checkYoutubeUrl))
                {
                    Debug.Log(checkYoutubeUrl);
                    youtubePlayer.ShowLoading();
                    youtubePlayer.Play(checkYoutubeUrl);
                    //    youtubePlayer.PlayYoutubeVideo(checkYoutubeUrl);
                }
                //If detect MP3 music file, play MP3 from local file.
                else if (speech.Length > 4 && speech.Substring(speech.Length - 4).ToLower() == ".mp3")
                {
                    mp3MusicPlayer.PlayMP3FromFile(speech);
                }
                //Otherwise play Speech-to-Text;
                else
                {
                    Speaker.Speak(speech, null, null, true, rate, pitch, 1); //rate = 0-3, pitch = 0-2, volume = 0-1
                }
                if (chatlog)
                {
                    chatlog.userSpoke(speech);
                }

                //Blink
                eyeBlend = 0f;
            } catch (Exception e) { Debug.LogException(e, this); }
        }
    }