Exemplo n.º 1
0
    /// <summary> Build a async request for a one-shot clip. This request handles creation, downloading, notifications and deletion. </summary>
    public static AsyncRequest Make(string body, string voice, string savePath)
    {
        //Build request
        AsyncRequest request = new AsyncRequest();

        request.status          = Status.BuildRequest;
        request.saveDirectory   = Path.GetDirectoryName(savePath);
        request.fileName        = Path.GetFileName(savePath);
        request.deleteClipAtEnd = true;
        request.requestName     = "OneShot > " + request.fileName.Remove(request.fileName.Length - 4);

        //Generate placeholder
        request.status = Status.GeneratePlaceHolder;
        request.GeneratePlaceHolder();

        //Send request
        request.status = Status.SendDataToAPI;
        ClipPatch.Data data = new ClipPatch.Data(GetTemporaryName(), body, voice);
        request.currentTask = APIBridge.CreateClip(data, false, (ClipStatus status, Error error) =>
                                                   { request.clipUUID = status.id; RegisterRequestToPool(request); });

        //Add request to the pending pool
        Resources.instance.requests.Add(request);
        EditorUtility.SetDirty(Resources.instance);
        Resemble_Window.RefreshPoolList();

        //Return the request
        return(request);
    }
 public void CreateClip(string name)
 {
     if (!string.IsNullOrEmpty(name))
     {
         APIBridge.CreateClip(new ClipPatch.Data(name, "", speech.voiceUUID), false, (ClipStatus status, Error error) =>
         {
             if (error)
             {
                 error.Log();
             }
             else
             {
                 if (status.status == "OK")
                 {
                     AddClip(name, status.id);
                 }
                 else
                 {
                     Debug.LogError("Cannot create the clip, please try again later.");
                 }
             }
         });
     }
 }
Exemplo n.º 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);
    }