コード例 #1
0
        public static string GenerateLipSync(string serverUrl, ParamsATL atl, byte[] wavFile, string serverToken = null)
        {
            var request = GenerateATLRequest(atl);
            var json    = JsonConvert.SerializeObject(request, new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            });

            Uri baseUri = new Uri(serverUrl);
            Uri reqUri  = new Uri(baseUri, "/dh/api/v1/atl");

            var form = new WWWForm();

            form.AddBinaryData("audio", wavFile);
            form.AddField("json", json);

            var webRequest = UnityWebRequest.Post(reqUri, form);

            if (!string.IsNullOrEmpty(serverToken))
            {
                webRequest.SetRequestHeader("Authorization", "Bearer " + serverToken);
            }
            var webRequestHandler = webRequest.SendWebRequest();

            while (!webRequestHandler.isDone)
            {
            }

            if (webRequest.isNetworkError)
            {
                Debug.LogError("ATL failed with network error: " + webRequest.error);
                return(null);
            }

            if (webRequest.isHttpError)
            {
                var text    = webRequest.downloadHandler.text;
                var errCode = webRequest.responseCode;

                Debug.LogError($"TTS failed with response code {errCode}. " +
                               $"Server returned message: {text}");
                return(null);
            }

            var data = webRequest.downloadHandler.text;

            return(data);
        }
コード例 #2
0
        public static object GenerateATLRequest(ParamsATL atl)
        {
            var request = new Request <AttributesATL>
            {
                data = new Data <AttributesATL>
                {
                    id         = Guid.NewGuid().ToString(),
                    type       = "audioToLipSync",
                    attributes = new AttributesATL()
                    {
                        atl = atl
                    }
                }
            };

            return(request);
        }