private void SaveJsonToModel(JSONObject j)
    {
        MCSFaceDto  faceDto = new MCSFaceDto();
        List <Face> faces   = new List <Face>();

        foreach (var faceItem in j.list)
        {
            Face face = new Face();

            face = new Face()
            {
                faceId = faceItem.GetField("faceId").ToString()
            };

            var faceRectangle = faceItem.GetField("faceRectangle");
            face.faceRectangle = new FaceRectangle()
            {
                left   = int.Parse(faceRectangle.GetField("left").ToString()),
                top    = int.Parse(faceRectangle.GetField("top").ToString()),
                width  = int.Parse(faceRectangle.GetField("width").ToString()),
                height = int.Parse(faceRectangle.GetField("height").ToString())
            };

            var faceAttributes = faceItem.GetField("faceAttributes");
            face.faceAttributes = new FaceAttributes()
            {
                age    = int.Parse(faceAttributes.GetField("age").ToString().Split('.')[0]),
                gender = faceAttributes.GetField("gender").ToString().Replace("\"", "") == "male" ? 0 : 1
            };

            var emotion = faceAttributes.GetField("emotion");
            face.emotionAttributes = new EmotionAttributes()
            {
                anger     = float.Parse(emotion.GetField("anger").ToString()),
                contempt  = float.Parse(emotion.GetField("contempt").ToString()),
                disgust   = float.Parse(emotion.GetField("disgust").ToString()),
                fear      = float.Parse(emotion.GetField("fear").ToString()),
                happiness = float.Parse(emotion.GetField("happiness").ToString()),
                neutral   = float.Parse(emotion.GetField("neutral").ToString()),
                sadness   = float.Parse(emotion.GetField("sadness").ToString()),
                surprise  = float.Parse(emotion.GetField("surprise").ToString()),
            };
            faces.Add(face);
        }

        faceDto.faces = faces;

        PlayVoiceMessage.Instance.PlayTextToSpeechMessage(faceDto);
    }
Пример #2
0
    public void PlayTextToSpeechMessage(MCSFaceDto face)
    {
        string message     = string.Empty;
        string emotionName = string.Empty;

        if (face.faces.Count > 0)
        {
            EmotionAttributes emotionAttributes = face.faces[0].emotionAttributes;

            Dictionary <string, float> emotions = new Dictionary <string, float>
            {
                { "anger", emotionAttributes.anger },
                { "contempt", emotionAttributes.contempt },
                { "disgust", emotionAttributes.disgust },
                { "fear", emotionAttributes.fear },
                { "happiness", emotionAttributes.happiness },
                { "sadness", emotionAttributes.sadness },
                { "suprise", emotionAttributes.surprise }
            };

            emotionName = emotions.Keys.Max();

            //Message
            message = string.Format("{0} is pretty much {1} years old and looks {2}", face.faces[0].faceAttributes.gender == 0 ? "He" : "She", face.faces[0].faceAttributes.age, emotionName);
        }
        else
        {
            message = "I could't detect anyone.";
        }

        // Try and get a TTS Manager
        TextToSpeechManager tts = null;

        if (photoCaptureManagerGmObj != null)
        {
            tts = photoCaptureManagerGmObj.GetComponent <TextToSpeechManager>();
        }

        if (tts != null)
        {
            //Play voice message
            tts.SpeakText(message);
        }
    }