/// <summary>
    /// Synchronizes the lip with the speech.
    /// </summary>
    /// <param name="text">The text to synchronize.</param>
    /// <param name="lang">The language to synchronize in.</param>
    /// <returns>An IEnumerator being the send action of the UnityWebRequest.</returns>
    public IEnumerator synchronize(string text, string lang)
    {
        Debug.Log("Trying to make request to phoneme server...");
        // Assumes ESpeak API is available on the same hostname
        using (var www = UnityWebRequest.Get(TextManager.tmInstance.getPhonemeServerHost() + "phoneme?text=" + text + "&lang=" + lang))
        {
            Debug.Log("request made to " + www.url);
            yield return(www.Send());

            Debug.Log("communication finished with " + www.url);

            if (www.isError)
            {
                Debug.Log(www.responseCode + ": " + www.error);
            }
            else
            {
                Debug.Log("response successfully received");
                var response    = JSON.Parse(www.downloadHandler.text);
                var phonemes    = response["phonemes"].AsArray;
                var phonemeList = JSONUtil.arrayToList(phonemes);
                //Debug.Log("Code to phonemes...");
                var actualPhonemeList = Phoneme.getPhonemeFromCode(phonemeList);
                //Debug.Log("Phonemes to visemes...");
                var actualVisemeList = Phoneme.toVisemes(actualPhonemeList);
                //Debug.Log("playing list...");
                SpeechAnimationManager.instance.playVisemeList(actualVisemeList);
                TextManager.tmInstance.startActualSpeech(text);
            }
        }
    }
示例#2
0
        public void arrayToListTest()
        {
            var jsonArray = new JSONArray();

            jsonArray.Add(0);
            jsonArray.Add(1);
            jsonArray.Add(2);

            var jsonList = JSONUtil.arrayToList(jsonArray);

            Assert.AreEqual(jsonArray[0].ToString(), jsonList[0]);
            Assert.AreEqual(jsonArray[1].ToString(), jsonList[1]);
            Assert.AreEqual(jsonArray[2].ToString(), jsonList[2]);
        }