예제 #1
0
    private static void ExecuteRequest(double time, AsyncRequest request)
    {
        //Do nothing if request is waiting for API response
        if (request.status == Status.WaitClipStatusRequest)
        {
            return;
        }

        //The next steps are only used to send status request
        if (request.status != Status.NeedNewClipStatusRequest)
        {
            return;
        }

        //Force a delay in requests to avoid flooding the api
        double delta = time - request.lastCheckTime;

        if (delta < 0.0f || delta > checkCooldown)
        {
            request.lastCheckTime = time;
        }
        else
        {
            return;
        }

        //Send GetClip request
        request.currentTask = APIBridge.GetClip(request.clipUUID, (ResembleClip clip, Error error) =>
        {
            //Error
            if (error)
            {
                request.SetError(error);
            }

            //Receive an response
            else
            {
                //Clip is ready - Start downloading
                if (clip.finished)
                {
                    DownloadClip(request, clip.link);

                    //Get phonemes
                    if (request.phonemeCallback != null)
                    {
                        request.phonemeCallback.Invoke(clip.phonemesRaw);
                    }
                }

                //Clip is not ready - Mark to create a request next time
                else
                {
                    request.status = Status.NeedNewClipStatusRequest;
                }
            }
        });
        request.status = Status.WaitClipStatusRequest;
    }
        public void UpdateFromAPI()
        {
            if (!EditorUtility.DisplayDialog("Update from API", "This operation will overwrite existing " +
                                             "information with information from the Resemble.ai website.", "Ok", "Cancel"))
            {
                return;
            }

            APIBridge.GetClip(clip.uuid, (ResembleClip clip, Error error) =>
            {
                if (error)
                {
                    error.Log();
                }
                else
                {
                    this.clip.text.ParseResembleString(clip.body);
                    this.clip.clipName = clip.title;
                    this.clip.name     = clip.uuid + "-" + clip.title;
                    drawer.Refresh();
                    Repaint();
                }
            });
        }
예제 #3
0
    /// <summary> Build a async request for a clip. This request handles patching, downloading and notifications. </summary>
    public static AsyncRequest Make(Clip clip)
    {
        //Build request
        AsyncRequest request = new AsyncRequest();

        request.status = Status.BuildRequest;
        string savePath = clip.GetSavePath();

        request.saveDirectory    = Path.GetDirectoryName(savePath);
        request.fileName         = Path.GetFileName(savePath);
        request.requestName      = clip.speech.name + " > " + clip.clipName;
        request.clipUUID         = clip.uuid;
        request.notificationLink = clip;


        //Generate place holder
        request.status = Status.GeneratePlaceHolder;
        clip.clip      = request.GeneratePlaceHolder();


        //Phonemes stuff
        bool   includePhonemes = clip.speech.includePhonemes;
        string voiceUUID       = clip.speech.voiceUUID;

        if (includePhonemes)
        {
            request.phonemeCallback = clip.SetPhonemesRaw;
        }

        //No UUID - Create new clip
        request.status = Status.SendDataToAPI;
        if (string.IsNullOrEmpty(request.clipUUID))
        {
            //Create new clip
            ClipPatch.Data data = new ClipPatch.Data(clip.clipName, clip.text.BuildResembleString(), voiceUUID);
            request.currentTask = APIBridge.CreateClip(data, includePhonemes, (ClipStatus status, Error error) =>
                                                       { request.clipUUID = clip.uuid = status.id;  RegisterRequestToPool(request); });
        }
        else
        {
            ClipPatch patch = new ClipPatch(clip.clipName, clip.text.BuildResembleString(), voiceUUID, clip.speech.includePhonemes);

            //Bypass the api check for similarities.
            if (Settings.forceGeneration)
            {
                //Patch clip
                request.currentTask = APIBridge.UpdateClip(request.clipUUID, patch, (string content, Error patchError) =>
                                                           { RegisterRequestToPool(request); });
            }

            //Check the api for similarities
            else
            {
                //Get existing clip
                APIBridge.GetClip(clip.uuid, (ResembleClip apiClip, Error error) =>
                {
                    //Handle error
                    if (error)
                    {
                        request.SetError(error);
                    }

                    else
                    {
                        //No changes - Download existing clip
                        if (apiClip.finished && patch.CompareContent(apiClip))
                        {
                            APIBridge.DownloadClip(apiClip.link, (byte[] data, Error downloadError) =>
                                                   { OnDownloaded(request, data, downloadError); RegisterRequestToPool(request); });
                        }

                        //Changes - Patch existing clip
                        else
                        {
                            request.currentTask = APIBridge.UpdateClip(request.clipUUID, patch, (string content, Error patchError) =>
                                                                       { RegisterRequestToPool(request); });
                        }
                    }
                });
            }
        }

        //Return the request
        return(request);
    }